summaryrefslogtreecommitdiff
path: root/core/java/android/util/SparseDoubleArray.java
diff options
context:
space:
mode:
authorJing Ji <jji@google.com>2022-01-05 01:29:52 -0800
committerJing Ji <jji@google.com>2022-01-25 14:33:12 -0800
commit627bbedd40b9b21480dd2ab4036bd9b718ca419d (patch)
treeaf27da72714dd32ad529470786de51f765ccd08d /core/java/android/util/SparseDoubleArray.java
parent1507931e89f5136813ba082d1a5472e2d9a0873f (diff)
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
Diffstat (limited to 'core/java/android/util/SparseDoubleArray.java')
-rw-r--r--core/java/android/util/SparseDoubleArray.java23
1 files changed, 23 insertions, 0 deletions
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
@@ -124,6 +124,15 @@ public class SparseDoubleArray implements Cloneable {
}
/**
+ * 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 <code>0...size()-1</code>, returns
* the key from the <code>index</code>th key-value mapping that this
* SparseDoubleArray stores.
@@ -146,6 +155,20 @@ public class SparseDoubleArray implements Cloneable {
}
/**
+ * Given an index in the range <code>0...size()-1</code>, sets a new
+ * value for the <code>index</code>th key-value mapping that this
+ * SparseDoubleArray stores.
+ *
+ * <p>For indices outside of the range <code>0...size()-1</code>, 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.</p>
+ */
+ public void setValueAt(int index, double value) {
+ mValues.setValueAt(index, Double.doubleToRawLongBits(value));
+ }
+
+ /**
* Removes all key-value mappings from this SparseDoubleArray.
*/
public void clear() {