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

Commit c4791feb authored by Jeongsik Mun's avatar Jeongsik Mun Committed by Song Chun Fan
Browse files

Optimize updating caches in AppsFilter

Updates caches for implicit access instead of invalidating it.

Bug: 285831656
Test: atest PackageManagerServiceServerTests:AppsFilterImplTest
Change-Id: Idba21df7abe32cd562272ac38d22d9b760e91d9f
parent 8131973d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -197,6 +197,7 @@ public abstract class AppsFilterBase implements AppsFilterSnapshot {

    protected volatile boolean mCacheReady = false;
    protected volatile boolean mCacheEnabled = true;
    protected volatile boolean mNeedToUpdateCacheForImplicitAccess = false;

    protected static final boolean CACHE_VALID = true;
    protected static final boolean CACHE_INVALID = false;
+29 −3
Original line number Diff line number Diff line
@@ -465,6 +465,9 @@ public final class AppsFilterImpl extends AppsFilterLocked implements Watchable,
            changed = retainOnUpdate
                    ? mRetainedImplicitlyQueryable.add(recipientUid, visibleUid)
                    : mImplicitlyQueryable.add(recipientUid, visibleUid);
            if (!mCacheReady && changed) {
                mNeedToUpdateCacheForImplicitAccess = true;
            }
        }
        if (changed && DEBUG_LOGGING) {
            Slog.i(TAG, (retainOnUpdate ? "retained " : "") + "implicit access granted: "
@@ -476,8 +479,6 @@ public final class AppsFilterImpl extends AppsFilterLocked implements Watchable,
                // Update the cache in a one-off manner since we've got all the information we need.
                mShouldFilterCache.put(recipientUid, visibleUid, false);
            }
        } else if (changed) {
            invalidateCache("grantImplicitAccess: " + recipientUid + " -> " + visibleUid);
        }
        if (changed) {
            onChanged();
@@ -833,7 +834,12 @@ public final class AppsFilterImpl extends AppsFilterLocked implements Watchable,
            }

            updateEntireShouldFilterCacheInner(snapshot, settings, usersRef[0], USER_ALL);
            onChanged();
            synchronized (mImplicitlyQueryableLock) {
                if (mNeedToUpdateCacheForImplicitAccess) {
                    updateShouldFilterCacheForImplicitAccess();
                    mNeedToUpdateCacheForImplicitAccess = false;
                }
            }
            logCacheRebuilt(reason, SystemClock.currentTimeMicro() - currentTimeUs,
                    users.length, settings.size());

@@ -845,6 +851,7 @@ public final class AppsFilterImpl extends AppsFilterLocked implements Watchable,
            }

            mCacheReady = true;
            onChanged();
        }, delayMs);
    }

@@ -875,6 +882,25 @@ public final class AppsFilterImpl extends AppsFilterLocked implements Watchable,
                snapshot.getPackageStates().size());
    }

    @GuardedBy("mImplicitlyQueryableLock")
    private void updateShouldFilterCacheForImplicitAccess() {
        updateShouldFilterCacheForImplicitAccess(mRetainedImplicitlyQueryable);
        updateShouldFilterCacheForImplicitAccess(mImplicitlyQueryable);
    }

    private void updateShouldFilterCacheForImplicitAccess(
            WatchedSparseSetArray<Integer> queriesMap) {
        synchronized (mCacheLock) {
            for (int i = 0; i < queriesMap.size(); i++) {
                Integer callingUid = queriesMap.keyAt(i);
                ArraySet<Integer> targetUids = queriesMap.get(callingUid);
                for (Integer targetUid : targetUids) {
                    mShouldFilterCache.put(callingUid, targetUid, false);
                }
            }
        }
    }

    private void updateShouldFilterCacheForPackage(Computer snapshot,
            String packageName) {
        if (!mCacheReady) {