Merge "[AppsFilter] read sysprop only when it's changed"

This commit is contained in:
Song Chun Fan
2022-09-22 01:08:44 +00:00
committed by Android (Google) Code Review
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;