summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Song Chun Fan <schfan@google.com> 2023-12-08 00:40:21 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2023-12-08 00:40:21 +0000
commite8c9818f50b6c76851377267e034bfd8289a1959 (patch)
tree6a75c175dcecaf9e1af241903b0b3850c8652f8b
parentf17942e89e8bcf8d208853311b28665c587fef97 (diff)
parent782fb5794fadc3017ed89bc8ab7e9c556886503d (diff)
Merge "Fix watchdog timeout during recomputeComponentVisibility" into main
-rw-r--r--services/core/java/com/android/server/pm/AppsFilterImpl.java11
-rw-r--r--services/core/java/com/android/server/pm/AppsFilterUtils.java9
-rw-r--r--services/core/java/com/android/server/utils/WatchedSparseSetArray.java14
3 files changed, 28 insertions, 6 deletions
diff --git a/services/core/java/com/android/server/pm/AppsFilterImpl.java b/services/core/java/com/android/server/pm/AppsFilterImpl.java
index bdcec3a33221..82622d9a4ea8 100644
--- a/services/core/java/com/android/server/pm/AppsFilterImpl.java
+++ b/services/core/java/com/android/server/pm/AppsFilterImpl.java
@@ -54,6 +54,7 @@ import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.Slog;
import android.util.SparseBooleanArray;
+import android.util.SparseSetArray;
import com.android.internal.R;
import com.android.internal.annotations.GuardedBy;
@@ -1030,14 +1031,18 @@ public final class AppsFilterImpl extends AppsFilterLocked implements Watchable,
private void recomputeComponentVisibility(
ArrayMap<String, ? extends PackageStateInternal> existingSettings) {
final WatchedArraySet<String> protectedBroadcasts;
+ final WatchedArraySet<Integer> forceQueryable;
synchronized (mProtectedBroadcastsLock) {
protectedBroadcasts = mProtectedBroadcasts.snapshot();
}
+ synchronized (mForceQueryableLock) {
+ forceQueryable = mForceQueryable.snapshot();
+ }
final ParallelComputeComponentVisibility computer = new ParallelComputeComponentVisibility(
- existingSettings, mForceQueryable, protectedBroadcasts);
+ existingSettings, forceQueryable, protectedBroadcasts);
+ SparseSetArray<Integer> queriesViaComponent = computer.execute();
synchronized (mQueriesViaComponentLock) {
- mQueriesViaComponent.clear();
- computer.execute(mQueriesViaComponent);
+ mQueriesViaComponent.copyFrom(queriesViaComponent);
}
mQueriesViaComponentRequireRecompute.set(false);
diff --git a/services/core/java/com/android/server/pm/AppsFilterUtils.java b/services/core/java/com/android/server/pm/AppsFilterUtils.java
index f3f64c5010ee..200734b37269 100644
--- a/services/core/java/com/android/server/pm/AppsFilterUtils.java
+++ b/services/core/java/com/android/server/pm/AppsFilterUtils.java
@@ -26,6 +26,7 @@ import android.content.IntentFilter;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.Pair;
+import android.util.SparseSetArray;
import com.android.internal.pm.pkg.component.ParsedComponent;
import com.android.internal.pm.pkg.component.ParsedIntentInfo;
@@ -37,7 +38,6 @@ import com.android.server.pm.pkg.AndroidPackage;
import com.android.server.pm.pkg.PackageState;
import com.android.server.pm.pkg.PackageStateInternal;
import com.android.server.utils.WatchedArraySet;
-import com.android.server.utils.WatchedSparseSetArray;
import java.util.ArrayList;
import java.util.List;
@@ -213,7 +213,9 @@ final class AppsFilterUtils {
/**
* Computes component visibility of all packages in parallel from a thread pool.
*/
- void execute(@NonNull WatchedSparseSetArray<Integer> outQueriesViaComponent) {
+ @NonNull
+ SparseSetArray<Integer> execute() {
+ final SparseSetArray<Integer> queriesViaComponent = new SparseSetArray<>();
final ExecutorService pool = ConcurrentUtils.newFixedThreadPool(
MAX_THREADS, ParallelComputeComponentVisibility.class.getSimpleName(),
THREAD_PRIORITY_DEFAULT);
@@ -239,7 +241,7 @@ final class AppsFilterUtils {
try {
final ArraySet<Integer> visibleList = future.get();
if (visibleList.size() != 0) {
- outQueriesViaComponent.addAll(appId, visibleList);
+ queriesViaComponent.addAll(appId, visibleList);
}
} catch (InterruptedException | ExecutionException e) {
throw new IllegalStateException(e);
@@ -248,6 +250,7 @@ final class AppsFilterUtils {
} finally {
pool.shutdownNow();
}
+ return queriesViaComponent;
}
/**
diff --git a/services/core/java/com/android/server/utils/WatchedSparseSetArray.java b/services/core/java/com/android/server/utils/WatchedSparseSetArray.java
index 0386e66aaf3d..b8850afdf3ad 100644
--- a/services/core/java/com/android/server/utils/WatchedSparseSetArray.java
+++ b/services/core/java/com/android/server/utils/WatchedSparseSetArray.java
@@ -142,6 +142,20 @@ public class WatchedSparseSetArray<T> extends WatchableImpl implements Snappable
return (T) mStorage.valueAt(intIndex, valueIndex);
}
+ /**
+ * Copy from another SparseSetArray.
+ */
+ public void copyFrom(@NonNull SparseSetArray<T> c) {
+ clear();
+ final int end = c.size();
+ for (int i = 0; i < end; i++) {
+ final int key = c.keyAt(i);
+ final ArraySet<T> set = c.get(key);
+ mStorage.addAll(key, set);
+ }
+ onChanged();
+ }
+
@NonNull
@Override
public Object snapshot() {