From 627bbedd40b9b21480dd2ab4036bd9b718ca419d Mon Sep 17 00:00:00 2001 From: Jing Ji Date: Wed, 5 Jan 2022 01:29:52 -0800 Subject: Add a tracker on background current drains for each uid On detecting excessive battery usage of a background uid, we may move the background restriction of the apps running in this uid to more restrictive levels. Bug: 200326767 Test: atest FrameworksMockingServicesTests:BackgroundRestrictionTest Change-Id: I6c2d41e44367a283d8aa9491be683018a80a810c --- core/java/android/util/SparseDoubleArray.java | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'core/java/android/util/SparseDoubleArray.java') diff --git a/core/java/android/util/SparseDoubleArray.java b/core/java/android/util/SparseDoubleArray.java index e8d96d8e26e4..cb51f7ac13b7 100644 --- a/core/java/android/util/SparseDoubleArray.java +++ b/core/java/android/util/SparseDoubleArray.java @@ -123,6 +123,15 @@ public class SparseDoubleArray implements Cloneable { return mValues.size(); } + /** + * Returns the index for which {@link #keyAt} would return the + * specified key, or a negative number if the specified + * key is not mapped. + */ + public int indexOfKey(int key) { + return mValues.indexOfKey(key); + } + /** * Given an index in the range 0...size()-1, returns * the key from the indexth key-value mapping that this @@ -145,6 +154,20 @@ public class SparseDoubleArray implements Cloneable { return Double.longBitsToDouble(mValues.valueAt(index)); } + /** + * Given an index in the range 0...size()-1, sets a new + * value for the indexth key-value mapping that this + * SparseDoubleArray stores. + * + *

For indices outside of the range 0...size()-1, the behavior is undefined for + * apps targeting {@link android.os.Build.VERSION_CODES#P} and earlier, and an + * {@link ArrayIndexOutOfBoundsException} is thrown for apps targeting + * {@link android.os.Build.VERSION_CODES#Q} and later.

+ */ + public void setValueAt(int index, double value) { + mValues.setValueAt(index, Double.doubleToRawLongBits(value)); + } + /** * Removes all key-value mappings from this SparseDoubleArray. */ -- cgit v1.2.3