Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 53e15887 authored by Songchun Fan's avatar Songchun Fan Committed by Automerger Merge Worker
Browse files

Merge "[AppsFilter] fix cache lock and rebuild cache if needed" into tm-dev...

Merge "[AppsFilter] fix cache lock and rebuild cache if needed" into tm-dev am: cd1a10a2 am: 20d964f2

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18360458



Change-Id: I649ece9767ed99ef11160c34b310e2625881f061
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 87370813 20d964f2
Loading
Loading
Loading
Loading
+41 −10
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.pm.SigningDetails;
import android.os.Binder;
import android.os.Handler;
import android.os.Process;
import android.os.Trace;
import android.os.UserHandle;
@@ -53,7 +54,7 @@ import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Collection;
import java.util.Objects;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicBoolean;

/**
 * AppsFilter is the entity responsible for filtering visibility between apps based on declarations
@@ -68,6 +69,11 @@ public abstract class AppsFilterBase implements AppsFilterSnapshot {
    protected static final boolean DEBUG_LOGGING = false;
    public static final boolean DEBUG_TRACING = false;

    // Allow some time for cache rebuilds.
    protected static final int CACHE_REBUILD_DELAY_MIN_MS = 10000;
    // With each new rebuild the delay doubles until it reaches max delay.
    protected static final int CACHE_REBUILD_DELAY_MAX_MS = 10000;

    /**
     * This contains a list of app UIDs that are implicitly queryable because another app explicitly
     * interacted with it. For example, if application A starts a service in application B,
@@ -122,10 +128,10 @@ public abstract class AppsFilterBase implements AppsFilterSnapshot {
    protected SnapshotCache<WatchedSparseSetArray<Integer>> mQueryableViaUsesLibrarySnapshot;

    /**
     * Executor for running reasonably short background tasks such as building the initial
     * Handler for running reasonably short background tasks such as building the initial
     * visibility cache.
     */
    protected Executor mBackgroundExecutor;
    protected Handler mBackgroundHandler;

    /**
     * Pending full recompute of mQueriesViaComponent. Occurs when a package adds a new set of
@@ -133,7 +139,7 @@ public abstract class AppsFilterBase implements AppsFilterSnapshot {
     * computationally expensive recomputing.
     * Full recompute is done lazily at the point when we use mQueriesViaComponent to filter apps.
     */
    protected boolean mQueriesViaComponentRequireRecompute = false;
    protected AtomicBoolean mQueriesViaComponentRequireRecompute = new AtomicBoolean(false);

    /**
     * A set of App IDs that are always queryable by any package, regardless of their manifest
@@ -173,7 +179,7 @@ public abstract class AppsFilterBase implements AppsFilterSnapshot {
     * {@link #shouldFilterApplicationInternal(PackageDataSnapshot, int, Object,
     * PackageStateInternal, int)} call.
     * NOTE: It can only be relied upon after the system is ready to avoid unnecessary update on
     * initial scam and is empty until {@link #mSystemReady} is true.
     * initial scam and is empty until {@link #mCacheReady} is true.
     */
    @NonNull
    @Watched
@@ -181,7 +187,11 @@ public abstract class AppsFilterBase implements AppsFilterSnapshot {
    @NonNull
    protected SnapshotCache<WatchedSparseBooleanMatrix> mShouldFilterCacheSnapshot;

    protected volatile boolean mSystemReady = false;
    protected volatile boolean mCacheReady = false;

    protected static final boolean CACHE_VALID = true;
    protected static final boolean CACHE_INVALID = false;
    protected AtomicBoolean mCacheValid = new AtomicBoolean(CACHE_INVALID);

    protected boolean isForceQueryable(int callingAppId) {
        return mForceQueryable.contains(callingAppId);
@@ -312,7 +322,7 @@ public abstract class AppsFilterBase implements AppsFilterSnapshot {
                    || callingAppId == targetPkgSetting.getAppId()) {
                return false;
            }
            if (mSystemReady) { // use cache
            if (mCacheReady) { // use cache
                if (!shouldFilterApplicationUsingCache(callingUid,
                        targetPkgSetting.getAppId(),
                        userId)) {
@@ -506,7 +516,7 @@ public abstract class AppsFilterBase implements AppsFilterSnapshot {
                if (DEBUG_TRACING) {
                    Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "mQueriesViaComponent");
                }
                if (!mQueriesViaComponentRequireRecompute) {
                if (!mQueriesViaComponentRequireRecompute.get()) {
                    if (isQueryableViaComponent(callingAppId, targetAppId)) {
                        if (DEBUG_LOGGING) {
                            log(callingSetting, targetPkgSetting, "queries component");
@@ -702,17 +712,34 @@ public abstract class AppsFilterBase implements AppsFilterSnapshot {
            }
        }
        pw.println("  system apps queryable: " + mSystemAppsQueryable);
        dumpQueryables(pw, filteringAppId, users, expandPackages);
        dumpForceQueryable(pw, filteringAppId, expandPackages);
        dumpQueriesViaPackage(pw, filteringAppId, expandPackages);
        dumpQueriesViaComponent(pw, filteringAppId, expandPackages);
        dumpQueriesViaImplicitlyQueryable(pw, filteringAppId, users, expandPackages);
        dumpQueriesViaUsesLibrary(pw, filteringAppId, expandPackages);
    }

    protected void dumpQueryables(PrintWriter pw, @Nullable Integer filteringAppId, int[] users,
    protected void dumpForceQueryable(PrintWriter pw, @Nullable Integer filteringAppId,
            ToString<Integer> expandPackages) {
        pw.println("  queries via forceQueryable:");
        dumpPackageSet(pw, filteringAppId, mForceQueryable.untrackedStorage(),
                "forceQueryable", "  ", expandPackages);
    }

    protected void dumpQueriesViaPackage(PrintWriter pw, @Nullable Integer filteringAppId,
            ToString<Integer> expandPackages) {
        pw.println("  queries via package name:");
        dumpQueriesMap(pw, filteringAppId, mQueriesViaPackage, "    ", expandPackages);
    }

    protected void dumpQueriesViaComponent(PrintWriter pw, @Nullable Integer filteringAppId,
            ToString<Integer> expandPackages) {
        pw.println("  queries via component:");
        dumpQueriesMap(pw, filteringAppId, mQueriesViaComponent, "    ", expandPackages);
    }

    protected void dumpQueriesViaImplicitlyQueryable(PrintWriter pw,
            @Nullable Integer filteringAppId, int[] users, ToString<Integer> expandPackages) {
        pw.println("  queryable via interaction:");
        for (int user : users) {
            pw.append("    User ").append(Integer.toString(user)).println(":");
@@ -723,6 +750,10 @@ public abstract class AppsFilterBase implements AppsFilterSnapshot {
                    filteringAppId == null ? null : UserHandle.getUid(user, filteringAppId),
                    mRetainedImplicitlyQueryable, "      ", expandPackages);
        }
    }

    protected void dumpQueriesViaUsesLibrary(PrintWriter pw, @Nullable Integer filteringAppId,
            ToString<Integer> expandPackages) {
        pw.println("  queryable via uses-library:");
        dumpQueriesMap(pw, filteringAppId, mQueryableViaUsesLibrary, "    ",
                expandPackages);
+167 −95

File changed.

Preview size limit exceeded, changes collapsed.

+53 −12

File changed.

Preview size limit exceeded, changes collapsed.

+30 −13

File changed.

Preview size limit exceeded, changes collapsed.

+47 −44

File changed.

Preview size limit exceeded, changes collapsed.