diff options
| author | Jing Ji <jji@google.com> | 2022-01-05 01:29:52 -0800 |
|---|---|---|
| committer | Jing Ji <jji@google.com> | 2022-01-25 14:33:12 -0800 |
| commit | 627bbedd40b9b21480dd2ab4036bd9b718ca419d (patch) | |
| tree | af27da72714dd32ad529470786de51f765ccd08d /core/java/android/util/SparseLongArray.java | |
| parent | 1507931e89f5136813ba082d1a5472e2d9a0873f (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/SparseLongArray.java')
| -rw-r--r-- | core/java/android/util/SparseLongArray.java | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/core/java/android/util/SparseLongArray.java b/core/java/android/util/SparseLongArray.java index 7185972b85bf..b739e379499c 100644 --- a/core/java/android/util/SparseLongArray.java +++ b/core/java/android/util/SparseLongArray.java @@ -245,6 +245,28 @@ public class SparseLongArray 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 + * SparseLongArray 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> + * + * @hide + */ + public void setValueAt(int index, long value) { + if (index >= mSize && UtilConfig.sThrowExceptionForUpperArrayOutOfBounds) { + // The array might be slightly bigger than mSize, in which case, indexing won't fail. + // Check if exception should be thrown outside of the critical path. + throw new ArrayIndexOutOfBoundsException(index); + } + + mValues[index] = value; + } + + /** * Returns the index for which {@link #keyAt} would return the * specified key, or a negative number if the specified * key is not mapped. |
