[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
This commit is contained in:
Songchun Fan
2022-09-21 15:04:37 -07:00
parent 94d707ccef
commit 9edad83f3c
3 changed files with 10 additions and 3 deletions

View File

@@ -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)) {

View File

@@ -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);
}
/**

View File

@@ -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;