Merge "[AppsFilter] make mShouldFilterCache non null" into tm-dev

This commit is contained in:
Songchun Fan
2022-04-04 20:10:52 +00:00
committed by Android (Google) Code Review

View File

@@ -52,7 +52,6 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.ArrayUtils; import com.android.internal.util.ArrayUtils;
import com.android.internal.util.function.QuadFunction; import com.android.internal.util.function.QuadFunction;
import com.android.server.FgThread; import com.android.server.FgThread;
import com.android.server.LocalServices;
import com.android.server.compat.CompatChange; import com.android.server.compat.CompatChange;
import com.android.server.om.OverlayReferenceMapper; import com.android.server.om.OverlayReferenceMapper;
import com.android.server.pm.parsing.pkg.AndroidPackage; import com.android.server.pm.parsing.pkg.AndroidPackage;
@@ -171,10 +170,13 @@ public class AppsFilter implements Watchable, Snappable {
* filtered to the second. It's essentially a cache of the * filtered to the second. It's essentially a cache of the
* {@link #shouldFilterApplicationInternal(int, Object, PackageStateInternal, int)} call. * {@link #shouldFilterApplicationInternal(int, Object, PackageStateInternal, int)} call.
* NOTE: It can only be relied upon after the system is ready to avoid unnecessary update on * NOTE: It can only be relied upon after the system is ready to avoid unnecessary update on
* initial scam and is null until {@link #onSystemReady()} is called. * initial scam and is empty until {@link #mSystemReady} is true.
*/ */
@GuardedBy("mCacheLock") @GuardedBy("mCacheLock")
private volatile WatchedSparseBooleanMatrix mShouldFilterCache; @NonNull
private final WatchedSparseBooleanMatrix mShouldFilterCache;
private volatile boolean mSystemReady = false;
/** /**
* A cached snapshot. * A cached snapshot.
@@ -187,7 +189,8 @@ public class AppsFilter implements Watchable, Snappable {
public AppsFilter createSnapshot() { public AppsFilter createSnapshot() {
AppsFilter s = new AppsFilter(mSource); AppsFilter s = new AppsFilter(mSource);
return s; return s;
}}; }
};
} }
/** /**
@@ -219,6 +222,7 @@ public class AppsFilter implements Watchable, Snappable {
/** /**
* Return true if the {@link Watcher) is a registered observer. * Return true if the {@link Watcher) is a registered observer.
*
* @param observer A {@link Watcher} that might be registered * @param observer A {@link Watcher} that might be registered
* @return true if the observer is registered with this {@link Watchable}. * @return true if the observer is registered with this {@link Watchable}.
*/ */
@@ -262,6 +266,7 @@ public class AppsFilter implements Watchable, Snappable {
mStateProvider = stateProvider; mStateProvider = stateProvider;
mPmInternal = pmInternal; mPmInternal = pmInternal;
mBackgroundExecutor = backgroundExecutor; mBackgroundExecutor = backgroundExecutor;
mShouldFilterCache = new WatchedSparseBooleanMatrix();
mSnapshot = makeCache(); mSnapshot = makeCache();
} }
@@ -285,16 +290,14 @@ public class AppsFilter implements Watchable, Snappable {
mStateProvider = orig.mStateProvider; mStateProvider = orig.mStateProvider;
mSystemSigningDetails = orig.mSystemSigningDetails; mSystemSigningDetails = orig.mSystemSigningDetails;
mProtectedBroadcasts = orig.mProtectedBroadcasts; mProtectedBroadcasts = orig.mProtectedBroadcasts;
mShouldFilterCache = orig.mShouldFilterCache; synchronized (orig.mCacheLock) {
if (mShouldFilterCache != null) { mShouldFilterCache = orig.mShouldFilterCache.snapshot();
synchronized (orig.mCacheLock) {
mShouldFilterCache = mShouldFilterCache.snapshot();
}
} }
mBackgroundExecutor = null; mBackgroundExecutor = null;
mPmInternal = null; mPmInternal = null;
mSnapshot = new SnapshotCache.Sealed<>(); mSnapshot = new SnapshotCache.Sealed<>();
mSystemReady = true;
} }
/** /**
@@ -653,9 +656,9 @@ public class AppsFilter implements Watchable, Snappable {
* Grants access based on an interaction between a calling and target package, granting * Grants access based on an interaction between a calling and target package, granting
* visibility of the caller from the target. * visibility of the caller from the target.
* *
* @param recipientUid the uid gaining visibility of the {@code visibleUid}. * @param recipientUid the uid gaining visibility of the {@code visibleUid}.
* @param visibleUid the uid becoming visible to the {@recipientUid} * @param visibleUid the uid becoming visible to the {@recipientUid}
* @param retainOnUpdate if the implicit access retained across package updates. * @param retainOnUpdate if the implicit access retained across package updates.
* @return {@code true} if implicit access was not already granted. * @return {@code true} if implicit access was not already granted.
*/ */
public boolean grantImplicitAccess(int recipientUid, int visibleUid, boolean retainOnUpdate) { public boolean grantImplicitAccess(int recipientUid, int visibleUid, boolean retainOnUpdate) {
@@ -669,8 +672,9 @@ public class AppsFilter implements Watchable, Snappable {
Slog.i(TAG, (retainOnUpdate ? "retained " : "") + "implicit access granted: " Slog.i(TAG, (retainOnUpdate ? "retained " : "") + "implicit access granted: "
+ recipientUid + " -> " + visibleUid); + recipientUid + " -> " + visibleUid);
} }
synchronized (mCacheLock) {
if (mShouldFilterCache != null) { if (mSystemReady) {
synchronized (mCacheLock) {
// update the cache in a one-off manner since we've got all the information we // update the cache in a one-off manner since we've got all the information we
// need. // need.
mShouldFilterCache.put(recipientUid, visibleUid, false); mShouldFilterCache.put(recipientUid, visibleUid, false);
@@ -688,13 +692,14 @@ public class AppsFilter implements Watchable, Snappable {
updateEntireShouldFilterCacheAsync(); updateEntireShouldFilterCacheAsync();
onChanged(); onChanged();
mSystemReady = true;
} }
/** /**
* Adds a package that should be considered when filtering visibility between apps. * Adds a package that should be considered when filtering visibility between apps.
* *
* @param newPkgSetting the new setting being added * @param newPkgSetting the new setting being added
* @param isReplace if the package is being replaced and may need extra cleanup. * @param isReplace if the package is being replaced and may need extra cleanup.
*/ */
public void addPackage(PackageStateInternal newPkgSetting, boolean isReplace) { public void addPackage(PackageStateInternal newPkgSetting, boolean isReplace) {
if (DEBUG_TRACING) { if (DEBUG_TRACING) {
@@ -708,29 +713,27 @@ public class AppsFilter implements Watchable, Snappable {
mStateProvider.runWithState((settings, users) -> { mStateProvider.runWithState((settings, users) -> {
ArraySet<String> additionalChangedPackages = ArraySet<String> additionalChangedPackages =
addPackageInternal(newPkgSetting, settings); addPackageInternal(newPkgSetting, settings);
synchronized (mCacheLock) { if (mSystemReady) {
if (mShouldFilterCache != null) { updateShouldFilterCacheForPackage(null, newPkgSetting,
updateShouldFilterCacheForPackage(mShouldFilterCache, null, newPkgSetting, settings, users, USER_ALL, settings.size());
settings, users, USER_ALL, settings.size()); if (additionalChangedPackages != null) {
if (additionalChangedPackages != null) { for (int index = 0; index < additionalChangedPackages.size(); index++) {
for (int index = 0; index < additionalChangedPackages.size(); index++) { String changedPackage = additionalChangedPackages.valueAt(index);
String changedPackage = additionalChangedPackages.valueAt(index); PackageStateInternal changedPkgSetting =
PackageStateInternal changedPkgSetting = settings.get(changedPackage);
settings.get(changedPackage); if (changedPkgSetting == null) {
if (changedPkgSetting == null) { // It's possible for the overlay mapper to know that an actor
// It's possible for the overlay mapper to know that an actor // package changed via an explicit reference, even if the actor
// package changed via an explicit reference, even if the actor // isn't installed, so skip if that's the case.
// isn't installed, so skip if that's the case. continue;
continue;
}
updateShouldFilterCacheForPackage(mShouldFilterCache, null,
changedPkgSetting, settings, users, USER_ALL,
settings.size());
} }
updateShouldFilterCacheForPackage(null,
changedPkgSetting, settings, users, USER_ALL,
settings.size());
} }
} // else, rebuild entire cache when system is ready }
} } // else, rebuild entire cache when system is ready
}); });
} finally { } finally {
onChanged(); onChanged();
@@ -845,19 +848,20 @@ public class AppsFilter implements Watchable, Snappable {
return changedPackages; return changedPackages;
} }
@GuardedBy("mCacheLock")
private void removeAppIdFromVisibilityCache(int appId) { private void removeAppIdFromVisibilityCache(int appId) {
if (mShouldFilterCache == null) { if (!mSystemReady) {
return; return;
} }
for (int i = 0; i < mShouldFilterCache.size(); i++) { synchronized (mCacheLock) {
if (UserHandle.getAppId(mShouldFilterCache.keyAt(i)) == appId) { for (int i = 0; i < mShouldFilterCache.size(); i++) {
mShouldFilterCache.removeAt(i); if (UserHandle.getAppId(mShouldFilterCache.keyAt(i)) == appId) {
// The key was deleted so the list of keys has shifted left. That means i mShouldFilterCache.removeAt(i);
// is now pointing at the next key to be examined. The decrement here and // The key was deleted so the list of keys has shifted left. That means i
// the loop increment together mean that i will be unchanged in the need // is now pointing at the next key to be examined. The decrement here and
// iteration and will correctly point to the next key to be examined. // the loop increment together mean that i will be unchanged in the need
i--; // iteration and will correctly point to the next key to be examined.
i--;
}
} }
} }
} }
@@ -880,31 +884,23 @@ public class AppsFilter implements Watchable, Snappable {
+ "updating the whole cache"); + "updating the whole cache");
userId = USER_ALL; userId = USER_ALL;
} }
WatchedSparseBooleanMatrix cache = updateEntireShouldFilterCacheInner(settings, users, userId);
updateEntireShouldFilterCacheInner(settings, users, userId);
synchronized (mCacheLock) {
mShouldFilterCache = cache;
}
}); });
} }
private WatchedSparseBooleanMatrix updateEntireShouldFilterCacheInner( private void updateEntireShouldFilterCacheInner(
ArrayMap<String, ? extends PackageStateInternal> settings, UserInfo[] users, ArrayMap<String, ? extends PackageStateInternal> settings, UserInfo[] users,
int subjectUserId) { int subjectUserId) {
final WatchedSparseBooleanMatrix cache; synchronized (mCacheLock) {
if (subjectUserId == USER_ALL) { if (subjectUserId == USER_ALL) {
cache = new WatchedSparseBooleanMatrix(users.length * settings.size()); mShouldFilterCache.clear();
} else {
synchronized (mCacheLock) {
cache = mShouldFilterCache.snapshot();
} }
cache.setCapacity(users.length * settings.size()); mShouldFilterCache.setCapacity(users.length * settings.size());
} }
for (int i = settings.size() - 1; i >= 0; i--) { for (int i = settings.size() - 1; i >= 0; i--) {
updateShouldFilterCacheForPackage(cache, updateShouldFilterCacheForPackage(
null /*skipPackage*/, settings.valueAt(i), settings, users, subjectUserId, i); null /*skipPackage*/, settings.valueAt(i), settings, users, subjectUserId, i);
} }
return cache;
} }
private void updateEntireShouldFilterCacheAsync() { private void updateEntireShouldFilterCacheAsync() {
@@ -923,8 +919,7 @@ public class AppsFilter implements Watchable, Snappable {
packagesCache.put(settings.keyAt(i), pkg); packagesCache.put(settings.keyAt(i), pkg);
} }
}); });
WatchedSparseBooleanMatrix cache = updateEntireShouldFilterCacheInner(
settingsCopy, usersRef[0], USER_ALL);
boolean[] changed = new boolean[1]; boolean[] changed = new boolean[1];
// We have a cache, let's make sure the world hasn't changed out from under us. // We have a cache, let's make sure the world hasn't changed out from under us.
mStateProvider.runWithState((settings, users) -> { mStateProvider.runWithState((settings, users) -> {
@@ -947,45 +942,39 @@ public class AppsFilter implements Watchable, Snappable {
Slog.i(TAG, "Rebuilding cache with lock due to package change."); Slog.i(TAG, "Rebuilding cache with lock due to package change.");
} }
} else { } else {
synchronized (mCacheLock) { updateEntireShouldFilterCacheInner(settingsCopy, usersRef[0], USER_ALL);
mShouldFilterCache = cache;
}
} }
}); });
} }
public void onUserCreated(int newUserId) { public void onUserCreated(int newUserId) {
synchronized (mCacheLock) { if (!mSystemReady) {
if (mShouldFilterCache != null) { return;
updateEntireShouldFilterCache(newUserId);
onChanged();
}
} }
updateEntireShouldFilterCache(newUserId);
onChanged();
} }
public void onUserDeleted(@UserIdInt int userId) { public void onUserDeleted(@UserIdInt int userId) {
synchronized (mCacheLock) { if (!mSystemReady) {
if (mShouldFilterCache != null) { return;
removeShouldFilterCacheForUser(userId);
onChanged();
}
} }
removeShouldFilterCacheForUser(userId);
onChanged();
} }
private void updateShouldFilterCacheForPackage(String packageName) { private void updateShouldFilterCacheForPackage(String packageName) {
mStateProvider.runWithState((settings, users) -> { mStateProvider.runWithState((settings, users) -> {
synchronized (mCacheLock) { if (!mSystemReady) {
if (mShouldFilterCache == null) { return;
return;
}
updateShouldFilterCacheForPackage(mShouldFilterCache, null /* skipPackage */,
settings.get(packageName), settings, users, USER_ALL,
settings.size() /*maxIndex*/);
} }
updateShouldFilterCacheForPackage(null /* skipPackage */,
settings.get(packageName), settings, users, USER_ALL,
settings.size() /*maxIndex*/);
}); });
} }
private void updateShouldFilterCacheForPackage(WatchedSparseBooleanMatrix cache, private void updateShouldFilterCacheForPackage(
@Nullable String skipPackageName, PackageStateInternal subjectSetting, ArrayMap<String, @Nullable String skipPackageName, PackageStateInternal subjectSetting, ArrayMap<String,
? extends PackageStateInternal> allSettings, UserInfo[] allUsers, int subjectUserId, ? extends PackageStateInternal> allSettings, UserInfo[] allUsers, int subjectUserId,
int maxIndex) { int maxIndex) {
@@ -1001,53 +990,56 @@ public class AppsFilter implements Watchable, Snappable {
} }
if (subjectUserId == USER_ALL) { if (subjectUserId == USER_ALL) {
for (int su = 0; su < allUsers.length; su++) { for (int su = 0; su < allUsers.length; su++) {
updateShouldFilterCacheForUser(cache, subjectSetting, allUsers, otherSetting, updateShouldFilterCacheForUser(subjectSetting, allUsers, otherSetting,
allUsers[su].id); allUsers[su].id);
} }
} else { } else {
updateShouldFilterCacheForUser(cache, subjectSetting, allUsers, otherSetting, updateShouldFilterCacheForUser(subjectSetting, allUsers, otherSetting,
subjectUserId); subjectUserId);
} }
} }
} }
private void updateShouldFilterCacheForUser(WatchedSparseBooleanMatrix cache, private void updateShouldFilterCacheForUser(
PackageStateInternal subjectSetting, UserInfo[] allUsers, PackageStateInternal subjectSetting, UserInfo[] allUsers,
PackageStateInternal otherSetting, int subjectUserId) { PackageStateInternal otherSetting, int subjectUserId) {
for (int ou = 0; ou < allUsers.length; ou++) { for (int ou = 0; ou < allUsers.length; ou++) {
int otherUser = allUsers[ou].id; int otherUser = allUsers[ou].id;
int subjectUid = UserHandle.getUid(subjectUserId, subjectSetting.getAppId()); int subjectUid = UserHandle.getUid(subjectUserId, subjectSetting.getAppId());
int otherUid = UserHandle.getUid(otherUser, otherSetting.getAppId()); int otherUid = UserHandle.getUid(otherUser, otherSetting.getAppId());
cache.put(subjectUid, otherUid, final boolean shouldFilterSubjectToOther = shouldFilterApplicationInternal(
shouldFilterApplicationInternal( subjectUid, subjectSetting, otherSetting, otherUser);
subjectUid, subjectSetting, otherSetting, otherUser)); final boolean shouldFilterOtherToSubject = shouldFilterApplicationInternal(
cache.put(otherUid, subjectUid, otherUid, otherSetting, subjectSetting, subjectUserId);
shouldFilterApplicationInternal( synchronized (mCacheLock) {
otherUid, otherSetting, subjectSetting, subjectUserId)); mShouldFilterCache.put(subjectUid, otherUid, shouldFilterSubjectToOther);
mShouldFilterCache.put(otherUid, subjectUid, shouldFilterOtherToSubject);
}
} }
} }
@GuardedBy("mCacheLock")
private void removeShouldFilterCacheForUser(int userId) { private void removeShouldFilterCacheForUser(int userId) {
// Sorted uids with the ascending order synchronized (mCacheLock) {
final int[] cacheUids = mShouldFilterCache.keys(); // Sorted uids with the ascending order
final int size = cacheUids.length; final int[] cacheUids = mShouldFilterCache.keys();
int pos = Arrays.binarySearch(cacheUids, UserHandle.getUid(userId, 0)); final int size = cacheUids.length;
final int fromIndex = (pos >= 0 ? pos : ~pos); int pos = Arrays.binarySearch(cacheUids, UserHandle.getUid(userId, 0));
if (fromIndex >= size || UserHandle.getUserId(cacheUids[fromIndex]) != userId) { final int fromIndex = (pos >= 0 ? pos : ~pos);
Slog.w(TAG, "Failed to remove should filter cache for user " + userId if (fromIndex >= size || UserHandle.getUserId(cacheUids[fromIndex]) != userId) {
+ ", fromIndex=" + fromIndex); Slog.w(TAG, "Failed to remove should filter cache for user " + userId
return; + ", fromIndex=" + fromIndex);
return;
}
pos = Arrays.binarySearch(cacheUids, UserHandle.getUid(userId + 1, 0) - 1);
final int toIndex = (pos >= 0 ? pos + 1 : ~pos);
if (fromIndex >= toIndex || UserHandle.getUserId(cacheUids[toIndex - 1]) != userId) {
Slog.w(TAG, "Failed to remove should filter cache for user " + userId
+ ", fromIndex=" + fromIndex + ", toIndex=" + toIndex);
return;
}
mShouldFilterCache.removeRange(fromIndex, toIndex);
mShouldFilterCache.compact();
} }
pos = Arrays.binarySearch(cacheUids, UserHandle.getUid(userId + 1, 0) - 1);
final int toIndex = (pos >= 0 ? pos + 1 : ~pos);
if (fromIndex >= toIndex || UserHandle.getUserId(cacheUids[toIndex - 1]) != userId) {
Slog.w(TAG, "Failed to remove should filter cache for user " + userId
+ ", fromIndex=" + fromIndex + ", toIndex=" + toIndex);
return;
}
mShouldFilterCache.removeRange(fromIndex, toIndex);
mShouldFilterCache.compact();
} }
private static boolean isSystemSigned(@NonNull SigningDetails sysSigningDetails, private static boolean isSystemSigned(@NonNull SigningDetails sysSigningDetails,
@@ -1171,6 +1163,7 @@ public class AppsFilter implements Watchable, Snappable {
/** /**
* Equivalent to calling {@link #addPackage(PackageStateInternal, boolean)} with * Equivalent to calling {@link #addPackage(PackageStateInternal, boolean)} with
* {@code isReplace} equal to {@code false}. * {@code isReplace} equal to {@code false}.
*
* @see AppsFilter#addPackage(PackageStateInternal, boolean) * @see AppsFilter#addPackage(PackageStateInternal, boolean)
*/ */
public void addPackage(PackageStateInternal newPkgSetting) { public void addPackage(PackageStateInternal newPkgSetting) {
@@ -1180,7 +1173,7 @@ public class AppsFilter implements Watchable, Snappable {
/** /**
* Removes a package for consideration when filtering visibility between apps. * Removes a package for consideration when filtering visibility between apps.
* *
* @param setting the setting of the package being removed. * @param setting the setting of the package being removed.
* @param isReplace if the package is being replaced. * @param isReplace if the package is being replaced.
*/ */
public void removePackage(PackageStateInternal setting, boolean isReplace) { public void removePackage(PackageStateInternal setting, boolean isReplace) {
@@ -1253,43 +1246,41 @@ public class AppsFilter implements Watchable, Snappable {
} }
} }
synchronized (mCacheLock) { removeAppIdFromVisibilityCache(setting.getAppId());
removeAppIdFromVisibilityCache(setting.getAppId()); if (mSystemReady && setting.hasSharedUser()) {
if (mShouldFilterCache != null && setting.hasSharedUser()) { final ArraySet<PackageStateInternal> sharedUserPackages =
final ArraySet<PackageStateInternal> sharedUserPackages = mPmInternal.getSharedUserPackages(setting.getSharedUserAppId());
mPmInternal.getSharedUserPackages(setting.getSharedUserAppId()); for (int i = sharedUserPackages.size() - 1; i >= 0; i--) {
for (int i = sharedUserPackages.size() - 1; i >= 0; i--) { PackageStateInternal siblingSetting =
PackageStateInternal siblingSetting = sharedUserPackages.valueAt(i);
sharedUserPackages.valueAt(i); if (siblingSetting == setting) {
if (siblingSetting == setting) { continue;
}
updateShouldFilterCacheForPackage(
setting.getPackageName(), siblingSetting, settings, users,
USER_ALL, settings.size());
}
}
if (mSystemReady) {
if (additionalChangedPackages != null) {
for (int index = 0; index < additionalChangedPackages.size(); index++) {
String changedPackage = additionalChangedPackages.valueAt(index);
PackageStateInternal changedPkgSetting = settings.get(changedPackage);
if (changedPkgSetting == null) {
// It's possible for the overlay mapper to know that an actor
// package changed via an explicit reference, even if the actor
// isn't installed, so skip if that's the case.
continue; continue;
} }
updateShouldFilterCacheForPackage(mShouldFilterCache,
setting.getPackageName(), siblingSetting, settings, users, updateShouldFilterCacheForPackage(null,
USER_ALL, settings.size()); changedPkgSetting, settings, users, USER_ALL, settings.size());
} }
} }
if (mShouldFilterCache != null) {
if (additionalChangedPackages != null) {
for (int index = 0; index < additionalChangedPackages.size(); index++) {
String changedPackage = additionalChangedPackages.valueAt(index);
PackageStateInternal changedPkgSetting = settings.get(changedPackage);
if (changedPkgSetting == null) {
// It's possible for the overlay mapper to know that an actor
// package changed via an explicit reference, even if the actor
// isn't installed, so skip if that's the case.
continue;
}
updateShouldFilterCacheForPackage(mShouldFilterCache, null,
changedPkgSetting, settings, users, USER_ALL, settings.size());
}
}
}
onChanged();
} }
onChanged();
}); });
} }
@@ -1315,29 +1306,16 @@ public class AppsFilter implements Watchable, Snappable {
|| callingAppId == targetPkgSetting.getAppId()) { || callingAppId == targetPkgSetting.getAppId()) {
return false; return false;
} }
synchronized (mCacheLock) { if (mSystemReady) { // use cache
if (mShouldFilterCache != null) { // use cache if (!shouldFilterApplicationUsingCache(callingUid,
final int callingIndex = mShouldFilterCache.indexOfKey(callingUid); targetPkgSetting.getAppId(),
if (callingIndex < 0) { userId)) {
Slog.wtf(TAG, "Encountered calling uid with no cached rules: " return false;
+ callingUid); }
return true; } else {
} if (!shouldFilterApplicationInternal(
final int targetUid = UserHandle.getUid(userId, targetPkgSetting.getAppId()); callingUid, callingSetting, targetPkgSetting, userId)) {
final int targetIndex = mShouldFilterCache.indexOfKey(targetUid); return false;
if (targetIndex < 0) {
Slog.w(TAG, "Encountered calling -> target with no cached rules: "
+ callingUid + " -> " + targetUid);
return true;
}
if (!mShouldFilterCache.valueAt(callingIndex, targetIndex)) {
return false;
}
} else {
if (!shouldFilterApplicationInternal(
callingUid, callingSetting, targetPkgSetting, userId)) {
return false;
}
} }
} }
if (DEBUG_LOGGING || mFeatureConfig.isLoggingEnabled(callingAppId)) { if (DEBUG_LOGGING || mFeatureConfig.isLoggingEnabled(callingAppId)) {
@@ -1351,6 +1329,25 @@ public class AppsFilter implements Watchable, Snappable {
} }
} }
private boolean shouldFilterApplicationUsingCache(int callingUid, int appId, int userId) {
synchronized (mCacheLock) {
final int callingIndex = mShouldFilterCache.indexOfKey(callingUid);
if (callingIndex < 0) {
Slog.wtf(TAG, "Encountered calling uid with no cached rules: "
+ callingUid);
return true;
}
final int targetUid = UserHandle.getUid(userId, appId);
final int targetIndex = mShouldFilterCache.indexOfKey(targetUid);
if (targetIndex < 0) {
Slog.w(TAG, "Encountered calling -> target with no cached rules: "
+ callingUid + " -> " + targetUid);
return true;
}
return mShouldFilterCache.valueAt(callingIndex, targetIndex);
}
}
private boolean shouldFilterApplicationInternal(int callingUid, Object callingSetting, private boolean shouldFilterApplicationInternal(int callingUid, Object callingSetting,
PackageStateInternal targetPkgSetting, int targetUserId) { PackageStateInternal targetPkgSetting, int targetUserId) {
if (DEBUG_TRACING) { if (DEBUG_TRACING) {
@@ -1437,10 +1434,10 @@ public class AppsFilter implements Watchable, Snappable {
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "requestsQueryAllPackages"); Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "requestsQueryAllPackages");
} }
if (callingPkgSetting != null) { if (callingPkgSetting != null) {
if (callingPkgSetting.getPkg() != null if (callingPkgSetting.getPkg() != null
&& requestsQueryAllPackages(callingPkgSetting.getPkg())) { && requestsQueryAllPackages(callingPkgSetting.getPkg())) {
return false; return false;
} }
} else { } else {
for (int i = callingSharedPkgSettings.size() - 1; i >= 0; i--) { for (int i = callingSharedPkgSettings.size() - 1; i >= 0; i--) {
AndroidPackage pkg = callingSharedPkgSettings.valueAt(i).getPkg(); AndroidPackage pkg = callingSharedPkgSettings.valueAt(i).getPkg();
@@ -1747,6 +1744,7 @@ public class AppsFilter implements Watchable, Snappable {
private interface ToString<T> { private interface ToString<T> {
String toString(T input); String toString(T input);
} }
private static <T> void dumpPackageSet(PrintWriter pw, @Nullable T filteringId, private static <T> void dumpPackageSet(PrintWriter pw, @Nullable T filteringId,