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

Commit 1728e088 authored by Song Chun Fan's avatar Song Chun Fan Committed by Android (Google) Code Review
Browse files

Merge "Optimize updating caches in AppsFilter"

parents f26c0ad8 c4791feb
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -197,6 +197,7 @@ public abstract class AppsFilterBase implements AppsFilterSnapshot {


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


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


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


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


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


@@ -875,6 +882,25 @@ public final class AppsFilterImpl extends AppsFilterLocked implements Watchable,
                snapshot.getPackageStates().size());
                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,
    private void updateShouldFilterCacheForPackage(Computer snapshot,
            String packageName) {
            String packageName) {
        if (!mCacheReady) {
        if (!mCacheReady) {