summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--services/core/java/com/android/server/pm/AppsFilterImpl.java4
-rw-r--r--services/core/java/com/android/server/utils/WatchedSparseSetArray.java11
2 files changed, 14 insertions, 1 deletions
diff --git a/services/core/java/com/android/server/pm/AppsFilterImpl.java b/services/core/java/com/android/server/pm/AppsFilterImpl.java
index 82622d9a4ea8..f3df4244c47f 100644
--- a/services/core/java/com/android/server/pm/AppsFilterImpl.java
+++ b/services/core/java/com/android/server/pm/AppsFilterImpl.java
@@ -1042,7 +1042,9 @@ public final class AppsFilterImpl extends AppsFilterLocked implements Watchable,
existingSettings, forceQueryable, protectedBroadcasts);
SparseSetArray<Integer> queriesViaComponent = computer.execute();
synchronized (mQueriesViaComponentLock) {
- mQueriesViaComponent.copyFrom(queriesViaComponent);
+ mQueriesViaComponent = new WatchedSparseSetArray<>(queriesViaComponent);
+ mQueriesViaComponentSnapshot = new SnapshotCache.Auto<>(
+ mQueriesViaComponent, mQueriesViaComponent, "AppsFilter.mQueriesViaComponent");
}
mQueriesViaComponentRequireRecompute.set(false);
diff --git a/services/core/java/com/android/server/utils/WatchedSparseSetArray.java b/services/core/java/com/android/server/utils/WatchedSparseSetArray.java
index b8850afdf3ad..ff426ccf9083 100644
--- a/services/core/java/com/android/server/utils/WatchedSparseSetArray.java
+++ b/services/core/java/com/android/server/utils/WatchedSparseSetArray.java
@@ -47,6 +47,17 @@ public class WatchedSparseSetArray<T> extends WatchableImpl implements Snappable
}
/**
+ * Create a new WatchedSparseSetArray from an existing SparseSetArray without copying.
+ * <p>
+ * Use with caution: Callers must ensure that no reference to {@code sparseSetArray} exists
+ * anywhere else in the system. If such a reference does exist, then changes to the storage via
+ * that reference will not be noticed by the new WatchedSpareSetArray.
+ */
+ public WatchedSparseSetArray(@NonNull SparseSetArray<T> sparseSetArray) {
+ mStorage = sparseSetArray;
+ }
+
+ /**
* Return the underlying storage. This breaks the wrapper but is necessary when
* passing the array to distant methods.
*/