diff options
| author | Songchun Fan <schfan@google.com> | 2022-03-22 22:29:25 +0000 |
|---|---|---|
| committer | Songchun Fan <schfan@google.com> | 2022-03-28 23:57:08 +0000 |
| commit | 8cb3e6aac93147287bcb9fa41a284b1745d47c75 (patch) | |
| tree | 97326af227099970bce0ec89e387ff473b3ca882 /core/java/android/util/SparseSetArray.java | |
| parent | 95387ac862c4c4f4a0eae942cdd95120cf1ebba6 (diff) | |
[AppsFilter] read-only interface for snapshots
Provides a read-only interface that is used by computer and snapshots.
It fixes the data conflicts when AppsFilter is changed while a snapshot is
taken. This requires a watchable class for SparseSetArray.
Test: atest AppsFilterTest
Test: atest com.android.server.utils.WatcherTest
Test: m RUN_ERROR_PRONE=true framework services.core |& grep AppsFilter
BUG: 218411030
Change-Id: Ib9d13537b6cec911b2a189aea828e9baec650585
Diffstat (limited to 'core/java/android/util/SparseSetArray.java')
| -rw-r--r-- | core/java/android/util/SparseSetArray.java | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/core/java/android/util/SparseSetArray.java b/core/java/android/util/SparseSetArray.java index f5025f7a9e99..eb53b425a228 100644 --- a/core/java/android/util/SparseSetArray.java +++ b/core/java/android/util/SparseSetArray.java @@ -21,9 +21,26 @@ package android.util; * @hide */ public class SparseSetArray<T> { - private final SparseArray<ArraySet<T>> mData = new SparseArray<>(); + private final SparseArray<ArraySet<T>> mData; public SparseSetArray() { + mData = new SparseArray<>(); + } + + /** + * Copy constructor + */ + public SparseSetArray(SparseSetArray<T> src) { + final int arraySize = src.size(); + mData = new SparseArray<>(arraySize); + for (int i = 0; i < arraySize; i++) { + final int key = src.keyAt(i); + final ArraySet<T> set = src.get(key); + final int setSize = set.size(); + for (int j = 0; j < setSize; j++) { + add(key, set.valueAt(j)); + } + } } /** |
