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

Commit 9edad83f authored by Songchun Fan's avatar Songchun Fan
Browse files

[AppsFilter] read sysprop only when it's changed

Bisection shows ag/19669172 likely caused a small regression on the
health metrics possibly due to the overhead of parsing.

Given that system properties don't change much, optimize the reading of
the debug property to be called when any system property is changed.

BUG: 241751330
Test: atest AppEnumerationTests
Change-Id: Ib1c71db0e668b10ddb92fd842fa3a18dd2cf323c
parent 94d707cc
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -28,7 +28,6 @@ import android.content.pm.SigningDetails;
import android.os.Binder;
import android.os.Handler;
import android.os.Process;
import android.os.SystemProperties;
import android.os.Trace;
import android.os.UserHandle;
import android.text.TextUtils;
@@ -199,6 +198,7 @@ public abstract class AppsFilterBase implements AppsFilterSnapshot {
    protected SnapshotCache<WatchedSparseBooleanMatrix> mShouldFilterCacheSnapshot;

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

    protected static final boolean CACHE_VALID = true;
    protected static final boolean CACHE_INVALID = false;
@@ -342,8 +342,7 @@ public abstract class AppsFilterBase implements AppsFilterSnapshot {
                      && !isImplicitlyQueryable(callingAppId, targetPkgSetting.getAppId());
            }
            // use cache
            if (mCacheReady && SystemProperties.getBoolean("debug.pm.use_app_filter_cache",
                    true)) {
            if (mCacheReady && mCacheEnabled) {
                if (!shouldFilterApplicationUsingCache(callingUid,
                        targetPkgSetting.getAppId(),
                        userId)) {
+7 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import android.content.pm.PackageManagerInternal;
import android.content.pm.SigningDetails;
import android.content.pm.UserInfo;
import android.os.Handler;
import android.os.SystemProperties;
import android.os.Trace;
import android.os.UserHandle;
import android.provider.DeviceConfig;
@@ -223,6 +224,12 @@ public final class AppsFilterImpl extends AppsFilterLocked implements Watchable,
                return new AppsFilterSnapshotImpl(AppsFilterImpl.this);
            }
        };
        readCacheEnabledSysProp();
        SystemProperties.addChangeCallback(this::readCacheEnabledSysProp);
    }

    private void readCacheEnabledSysProp() {
        mCacheEnabled = SystemProperties.getBoolean("debug.pm.use_app_filter_cache", true);
    }

    /**
+1 −0
Original line number Diff line number Diff line
@@ -74,6 +74,7 @@ public final class AppsFilterSnapshotImpl extends AppsFilterBase {
            // cache is not ready, use an empty cache for the snapshot
            mShouldFilterCache = new WatchedSparseBooleanMatrix();
        }
        mCacheEnabled = orig.mCacheEnabled;
        mShouldFilterCacheSnapshot = new SnapshotCache.Sealed<>();

        mBackgroundHandler = null;