Pre-cache filter results
This change adds a cache layer for the return of shouldFilterApplicationInternal in AppsFilter. This cuts most operations that rely on app filtering nearly in half by removing a good deal of branching that used to exist on the critical path for a crosshatch. Before this CL: android.os.PackageManagerPerfTest#testGetApplicationInfoWithFiltering: getApplicationInfoWithFiltering_mean: 983719 getApplicationInfoWithFiltering_standardDeviation: 120061 getApplicationInfoWithFiltering_median: 1061674 getApplicationInfoWithFiltering_min: 827489 android.multiuser.UserLifecycleTests#createAndStartUser: Mean (ms): 4243.10 After this CL: android.os.PackageManagerPerfTest#testGetApplicationInfoWithFiltering: getApplicationInfoWithFiltering_mean: 426340 getApplicationInfoWithFiltering_standardDeviation: 18861 getApplicationInfoWithFiltering_median: 427002 getApplicationInfoWithFiltering_min: 407887 android.multiuser.UserLifecycleTests#createAndStartUser: Mean (ms): 3387.25 Note: this is a 2nd attempt at this change that fixes a few from the previous at ag/11622391. This works with multi-user and updates tests to ensure this stays true. It also improves peformance when building the cache by pre-allocating the SparseBooleanArrays to their max sizes. Test: atest AppEnumerationTests AppsFilterTest PackageManagerPerfTests Fixes: 150405193 Change-Id: I6e0446068f46af0f22e0259ab7b6cdbbc7e08a22
This commit is contained in:
committed by
Alex Buynytskyy
parent
88d54c764f
commit
2377f33ace
@@ -19,6 +19,8 @@ package com.android.server.pm;
|
|||||||
import static android.os.Trace.TRACE_TAG_PACKAGE_MANAGER;
|
import static android.os.Trace.TRACE_TAG_PACKAGE_MANAGER;
|
||||||
import static android.provider.DeviceConfig.NAMESPACE_PACKAGE_MANAGER_SERVICE;
|
import static android.provider.DeviceConfig.NAMESPACE_PACKAGE_MANAGER_SERVICE;
|
||||||
|
|
||||||
|
import static com.android.internal.annotations.VisibleForTesting.Visibility.PRIVATE;
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
@@ -27,6 +29,7 @@ import android.content.IntentFilter;
|
|||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.PackageManagerInternal;
|
import android.content.pm.PackageManagerInternal;
|
||||||
import android.content.pm.PackageParser;
|
import android.content.pm.PackageParser;
|
||||||
|
import android.content.pm.UserInfo;
|
||||||
import android.content.pm.parsing.component.ParsedComponent;
|
import android.content.pm.parsing.component.ParsedComponent;
|
||||||
import android.content.pm.parsing.component.ParsedInstrumentation;
|
import android.content.pm.parsing.component.ParsedInstrumentation;
|
||||||
import android.content.pm.parsing.component.ParsedIntentInfo;
|
import android.content.pm.parsing.component.ParsedIntentInfo;
|
||||||
@@ -108,12 +111,25 @@ public class AppsFilter {
|
|||||||
private final boolean mSystemAppsQueryable;
|
private final boolean mSystemAppsQueryable;
|
||||||
|
|
||||||
private final FeatureConfig mFeatureConfig;
|
private final FeatureConfig mFeatureConfig;
|
||||||
|
|
||||||
private final OverlayReferenceMapper mOverlayReferenceMapper;
|
private final OverlayReferenceMapper mOverlayReferenceMapper;
|
||||||
|
private final StateProvider mStateProvider;
|
||||||
|
|
||||||
private PackageParser.SigningDetails mSystemSigningDetails;
|
private PackageParser.SigningDetails mSystemSigningDetails;
|
||||||
private Set<String> mProtectedBroadcasts = new ArraySet<>();
|
private Set<String> mProtectedBroadcasts = new ArraySet<>();
|
||||||
|
|
||||||
AppsFilter(FeatureConfig featureConfig, String[] forceQueryableWhitelist,
|
/**
|
||||||
|
* This structure maps uid -> uid and indicates whether access from the first should be
|
||||||
|
* filtered to the second. It's essentially a cache of the
|
||||||
|
* {@link #shouldFilterApplicationInternal(int, SettingBase, PackageSetting, int)} call.
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
private volatile SparseArray<SparseBooleanArray> mShouldFilterCache;
|
||||||
|
|
||||||
|
@VisibleForTesting(visibility = PRIVATE)
|
||||||
|
AppsFilter(StateProvider stateProvider,
|
||||||
|
FeatureConfig featureConfig,
|
||||||
|
String[] forceQueryableWhitelist,
|
||||||
boolean systemAppsQueryable,
|
boolean systemAppsQueryable,
|
||||||
@Nullable OverlayReferenceMapper.Provider overlayProvider) {
|
@Nullable OverlayReferenceMapper.Provider overlayProvider) {
|
||||||
mFeatureConfig = featureConfig;
|
mFeatureConfig = featureConfig;
|
||||||
@@ -121,8 +137,23 @@ public class AppsFilter {
|
|||||||
mSystemAppsQueryable = systemAppsQueryable;
|
mSystemAppsQueryable = systemAppsQueryable;
|
||||||
mOverlayReferenceMapper = new OverlayReferenceMapper(true /*deferRebuild*/,
|
mOverlayReferenceMapper = new OverlayReferenceMapper(true /*deferRebuild*/,
|
||||||
overlayProvider);
|
overlayProvider);
|
||||||
|
mStateProvider = stateProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides system state to AppsFilter via {@link CurrentStateCallback} after properly guarding
|
||||||
|
* the data with the package lock.
|
||||||
|
*/
|
||||||
|
@VisibleForTesting(visibility = PRIVATE)
|
||||||
|
public interface StateProvider {
|
||||||
|
void runWithState(CurrentStateCallback callback);
|
||||||
|
|
||||||
|
interface CurrentStateCallback {
|
||||||
|
void currentState(ArrayMap<String, PackageSetting> settings, List<UserInfo> users);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting(visibility = PRIVATE)
|
||||||
public interface FeatureConfig {
|
public interface FeatureConfig {
|
||||||
|
|
||||||
/** Called when the system is ready and components can be queried. */
|
/** Called when the system is ready and components can be queried. */
|
||||||
@@ -139,6 +170,7 @@ public class AppsFilter {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Turns on logging for the given appId
|
* Turns on logging for the given appId
|
||||||
|
*
|
||||||
* @param enable true if logging should be enabled, false if disabled.
|
* @param enable true if logging should be enabled, false if disabled.
|
||||||
*/
|
*/
|
||||||
void enableLogging(int appId, boolean enable);
|
void enableLogging(int appId, boolean enable);
|
||||||
@@ -146,6 +178,7 @@ public class AppsFilter {
|
|||||||
/**
|
/**
|
||||||
* Initializes the package enablement state for the given package. This gives opportunity
|
* Initializes the package enablement state for the given package. This gives opportunity
|
||||||
* to do any expensive operations ahead of the actual checks.
|
* to do any expensive operations ahead of the actual checks.
|
||||||
|
*
|
||||||
* @param removed true if adding, false if removing
|
* @param removed true if adding, false if removing
|
||||||
*/
|
*/
|
||||||
void updatePackageState(PackageSetting setting, boolean removed);
|
void updatePackageState(PackageSetting setting, boolean removed);
|
||||||
@@ -161,6 +194,7 @@ public class AppsFilter {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private SparseBooleanArray mLoggingEnabled = null;
|
private SparseBooleanArray mLoggingEnabled = null;
|
||||||
|
private AppsFilter mAppsFilter;
|
||||||
|
|
||||||
private FeatureConfigImpl(
|
private FeatureConfigImpl(
|
||||||
PackageManagerInternal pmInternal, PackageManagerService.Injector injector) {
|
PackageManagerInternal pmInternal, PackageManagerService.Injector injector) {
|
||||||
@@ -168,6 +202,10 @@ public class AppsFilter {
|
|||||||
mInjector = injector;
|
mInjector = injector;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setAppsFilter(AppsFilter filter) {
|
||||||
|
mAppsFilter = filter;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSystemReady() {
|
public void onSystemReady() {
|
||||||
mFeatureEnabled = DeviceConfig.getBoolean(
|
mFeatureEnabled = DeviceConfig.getBoolean(
|
||||||
@@ -235,6 +273,7 @@ public class AppsFilter {
|
|||||||
@Override
|
@Override
|
||||||
public void onCompatChange(String packageName) {
|
public void onCompatChange(String packageName) {
|
||||||
updateEnabledState(mPmInternal.getPackage(packageName));
|
updateEnabledState(mPmInternal.getPackage(packageName));
|
||||||
|
mAppsFilter.updateShouldFilterCacheForPackage(packageName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateEnabledState(AndroidPackage pkg) {
|
private void updateEnabledState(AndroidPackage pkg) {
|
||||||
@@ -267,7 +306,7 @@ public class AppsFilter {
|
|||||||
final boolean forceSystemAppsQueryable =
|
final boolean forceSystemAppsQueryable =
|
||||||
injector.getContext().getResources()
|
injector.getContext().getResources()
|
||||||
.getBoolean(R.bool.config_forceSystemPackagesQueryable);
|
.getBoolean(R.bool.config_forceSystemPackagesQueryable);
|
||||||
final FeatureConfig featureConfig = new FeatureConfigImpl(pms, injector);
|
final FeatureConfigImpl featureConfig = new FeatureConfigImpl(pms, injector);
|
||||||
final String[] forcedQueryablePackageNames;
|
final String[] forcedQueryablePackageNames;
|
||||||
if (forceSystemAppsQueryable) {
|
if (forceSystemAppsQueryable) {
|
||||||
// all system apps already queryable, no need to read and parse individual exceptions
|
// all system apps already queryable, no need to read and parse individual exceptions
|
||||||
@@ -280,8 +319,16 @@ public class AppsFilter {
|
|||||||
forcedQueryablePackageNames[i] = forcedQueryablePackageNames[i].intern();
|
forcedQueryablePackageNames[i] = forcedQueryablePackageNames[i].intern();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new AppsFilter(featureConfig, forcedQueryablePackageNames,
|
final StateProvider stateProvider = command -> {
|
||||||
forceSystemAppsQueryable, null);
|
synchronized (injector.getLock()) {
|
||||||
|
command.currentState(injector.getSettings().mPackages,
|
||||||
|
injector.getUserManagerService().getUsers(false, false, false));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
AppsFilter appsFilter = new AppsFilter(stateProvider, featureConfig,
|
||||||
|
forcedQueryablePackageNames, forceSystemAppsQueryable, null);
|
||||||
|
featureConfig.setAppsFilter(appsFilter);
|
||||||
|
return appsFilter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FeatureConfig getFeatureConfig() {
|
public FeatureConfig getFeatureConfig() {
|
||||||
@@ -407,24 +454,56 @@ public class AppsFilter {
|
|||||||
* @param visibleUid the uid becoming visible to the {@recipientUid}
|
* @param visibleUid the uid becoming visible to the {@recipientUid}
|
||||||
*/
|
*/
|
||||||
public void grantImplicitAccess(int recipientUid, int visibleUid) {
|
public void grantImplicitAccess(int recipientUid, int visibleUid) {
|
||||||
if (recipientUid != visibleUid
|
if (recipientUid != visibleUid) {
|
||||||
&& mImplicitlyQueryable.add(recipientUid, visibleUid) && DEBUG_LOGGING) {
|
if (mImplicitlyQueryable.add(recipientUid, visibleUid) && DEBUG_LOGGING) {
|
||||||
Slog.i(TAG, "implicit access granted: " + recipientUid + " -> " + visibleUid);
|
Slog.i(TAG, "implicit access granted: " + recipientUid + " -> " + visibleUid);
|
||||||
}
|
}
|
||||||
|
if (mShouldFilterCache != null) {
|
||||||
|
// update the cache in a one-off manner since we've got all the information we need.
|
||||||
|
SparseBooleanArray visibleUids = mShouldFilterCache.get(recipientUid);
|
||||||
|
if (visibleUids == null) {
|
||||||
|
visibleUids = new SparseBooleanArray();
|
||||||
|
mShouldFilterCache.put(recipientUid, visibleUids);
|
||||||
|
}
|
||||||
|
visibleUids.put(visibleUid, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onSystemReady() {
|
public void onSystemReady() {
|
||||||
|
mStateProvider.runWithState(new StateProvider.CurrentStateCallback() {
|
||||||
|
@Override
|
||||||
|
public void currentState(ArrayMap<String, PackageSetting> settings,
|
||||||
|
List<UserInfo> users) {
|
||||||
|
mShouldFilterCache = new SparseArray<>(users.size() * settings.size());
|
||||||
|
}
|
||||||
|
});
|
||||||
mFeatureConfig.onSystemReady();
|
mFeatureConfig.onSystemReady();
|
||||||
mOverlayReferenceMapper.rebuildIfDeferred();
|
mOverlayReferenceMapper.rebuildIfDeferred();
|
||||||
|
updateEntireShouldFilterCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 existingSettings all other settings currently on the device.
|
|
||||||
*/
|
*/
|
||||||
public void addPackage(PackageSetting newPkgSetting,
|
public void addPackage(PackageSetting newPkgSetting) {
|
||||||
|
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "filter.addPackage");
|
||||||
|
try {
|
||||||
|
mStateProvider.runWithState((settings, users) -> {
|
||||||
|
addPackageInternal(newPkgSetting, settings);
|
||||||
|
if (mShouldFilterCache != null) {
|
||||||
|
updateShouldFilterCacheForPackage(
|
||||||
|
null, newPkgSetting, settings, users, settings.size());
|
||||||
|
} // else, rebuild entire cache when system is ready
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addPackageInternal(PackageSetting newPkgSetting,
|
||||||
ArrayMap<String, PackageSetting> existingSettings) {
|
ArrayMap<String, PackageSetting> existingSettings) {
|
||||||
if (Objects.equals("android", newPkgSetting.name)) {
|
if (Objects.equals("android", newPkgSetting.name)) {
|
||||||
// let's set aside the framework signatures
|
// let's set aside the framework signatures
|
||||||
@@ -438,8 +517,6 @@ public class AppsFilter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "filter.addPackage");
|
|
||||||
try {
|
|
||||||
final AndroidPackage newPkg = newPkgSetting.pkg;
|
final AndroidPackage newPkg = newPkgSetting.pkg;
|
||||||
if (newPkg == null) {
|
if (newPkg == null) {
|
||||||
// nothing to add
|
// nothing to add
|
||||||
@@ -509,8 +586,84 @@ public class AppsFilter {
|
|||||||
}
|
}
|
||||||
mOverlayReferenceMapper.addPkg(newPkgSetting.pkg, existingPkgs);
|
mOverlayReferenceMapper.addPkg(newPkgSetting.pkg, existingPkgs);
|
||||||
mFeatureConfig.updatePackageState(newPkgSetting, false /*removed*/);
|
mFeatureConfig.updatePackageState(newPkgSetting, false /*removed*/);
|
||||||
} finally {
|
}
|
||||||
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
|
|
||||||
|
private void removeAppIdFromVisibilityCache(int appId) {
|
||||||
|
if (mShouldFilterCache == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (int i = mShouldFilterCache.size() - 1; i >= 0; i--) {
|
||||||
|
if (UserHandle.getAppId(mShouldFilterCache.keyAt(i)) == appId) {
|
||||||
|
mShouldFilterCache.removeAt(i);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
SparseBooleanArray targetSparseArray = mShouldFilterCache.valueAt(i);
|
||||||
|
for (int j = targetSparseArray.size() - 1; j >= 0; j--) {
|
||||||
|
if (UserHandle.getAppId(targetSparseArray.keyAt(j)) == appId) {
|
||||||
|
targetSparseArray.removeAt(j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateEntireShouldFilterCache() {
|
||||||
|
mStateProvider.runWithState((settings, users) -> {
|
||||||
|
mShouldFilterCache.clear();
|
||||||
|
for (int i = settings.size() - 1; i >= 0; i--) {
|
||||||
|
updateShouldFilterCacheForPackage(
|
||||||
|
null /*skipPackage*/, settings.valueAt(i), settings, users, i);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onUsersChanged() {
|
||||||
|
if (mShouldFilterCache != null) {
|
||||||
|
updateEntireShouldFilterCache();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateShouldFilterCacheForPackage(String packageName) {
|
||||||
|
mStateProvider.runWithState((settings, users) -> {
|
||||||
|
updateShouldFilterCacheForPackage(null /* skipPackage */, settings.get(packageName),
|
||||||
|
settings, users, settings.size() /*maxIndex*/);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateShouldFilterCacheForPackage(@Nullable String skipPackageName,
|
||||||
|
PackageSetting subjectSetting, ArrayMap<String, PackageSetting> allSettings,
|
||||||
|
List<UserInfo> allUsers, int maxIndex) {
|
||||||
|
for (int i = Math.min(maxIndex, allSettings.size() - 1); i >= 0; i--) {
|
||||||
|
PackageSetting otherSetting = allSettings.valueAt(i);
|
||||||
|
if (subjectSetting.appId == otherSetting.appId) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
//noinspection StringEquality
|
||||||
|
if (subjectSetting.name == skipPackageName || otherSetting.name == skipPackageName) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
final int userCount = allUsers.size();
|
||||||
|
final int appxUidCount = userCount * allSettings.size();
|
||||||
|
for (int su = 0; su < userCount; su++) {
|
||||||
|
int subjectUser = allUsers.get(su).id;
|
||||||
|
for (int ou = su; ou < userCount; ou++) {
|
||||||
|
int otherUser = allUsers.get(ou).id;
|
||||||
|
int subjectUid = UserHandle.getUid(subjectUser, subjectSetting.appId);
|
||||||
|
if (!mShouldFilterCache.contains(subjectUid)) {
|
||||||
|
mShouldFilterCache.put(subjectUid, new SparseBooleanArray(appxUidCount));
|
||||||
|
}
|
||||||
|
int otherUid = UserHandle.getUid(otherUser, otherSetting.appId);
|
||||||
|
if (!mShouldFilterCache.contains(otherUid)) {
|
||||||
|
mShouldFilterCache.put(otherUid, new SparseBooleanArray(appxUidCount));
|
||||||
|
}
|
||||||
|
mShouldFilterCache.get(subjectUid).put(otherUid,
|
||||||
|
shouldFilterApplicationInternal(
|
||||||
|
subjectUid, subjectSetting, otherSetting, otherUser));
|
||||||
|
mShouldFilterCache.get(otherUid).put(subjectUid,
|
||||||
|
shouldFilterApplicationInternal(
|
||||||
|
otherUid, otherSetting, subjectSetting, subjectUser));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -561,6 +714,7 @@ public class AppsFilter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches all app Ids that a given setting is currently visible to, per provided user. This
|
* Fetches all app Ids that a given setting is currently visible to, per provided user. This
|
||||||
* only includes UIDs >= {@link Process#FIRST_APPLICATION_UID} as all other UIDs can already see
|
* only includes UIDs >= {@link Process#FIRST_APPLICATION_UID} as all other UIDs can already see
|
||||||
@@ -619,14 +773,13 @@ public class AppsFilter {
|
|||||||
* 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 allUsers array of all current users on device.
|
|
||||||
*/
|
*/
|
||||||
public void removePackage(PackageSetting setting, int[] allUsers,
|
public void removePackage(PackageSetting setting) {
|
||||||
ArrayMap<String, PackageSetting> existingSettings) {
|
removeAppIdFromVisibilityCache(setting.appId);
|
||||||
mForceQueryable.remove(setting.appId);
|
mStateProvider.runWithState((settings, users) -> {
|
||||||
|
final int userCount = users.size();
|
||||||
for (int u = 0; u < allUsers.length; u++) {
|
for (int u = 0; u < userCount; u++) {
|
||||||
final int userId = allUsers[u];
|
final int userId = users.get(u).id;
|
||||||
final int removingUid = UserHandle.getUid(userId, setting.appId);
|
final int removingUid = UserHandle.getUid(userId, setting.appId);
|
||||||
mImplicitlyQueryable.remove(removingUid);
|
mImplicitlyQueryable.remove(removingUid);
|
||||||
for (int i = mImplicitlyQueryable.size() - 1; i >= 0; i--) {
|
for (int i = mImplicitlyQueryable.size() - 1; i >= 0; i--) {
|
||||||
@@ -650,7 +803,8 @@ public class AppsFilter {
|
|||||||
if (setting.sharedUser.packages.valueAt(i) == setting) {
|
if (setting.sharedUser.packages.valueAt(i) == setting) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
addPackage(setting.sharedUser.packages.valueAt(i), existingSettings);
|
addPackageInternal(
|
||||||
|
setting.sharedUser.packages.valueAt(i), settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -658,12 +812,21 @@ public class AppsFilter {
|
|||||||
final String removingPackageName = setting.pkg.getPackageName();
|
final String removingPackageName = setting.pkg.getPackageName();
|
||||||
mProtectedBroadcasts.clear();
|
mProtectedBroadcasts.clear();
|
||||||
mProtectedBroadcasts.addAll(
|
mProtectedBroadcasts.addAll(
|
||||||
collectProtectedBroadcasts(existingSettings, removingPackageName));
|
collectProtectedBroadcasts(settings, removingPackageName));
|
||||||
recomputeComponentVisibility(existingSettings, removingPackageName);
|
recomputeComponentVisibility(settings, removingPackageName);
|
||||||
}
|
}
|
||||||
|
|
||||||
mOverlayReferenceMapper.removePkg(setting.name);
|
mOverlayReferenceMapper.removePkg(setting.name);
|
||||||
mFeatureConfig.updatePackageState(setting, true /*removed*/);
|
mFeatureConfig.updatePackageState(setting, true /*removed*/);
|
||||||
|
|
||||||
|
if (mShouldFilterCache != null) {
|
||||||
|
updateShouldFilterCacheForPackage(
|
||||||
|
setting.name, setting, settings, users, settings.size());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
mForceQueryable.remove(setting.appId);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -680,11 +843,32 @@ public class AppsFilter {
|
|||||||
PackageSetting targetPkgSetting, int userId) {
|
PackageSetting targetPkgSetting, int userId) {
|
||||||
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "shouldFilterApplication");
|
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "shouldFilterApplication");
|
||||||
try {
|
try {
|
||||||
|
if (callingUid < Process.FIRST_APPLICATION_UID
|
||||||
|
|| UserHandle.getAppId(callingUid) == targetPkgSetting.appId) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (mShouldFilterCache != null) { // use cache
|
||||||
|
SparseBooleanArray shouldFilterTargets = mShouldFilterCache.get(callingUid);
|
||||||
|
final int targetUid = UserHandle.getUid(userId, targetPkgSetting.appId);
|
||||||
|
if (shouldFilterTargets == null) {
|
||||||
|
Slog.wtf(TAG, "Encountered calling uid with no cached rules: " + callingUid);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
int indexOfTargetUid = shouldFilterTargets.indexOfKey(targetUid);
|
||||||
|
if (indexOfTargetUid < 0) {
|
||||||
|
Slog.w(TAG, "Encountered calling -> target with no cached rules: "
|
||||||
|
+ callingUid + " -> " + targetUid);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!shouldFilterTargets.valueAt(indexOfTargetUid)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
if (!shouldFilterApplicationInternal(
|
if (!shouldFilterApplicationInternal(
|
||||||
callingUid, callingSetting, targetPkgSetting, userId)) {
|
callingUid, callingSetting, targetPkgSetting, userId)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (DEBUG_LOGGING || mFeatureConfig.isLoggingEnabled(UserHandle.getAppId(callingUid))) {
|
if (DEBUG_LOGGING || mFeatureConfig.isLoggingEnabled(UserHandle.getAppId(callingUid))) {
|
||||||
log(callingSetting, targetPkgSetting, "BLOCKED");
|
log(callingSetting, targetPkgSetting, "BLOCKED");
|
||||||
}
|
}
|
||||||
@@ -695,7 +879,7 @@ public class AppsFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean shouldFilterApplicationInternal(int callingUid, SettingBase callingSetting,
|
private boolean shouldFilterApplicationInternal(int callingUid, SettingBase callingSetting,
|
||||||
PackageSetting targetPkgSetting, int userId) {
|
PackageSetting targetPkgSetting, int targetUserId) {
|
||||||
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "shouldFilterApplicationInternal");
|
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "shouldFilterApplicationInternal");
|
||||||
try {
|
try {
|
||||||
final boolean featureEnabled = mFeatureConfig.isGloballyEnabled();
|
final boolean featureEnabled = mFeatureConfig.isGloballyEnabled();
|
||||||
@@ -705,12 +889,6 @@ public class AppsFilter {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (callingUid < Process.FIRST_APPLICATION_UID) {
|
|
||||||
if (DEBUG_LOGGING) {
|
|
||||||
Slog.d(TAG, "filtering skipped; " + callingUid + " is system");
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (callingSetting == null) {
|
if (callingSetting == null) {
|
||||||
Slog.wtf(TAG, "No setting found for non system uid " + callingUid);
|
Slog.wtf(TAG, "No setting found for non system uid " + callingUid);
|
||||||
return true;
|
return true;
|
||||||
@@ -719,8 +897,14 @@ public class AppsFilter {
|
|||||||
final ArraySet<PackageSetting> callingSharedPkgSettings;
|
final ArraySet<PackageSetting> callingSharedPkgSettings;
|
||||||
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "callingSetting instanceof");
|
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "callingSetting instanceof");
|
||||||
if (callingSetting instanceof PackageSetting) {
|
if (callingSetting instanceof PackageSetting) {
|
||||||
|
if (((PackageSetting) callingSetting).sharedUser == null) {
|
||||||
callingPkgSetting = (PackageSetting) callingSetting;
|
callingPkgSetting = (PackageSetting) callingSetting;
|
||||||
callingSharedPkgSettings = null;
|
callingSharedPkgSettings = null;
|
||||||
|
} else {
|
||||||
|
callingPkgSetting = null;
|
||||||
|
callingSharedPkgSettings =
|
||||||
|
((PackageSetting) callingSetting).sharedUser.packages;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
callingPkgSetting = null;
|
callingPkgSetting = null;
|
||||||
callingSharedPkgSettings = ((SharedUserSetting) callingSetting).packages;
|
callingSharedPkgSettings = ((SharedUserSetting) callingSetting).packages;
|
||||||
@@ -778,14 +962,18 @@ public class AppsFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "hasPermission");
|
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "requestsQueryAllPackages");
|
||||||
if (callingSetting.getPermissionsState().hasPermission(
|
if (callingPkgSetting != null) {
|
||||||
Manifest.permission.QUERY_ALL_PACKAGES, UserHandle.getUserId(callingUid))) {
|
if (requestsQueryAllPackages(callingPkgSetting)) {
|
||||||
if (DEBUG_LOGGING) {
|
|
||||||
log(callingSetting, targetPkgSetting, "has query-all permission");
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
for (int i = callingSharedPkgSettings.size() - 1; i >= 0; i--) {
|
||||||
|
if (requestsQueryAllPackages(callingSharedPkgSettings.valueAt(i))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
|
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
|
||||||
}
|
}
|
||||||
@@ -825,7 +1013,7 @@ public class AppsFilter {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "mImplicitlyQueryable");
|
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "mImplicitlyQueryable");
|
||||||
final int targetUid = UserHandle.getUid(userId, targetAppId);
|
final int targetUid = UserHandle.getUid(targetUserId, targetAppId);
|
||||||
if (mImplicitlyQueryable.contains(callingUid, targetUid)) {
|
if (mImplicitlyQueryable.contains(callingUid, targetUid)) {
|
||||||
if (DEBUG_LOGGING) {
|
if (DEBUG_LOGGING) {
|
||||||
log(callingSetting, targetPkgSetting, "implicitly queryable for user");
|
log(callingSetting, targetPkgSetting, "implicitly queryable for user");
|
||||||
@@ -863,13 +1051,20 @@ public class AppsFilter {
|
|||||||
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
|
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} finally {
|
} finally {
|
||||||
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
|
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static boolean requestsQueryAllPackages(PackageSetting pkgSetting) {
|
||||||
|
// we're not guaranteed to have permissions yet analyzed at package add, so we inspect the
|
||||||
|
// package directly
|
||||||
|
return pkgSetting.pkg.getRequestedPermissions().contains(
|
||||||
|
Manifest.permission.QUERY_ALL_PACKAGES);
|
||||||
|
}
|
||||||
|
|
||||||
/** Returns {@code true} if the source package instruments the target package. */
|
/** Returns {@code true} if the source package instruments the target package. */
|
||||||
private static boolean pkgInstruments(PackageSetting source, PackageSetting target) {
|
private static boolean pkgInstruments(PackageSetting source, PackageSetting target) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -12359,7 +12359,7 @@ public class PackageManagerService extends IPackageManager.Stub
|
|||||||
ksms.addScannedPackageLPw(pkg);
|
ksms.addScannedPackageLPw(pkg);
|
||||||
|
|
||||||
mComponentResolver.addAllComponents(pkg, chatty);
|
mComponentResolver.addAllComponents(pkg, chatty);
|
||||||
mAppsFilter.addPackage(pkgSetting, mSettings.mPackages);
|
mAppsFilter.addPackage(pkgSetting);
|
||||||
|
|
||||||
// Don't allow ephemeral applications to define new permissions groups.
|
// Don't allow ephemeral applications to define new permissions groups.
|
||||||
if ((scanFlags & SCAN_AS_INSTANT_APP) != 0) {
|
if ((scanFlags & SCAN_AS_INSTANT_APP) != 0) {
|
||||||
@@ -12533,8 +12533,6 @@ public class PackageManagerService extends IPackageManager.Stub
|
|||||||
|
|
||||||
void cleanPackageDataStructuresLILPw(AndroidPackage pkg, boolean chatty) {
|
void cleanPackageDataStructuresLILPw(AndroidPackage pkg, boolean chatty) {
|
||||||
mComponentResolver.removeAllComponents(pkg, chatty);
|
mComponentResolver.removeAllComponents(pkg, chatty);
|
||||||
mAppsFilter.removePackage(getPackageSetting(pkg.getPackageName()),
|
|
||||||
mInjector.getUserManagerInternal().getUserIds(), mSettings.mPackages);
|
|
||||||
mPermissionManager.removeAllPermissions(pkg, chatty);
|
mPermissionManager.removeAllPermissions(pkg, chatty);
|
||||||
|
|
||||||
final int instrumentationSize = ArrayUtils.size(pkg.getInstrumentations());
|
final int instrumentationSize = ArrayUtils.size(pkg.getInstrumentations());
|
||||||
@@ -14261,7 +14259,7 @@ public class PackageManagerService extends IPackageManager.Stub
|
|||||||
// Okay!
|
// Okay!
|
||||||
targetPackageSetting.setInstallerPackageName(installerPackageName);
|
targetPackageSetting.setInstallerPackageName(installerPackageName);
|
||||||
mSettings.addInstallerPackageNames(targetPackageSetting.installSource);
|
mSettings.addInstallerPackageNames(targetPackageSetting.installSource);
|
||||||
mAppsFilter.addPackage(targetPackageSetting, mSettings.mPackages);
|
mAppsFilter.addPackage(targetPackageSetting);
|
||||||
scheduleWriteSettingsLocked();
|
scheduleWriteSettingsLocked();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -18686,6 +18684,7 @@ public class PackageManagerService extends IPackageManager.Stub
|
|||||||
clearIntentFilterVerificationsLPw(deletedPs.name, UserHandle.USER_ALL, true);
|
clearIntentFilterVerificationsLPw(deletedPs.name, UserHandle.USER_ALL, true);
|
||||||
clearDefaultBrowserIfNeeded(packageName);
|
clearDefaultBrowserIfNeeded(packageName);
|
||||||
mSettings.mKeySetManagerService.removeAppKeySetDataLPw(packageName);
|
mSettings.mKeySetManagerService.removeAppKeySetDataLPw(packageName);
|
||||||
|
mAppsFilter.removePackage(getPackageSetting(packageName));
|
||||||
removedAppId = mSettings.removePackageLPw(packageName);
|
removedAppId = mSettings.removePackageLPw(packageName);
|
||||||
if (outInfo != null) {
|
if (outInfo != null) {
|
||||||
outInfo.removedAppId = removedAppId;
|
outInfo.removedAppId = removedAppId;
|
||||||
@@ -23443,6 +23442,7 @@ public class PackageManagerService extends IPackageManager.Stub
|
|||||||
scheduleWritePackageRestrictionsLocked(userId);
|
scheduleWritePackageRestrictionsLocked(userId);
|
||||||
scheduleWritePackageListLocked(userId);
|
scheduleWritePackageListLocked(userId);
|
||||||
primeDomainVerificationsLPw(userId);
|
primeDomainVerificationsLPw(userId);
|
||||||
|
mAppsFilter.onUsersChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import static org.hamcrest.Matchers.empty;
|
|||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.Mockito.doAnswer;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@@ -32,6 +33,7 @@ import android.content.IntentFilter;
|
|||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.content.pm.PackageParser;
|
import android.content.pm.PackageParser;
|
||||||
import android.content.pm.Signature;
|
import android.content.pm.Signature;
|
||||||
|
import android.content.pm.UserInfo;
|
||||||
import android.content.pm.parsing.ParsingPackage;
|
import android.content.pm.parsing.ParsingPackage;
|
||||||
import android.content.pm.parsing.component.ParsedActivity;
|
import android.content.pm.parsing.component.ParsedActivity;
|
||||||
import android.content.pm.parsing.component.ParsedInstrumentation;
|
import android.content.pm.parsing.component.ParsedInstrumentation;
|
||||||
@@ -39,9 +41,11 @@ import android.content.pm.parsing.component.ParsedIntentInfo;
|
|||||||
import android.content.pm.parsing.component.ParsedProvider;
|
import android.content.pm.parsing.component.ParsedProvider;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
|
import android.os.UserHandle;
|
||||||
import android.platform.test.annotations.Presubmit;
|
import android.platform.test.annotations.Presubmit;
|
||||||
import android.util.ArrayMap;
|
import android.util.ArrayMap;
|
||||||
import android.util.ArraySet;
|
import android.util.ArraySet;
|
||||||
|
import android.util.SparseArray;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
@@ -57,26 +61,36 @@ import org.junit.runners.JUnit4;
|
|||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
|
import org.mockito.stubbing.Answer;
|
||||||
|
|
||||||
import java.security.cert.CertificateException;
|
import java.security.cert.CertificateException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.function.IntFunction;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Presubmit
|
@Presubmit
|
||||||
@RunWith(JUnit4.class)
|
@RunWith(JUnit4.class)
|
||||||
public class AppsFilterTest {
|
public class AppsFilterTest {
|
||||||
|
|
||||||
private static final int DUMMY_CALLING_UID = 10345;
|
private static final int DUMMY_CALLING_APPID = 10345;
|
||||||
private static final int DUMMY_TARGET_UID = 10556;
|
private static final int DUMMY_TARGET_APPID = 10556;
|
||||||
private static final int DUMMY_ACTOR_UID = 10656;
|
private static final int DUMMY_ACTOR_APPID = 10656;
|
||||||
private static final int DUMMY_OVERLAY_UID = 10756;
|
private static final int DUMMY_OVERLAY_APPID = 10756;
|
||||||
private static final int DUMMY_ACTOR_TWO_UID = 10856;
|
private static final int SYSTEM_USER = 0;
|
||||||
|
private static final int SECONDARY_USER = 10;
|
||||||
|
private static final int[] USER_ARRAY = {SYSTEM_USER, SECONDARY_USER};
|
||||||
|
private static final List<UserInfo> USER_INFO_LIST = Arrays.stream(USER_ARRAY).mapToObj(
|
||||||
|
id -> new UserInfo(id, Integer.toString(id), 0)).collect(Collectors.toList());
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
AppsFilter.FeatureConfig mFeatureConfigMock;
|
AppsFilter.FeatureConfig mFeatureConfigMock;
|
||||||
|
@Mock
|
||||||
|
AppsFilter.StateProvider mStateProvider;
|
||||||
|
|
||||||
private ArrayMap<String, PackageSetting> mExisting = new ArrayMap<>();
|
private ArrayMap<String, PackageSetting> mExisting = new ArrayMap<>();
|
||||||
|
|
||||||
@@ -170,15 +184,24 @@ public class AppsFilterTest {
|
|||||||
mExisting = new ArrayMap<>();
|
mExisting = new ArrayMap<>();
|
||||||
|
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
|
doAnswer(invocation -> {
|
||||||
|
((AppsFilter.StateProvider.CurrentStateCallback) invocation.getArgument(0))
|
||||||
|
.currentState(mExisting, USER_INFO_LIST);
|
||||||
|
return null;
|
||||||
|
}).when(mStateProvider)
|
||||||
|
.runWithState(any(AppsFilter.StateProvider.CurrentStateCallback.class));
|
||||||
|
|
||||||
when(mFeatureConfigMock.isGloballyEnabled()).thenReturn(true);
|
when(mFeatureConfigMock.isGloballyEnabled()).thenReturn(true);
|
||||||
when(mFeatureConfigMock.packageIsEnabled(any(AndroidPackage.class)))
|
when(mFeatureConfigMock.packageIsEnabled(any(AndroidPackage.class))).thenAnswer(
|
||||||
.thenReturn(true);
|
(Answer<Boolean>) invocation ->
|
||||||
|
((AndroidPackage)invocation.getArgument(SYSTEM_USER)).getTargetSdkVersion()
|
||||||
|
>= Build.VERSION_CODES.R);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSystemReadyPropogates() throws Exception {
|
public void testSystemReadyPropogates() throws Exception {
|
||||||
final AppsFilter appsFilter =
|
final AppsFilter appsFilter =
|
||||||
new AppsFilter(mFeatureConfigMock, new String[]{}, false, null);
|
new AppsFilter(mStateProvider, mFeatureConfigMock, new String[]{}, false, null);
|
||||||
appsFilter.onSystemReady();
|
appsFilter.onSystemReady();
|
||||||
verify(mFeatureConfigMock).onSystemReady();
|
verify(mFeatureConfigMock).onSystemReady();
|
||||||
}
|
}
|
||||||
@@ -186,22 +209,23 @@ public class AppsFilterTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testQueriesAction_FilterMatches() throws Exception {
|
public void testQueriesAction_FilterMatches() throws Exception {
|
||||||
final AppsFilter appsFilter =
|
final AppsFilter appsFilter =
|
||||||
new AppsFilter(mFeatureConfigMock, new String[]{}, false, null);
|
new AppsFilter(mStateProvider, mFeatureConfigMock, new String[]{}, false, null);
|
||||||
simulateAddBasicAndroid(appsFilter);
|
simulateAddBasicAndroid(appsFilter);
|
||||||
appsFilter.onSystemReady();
|
appsFilter.onSystemReady();
|
||||||
|
|
||||||
PackageSetting target = simulateAddPackage(appsFilter,
|
PackageSetting target = simulateAddPackage(appsFilter,
|
||||||
pkg("com.some.package", new IntentFilter("TEST_ACTION")), DUMMY_TARGET_UID);
|
pkg("com.some.package", new IntentFilter("TEST_ACTION")), DUMMY_TARGET_APPID);
|
||||||
PackageSetting calling = simulateAddPackage(appsFilter,
|
PackageSetting calling = simulateAddPackage(appsFilter,
|
||||||
pkg("com.some.other.package", new Intent("TEST_ACTION")), DUMMY_CALLING_UID);
|
pkg("com.some.other.package", new Intent("TEST_ACTION")), DUMMY_CALLING_APPID);
|
||||||
|
|
||||||
assertFalse(appsFilter.shouldFilterApplication(DUMMY_CALLING_UID, calling, target, 0));
|
assertFalse(appsFilter.shouldFilterApplication(DUMMY_CALLING_APPID, calling, target,
|
||||||
|
SYSTEM_USER));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testQueriesProtectedAction_FilterDoesNotMatch() throws Exception {
|
public void testQueriesProtectedAction_FilterDoesNotMatch() throws Exception {
|
||||||
final AppsFilter appsFilter =
|
final AppsFilter appsFilter =
|
||||||
new AppsFilter(mFeatureConfigMock, new String[]{}, false, null);
|
new AppsFilter(mStateProvider, mFeatureConfigMock, new String[]{}, false, null);
|
||||||
final Signature frameworkSignature = Mockito.mock(Signature.class);
|
final Signature frameworkSignature = Mockito.mock(Signature.class);
|
||||||
final PackageParser.SigningDetails frameworkSigningDetails =
|
final PackageParser.SigningDetails frameworkSigningDetails =
|
||||||
new PackageParser.SigningDetails(new Signature[]{frameworkSignature}, 1);
|
new PackageParser.SigningDetails(new Signature[]{frameworkSignature}, 1);
|
||||||
@@ -211,164 +235,174 @@ public class AppsFilterTest {
|
|||||||
b -> b.setSigningDetails(frameworkSigningDetails));
|
b -> b.setSigningDetails(frameworkSigningDetails));
|
||||||
appsFilter.onSystemReady();
|
appsFilter.onSystemReady();
|
||||||
|
|
||||||
final int activityUid = DUMMY_TARGET_UID;
|
final int activityUid = DUMMY_TARGET_APPID;
|
||||||
PackageSetting targetActivity = simulateAddPackage(appsFilter,
|
PackageSetting targetActivity = simulateAddPackage(appsFilter,
|
||||||
pkg("com.target.activity", new IntentFilter("TEST_ACTION")), activityUid);
|
pkg("com.target.activity", new IntentFilter("TEST_ACTION")), activityUid);
|
||||||
final int receiverUid = DUMMY_TARGET_UID + 1;
|
final int receiverUid = DUMMY_TARGET_APPID + 1;
|
||||||
PackageSetting targetReceiver = simulateAddPackage(appsFilter,
|
PackageSetting targetReceiver = simulateAddPackage(appsFilter,
|
||||||
pkgWithReceiver("com.target.receiver", new IntentFilter("TEST_ACTION")),
|
pkgWithReceiver("com.target.receiver", new IntentFilter("TEST_ACTION")),
|
||||||
receiverUid);
|
receiverUid);
|
||||||
final int callingUid = DUMMY_CALLING_UID;
|
final int callingUid = DUMMY_CALLING_APPID;
|
||||||
PackageSetting calling = simulateAddPackage(appsFilter,
|
PackageSetting calling = simulateAddPackage(appsFilter,
|
||||||
pkg("com.calling.action", new Intent("TEST_ACTION")), callingUid);
|
pkg("com.calling.action", new Intent("TEST_ACTION")), callingUid);
|
||||||
final int wildcardUid = DUMMY_CALLING_UID + 1;
|
final int wildcardUid = DUMMY_CALLING_APPID + 1;
|
||||||
PackageSetting callingWildCard = simulateAddPackage(appsFilter,
|
PackageSetting callingWildCard = simulateAddPackage(appsFilter,
|
||||||
pkg("com.calling.wildcard", new Intent("*")), wildcardUid);
|
pkg("com.calling.wildcard", new Intent("*")), wildcardUid);
|
||||||
|
|
||||||
assertFalse(appsFilter.shouldFilterApplication(callingUid, calling, targetActivity, 0));
|
assertFalse(appsFilter.shouldFilterApplication(callingUid, calling, targetActivity,
|
||||||
assertTrue(appsFilter.shouldFilterApplication(callingUid, calling, targetReceiver, 0));
|
SYSTEM_USER));
|
||||||
|
assertTrue(appsFilter.shouldFilterApplication(callingUid, calling, targetReceiver,
|
||||||
|
SYSTEM_USER));
|
||||||
|
|
||||||
assertFalse(appsFilter.shouldFilterApplication(
|
assertFalse(appsFilter.shouldFilterApplication(
|
||||||
wildcardUid, callingWildCard, targetActivity, 0));
|
wildcardUid, callingWildCard, targetActivity, SYSTEM_USER));
|
||||||
assertTrue(appsFilter.shouldFilterApplication(
|
assertTrue(appsFilter.shouldFilterApplication(
|
||||||
wildcardUid, callingWildCard, targetReceiver, 0));
|
wildcardUid, callingWildCard, targetReceiver, SYSTEM_USER));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testQueriesProvider_FilterMatches() throws Exception {
|
public void testQueriesProvider_FilterMatches() throws Exception {
|
||||||
final AppsFilter appsFilter =
|
final AppsFilter appsFilter =
|
||||||
new AppsFilter(mFeatureConfigMock, new String[]{}, false, null);
|
new AppsFilter(mStateProvider, mFeatureConfigMock, new String[]{}, false, null);
|
||||||
simulateAddBasicAndroid(appsFilter);
|
simulateAddBasicAndroid(appsFilter);
|
||||||
appsFilter.onSystemReady();
|
appsFilter.onSystemReady();
|
||||||
|
|
||||||
PackageSetting target = simulateAddPackage(appsFilter,
|
PackageSetting target = simulateAddPackage(appsFilter,
|
||||||
pkgWithProvider("com.some.package", "com.some.authority"), DUMMY_TARGET_UID);
|
pkgWithProvider("com.some.package", "com.some.authority"), DUMMY_TARGET_APPID);
|
||||||
PackageSetting calling = simulateAddPackage(appsFilter,
|
PackageSetting calling = simulateAddPackage(appsFilter,
|
||||||
pkgQueriesProvider("com.some.other.package", "com.some.authority"),
|
pkgQueriesProvider("com.some.other.package", "com.some.authority"),
|
||||||
DUMMY_CALLING_UID);
|
DUMMY_CALLING_APPID);
|
||||||
|
|
||||||
assertFalse(appsFilter.shouldFilterApplication(DUMMY_CALLING_UID, calling, target, 0));
|
assertFalse(appsFilter.shouldFilterApplication(DUMMY_CALLING_APPID, calling, target,
|
||||||
|
SYSTEM_USER));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testQueriesDifferentProvider_Filters() throws Exception {
|
public void testQueriesDifferentProvider_Filters() throws Exception {
|
||||||
final AppsFilter appsFilter =
|
final AppsFilter appsFilter =
|
||||||
new AppsFilter(mFeatureConfigMock, new String[]{}, false, null);
|
new AppsFilter(mStateProvider, mFeatureConfigMock, new String[]{}, false, null);
|
||||||
simulateAddBasicAndroid(appsFilter);
|
simulateAddBasicAndroid(appsFilter);
|
||||||
appsFilter.onSystemReady();
|
appsFilter.onSystemReady();
|
||||||
|
|
||||||
PackageSetting target = simulateAddPackage(appsFilter,
|
PackageSetting target = simulateAddPackage(appsFilter,
|
||||||
pkgWithProvider("com.some.package", "com.some.authority"), DUMMY_TARGET_UID);
|
pkgWithProvider("com.some.package", "com.some.authority"), DUMMY_TARGET_APPID);
|
||||||
PackageSetting calling = simulateAddPackage(appsFilter,
|
PackageSetting calling = simulateAddPackage(appsFilter,
|
||||||
pkgQueriesProvider("com.some.other.package", "com.some.other.authority"),
|
pkgQueriesProvider("com.some.other.package", "com.some.other.authority"),
|
||||||
DUMMY_CALLING_UID);
|
DUMMY_CALLING_APPID);
|
||||||
|
|
||||||
assertTrue(appsFilter.shouldFilterApplication(DUMMY_CALLING_UID, calling, target, 0));
|
assertTrue(appsFilter.shouldFilterApplication(DUMMY_CALLING_APPID, calling, target,
|
||||||
|
SYSTEM_USER));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testQueriesProviderWithSemiColon_FilterMatches() throws Exception {
|
public void testQueriesProviderWithSemiColon_FilterMatches() throws Exception {
|
||||||
final AppsFilter appsFilter =
|
final AppsFilter appsFilter =
|
||||||
new AppsFilter(mFeatureConfigMock, new String[]{}, false, null);
|
new AppsFilter(mStateProvider, mFeatureConfigMock, new String[]{}, false, null);
|
||||||
simulateAddBasicAndroid(appsFilter);
|
simulateAddBasicAndroid(appsFilter);
|
||||||
appsFilter.onSystemReady();
|
appsFilter.onSystemReady();
|
||||||
|
|
||||||
PackageSetting target = simulateAddPackage(appsFilter,
|
PackageSetting target = simulateAddPackage(appsFilter,
|
||||||
pkgWithProvider("com.some.package", "com.some.authority;com.some.other.authority"),
|
pkgWithProvider("com.some.package", "com.some.authority;com.some.other.authority"),
|
||||||
DUMMY_TARGET_UID);
|
DUMMY_TARGET_APPID);
|
||||||
PackageSetting calling = simulateAddPackage(appsFilter,
|
PackageSetting calling = simulateAddPackage(appsFilter,
|
||||||
pkgQueriesProvider("com.some.other.package", "com.some.authority"),
|
pkgQueriesProvider("com.some.other.package", "com.some.authority"),
|
||||||
DUMMY_CALLING_UID);
|
DUMMY_CALLING_APPID);
|
||||||
|
|
||||||
assertFalse(appsFilter.shouldFilterApplication(DUMMY_CALLING_UID, calling, target, 0));
|
assertFalse(appsFilter.shouldFilterApplication(DUMMY_CALLING_APPID, calling, target,
|
||||||
|
SYSTEM_USER));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testQueriesAction_NoMatchingAction_Filters() throws Exception {
|
public void testQueriesAction_NoMatchingAction_Filters() throws Exception {
|
||||||
final AppsFilter appsFilter =
|
final AppsFilter appsFilter =
|
||||||
new AppsFilter(mFeatureConfigMock, new String[]{}, false, null);
|
new AppsFilter(mStateProvider, mFeatureConfigMock, new String[]{}, false, null);
|
||||||
simulateAddBasicAndroid(appsFilter);
|
simulateAddBasicAndroid(appsFilter);
|
||||||
appsFilter.onSystemReady();
|
appsFilter.onSystemReady();
|
||||||
|
|
||||||
PackageSetting target = simulateAddPackage(appsFilter,
|
PackageSetting target = simulateAddPackage(appsFilter,
|
||||||
pkg("com.some.package"), DUMMY_TARGET_UID);
|
pkg("com.some.package"), DUMMY_TARGET_APPID);
|
||||||
PackageSetting calling = simulateAddPackage(appsFilter,
|
PackageSetting calling = simulateAddPackage(appsFilter,
|
||||||
pkg("com.some.other.package", new Intent("TEST_ACTION")), DUMMY_CALLING_UID);
|
pkg("com.some.other.package", new Intent("TEST_ACTION")), DUMMY_CALLING_APPID);
|
||||||
|
|
||||||
assertTrue(appsFilter.shouldFilterApplication(DUMMY_CALLING_UID, calling, target, 0));
|
assertTrue(appsFilter.shouldFilterApplication(DUMMY_CALLING_APPID, calling, target,
|
||||||
|
SYSTEM_USER));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testQueriesAction_NoMatchingActionFilterLowSdk_DoesntFilter() throws Exception {
|
public void testQueriesAction_NoMatchingActionFilterLowSdk_DoesntFilter() throws Exception {
|
||||||
final AppsFilter appsFilter =
|
final AppsFilter appsFilter =
|
||||||
new AppsFilter(mFeatureConfigMock, new String[]{}, false, null);
|
new AppsFilter(mStateProvider, mFeatureConfigMock, new String[]{}, false, null);
|
||||||
simulateAddBasicAndroid(appsFilter);
|
simulateAddBasicAndroid(appsFilter);
|
||||||
appsFilter.onSystemReady();
|
appsFilter.onSystemReady();
|
||||||
|
|
||||||
PackageSetting target = simulateAddPackage(appsFilter,
|
PackageSetting target = simulateAddPackage(appsFilter,
|
||||||
pkg("com.some.package"), DUMMY_TARGET_UID);
|
pkg("com.some.package"), DUMMY_TARGET_APPID);
|
||||||
PackageSetting calling = simulateAddPackage(appsFilter,
|
ParsingPackage callingPkg = pkg("com.some.other.package",
|
||||||
pkg("com.some.other.package",
|
|
||||||
new Intent("TEST_ACTION"))
|
new Intent("TEST_ACTION"))
|
||||||
.setTargetSdkVersion(Build.VERSION_CODES.P),
|
.setTargetSdkVersion(Build.VERSION_CODES.P);
|
||||||
DUMMY_CALLING_UID);
|
PackageSetting calling = simulateAddPackage(appsFilter, callingPkg,
|
||||||
|
DUMMY_CALLING_APPID);
|
||||||
|
|
||||||
when(mFeatureConfigMock.packageIsEnabled(calling.pkg)).thenReturn(false);
|
|
||||||
|
|
||||||
assertFalse(appsFilter.shouldFilterApplication(DUMMY_CALLING_UID, calling, target, 0));
|
assertFalse(appsFilter.shouldFilterApplication(DUMMY_CALLING_APPID, calling, target,
|
||||||
|
SYSTEM_USER));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoQueries_Filters() throws Exception {
|
public void testNoQueries_Filters() throws Exception {
|
||||||
final AppsFilter appsFilter =
|
final AppsFilter appsFilter =
|
||||||
new AppsFilter(mFeatureConfigMock, new String[]{}, false, null);
|
new AppsFilter(mStateProvider, mFeatureConfigMock, new String[]{}, false, null);
|
||||||
simulateAddBasicAndroid(appsFilter);
|
simulateAddBasicAndroid(appsFilter);
|
||||||
appsFilter.onSystemReady();
|
appsFilter.onSystemReady();
|
||||||
|
|
||||||
PackageSetting target = simulateAddPackage(appsFilter,
|
PackageSetting target = simulateAddPackage(appsFilter,
|
||||||
pkg("com.some.package"), DUMMY_TARGET_UID);
|
pkg("com.some.package"), DUMMY_TARGET_APPID);
|
||||||
PackageSetting calling = simulateAddPackage(appsFilter,
|
PackageSetting calling = simulateAddPackage(appsFilter,
|
||||||
pkg("com.some.other.package"), DUMMY_CALLING_UID);
|
pkg("com.some.other.package"), DUMMY_CALLING_APPID);
|
||||||
|
|
||||||
assertTrue(appsFilter.shouldFilterApplication(DUMMY_CALLING_UID, calling, target, 0));
|
assertTrue(appsFilter.shouldFilterApplication(DUMMY_CALLING_APPID, calling, target,
|
||||||
|
SYSTEM_USER));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testForceQueryable_DoesntFilter() throws Exception {
|
public void testForceQueryable_DoesntFilter() throws Exception {
|
||||||
final AppsFilter appsFilter =
|
final AppsFilter appsFilter =
|
||||||
new AppsFilter(mFeatureConfigMock, new String[]{}, false, null);
|
new AppsFilter(mStateProvider, mFeatureConfigMock, new String[]{}, false, null);
|
||||||
simulateAddBasicAndroid(appsFilter);
|
simulateAddBasicAndroid(appsFilter);
|
||||||
appsFilter.onSystemReady();
|
appsFilter.onSystemReady();
|
||||||
|
|
||||||
PackageSetting target = simulateAddPackage(appsFilter,
|
PackageSetting target = simulateAddPackage(appsFilter,
|
||||||
pkg("com.some.package").setForceQueryable(true), DUMMY_TARGET_UID);
|
pkg("com.some.package").setForceQueryable(true), DUMMY_TARGET_APPID);
|
||||||
PackageSetting calling = simulateAddPackage(appsFilter,
|
PackageSetting calling = simulateAddPackage(appsFilter,
|
||||||
pkg("com.some.other.package"), DUMMY_CALLING_UID);
|
pkg("com.some.other.package"), DUMMY_CALLING_APPID);
|
||||||
|
|
||||||
assertFalse(appsFilter.shouldFilterApplication(DUMMY_CALLING_UID, calling, target, 0));
|
assertFalse(appsFilter.shouldFilterApplication(DUMMY_CALLING_APPID, calling, target,
|
||||||
|
SYSTEM_USER));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testForceQueryableByDevice_SystemCaller_DoesntFilter() throws Exception {
|
public void testForceQueryableByDevice_SystemCaller_DoesntFilter() throws Exception {
|
||||||
final AppsFilter appsFilter =
|
final AppsFilter appsFilter =
|
||||||
new AppsFilter(mFeatureConfigMock, new String[]{"com.some.package"}, false, null);
|
new AppsFilter(mStateProvider, mFeatureConfigMock, new String[]{"com.some.package"},
|
||||||
|
false, null);
|
||||||
simulateAddBasicAndroid(appsFilter);
|
simulateAddBasicAndroid(appsFilter);
|
||||||
appsFilter.onSystemReady();
|
appsFilter.onSystemReady();
|
||||||
|
|
||||||
PackageSetting target = simulateAddPackage(appsFilter,
|
PackageSetting target = simulateAddPackage(appsFilter,
|
||||||
pkg("com.some.package"), DUMMY_TARGET_UID,
|
pkg("com.some.package"), DUMMY_TARGET_APPID,
|
||||||
setting -> setting.setPkgFlags(ApplicationInfo.FLAG_SYSTEM));
|
setting -> setting.setPkgFlags(ApplicationInfo.FLAG_SYSTEM));
|
||||||
PackageSetting calling = simulateAddPackage(appsFilter,
|
PackageSetting calling = simulateAddPackage(appsFilter,
|
||||||
pkg("com.some.other.package"), DUMMY_CALLING_UID);
|
pkg("com.some.other.package"), DUMMY_CALLING_APPID);
|
||||||
|
|
||||||
assertFalse(appsFilter.shouldFilterApplication(DUMMY_CALLING_UID, calling, target, 0));
|
assertFalse(appsFilter.shouldFilterApplication(DUMMY_CALLING_APPID, calling, target,
|
||||||
|
SYSTEM_USER));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSystemSignedTarget_DoesntFilter() throws CertificateException {
|
public void testSystemSignedTarget_DoesntFilter() throws CertificateException {
|
||||||
final AppsFilter appsFilter =
|
final AppsFilter appsFilter =
|
||||||
new AppsFilter(mFeatureConfigMock, new String[]{}, false, null);
|
new AppsFilter(mStateProvider, mFeatureConfigMock, new String[]{}, false, null);
|
||||||
appsFilter.onSystemReady();
|
appsFilter.onSystemReady();
|
||||||
|
|
||||||
final Signature frameworkSignature = Mockito.mock(Signature.class);
|
final Signature frameworkSignature = Mockito.mock(Signature.class);
|
||||||
@@ -382,62 +416,67 @@ public class AppsFilterTest {
|
|||||||
simulateAddPackage(appsFilter, pkg("android"), 1000,
|
simulateAddPackage(appsFilter, pkg("android"), 1000,
|
||||||
b -> b.setSigningDetails(frameworkSigningDetails));
|
b -> b.setSigningDetails(frameworkSigningDetails));
|
||||||
PackageSetting target = simulateAddPackage(appsFilter, pkg("com.some.package"),
|
PackageSetting target = simulateAddPackage(appsFilter, pkg("com.some.package"),
|
||||||
DUMMY_TARGET_UID,
|
DUMMY_TARGET_APPID,
|
||||||
b -> b.setSigningDetails(frameworkSigningDetails)
|
b -> b.setSigningDetails(frameworkSigningDetails)
|
||||||
.setPkgFlags(ApplicationInfo.FLAG_SYSTEM));
|
.setPkgFlags(ApplicationInfo.FLAG_SYSTEM));
|
||||||
PackageSetting calling = simulateAddPackage(appsFilter,
|
PackageSetting calling = simulateAddPackage(appsFilter,
|
||||||
pkg("com.some.other.package"), DUMMY_CALLING_UID,
|
pkg("com.some.other.package"), DUMMY_CALLING_APPID,
|
||||||
b -> b.setSigningDetails(otherSigningDetails));
|
b -> b.setSigningDetails(otherSigningDetails));
|
||||||
|
|
||||||
assertFalse(appsFilter.shouldFilterApplication(DUMMY_CALLING_UID, calling, target, 0));
|
assertFalse(appsFilter.shouldFilterApplication(DUMMY_CALLING_APPID, calling, target,
|
||||||
|
SYSTEM_USER));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testForceQueryableByDevice_NonSystemCaller_Filters() throws Exception {
|
public void testForceQueryableByDevice_NonSystemCaller_Filters() throws Exception {
|
||||||
final AppsFilter appsFilter =
|
final AppsFilter appsFilter =
|
||||||
new AppsFilter(mFeatureConfigMock, new String[]{"com.some.package"}, false, null);
|
new AppsFilter(mStateProvider, mFeatureConfigMock, new String[]{"com.some.package"},
|
||||||
|
false, null);
|
||||||
simulateAddBasicAndroid(appsFilter);
|
simulateAddBasicAndroid(appsFilter);
|
||||||
appsFilter.onSystemReady();
|
appsFilter.onSystemReady();
|
||||||
|
|
||||||
PackageSetting target = simulateAddPackage(appsFilter,
|
PackageSetting target = simulateAddPackage(appsFilter,
|
||||||
pkg("com.some.package"), DUMMY_TARGET_UID);
|
pkg("com.some.package"), DUMMY_TARGET_APPID);
|
||||||
PackageSetting calling = simulateAddPackage(appsFilter,
|
PackageSetting calling = simulateAddPackage(appsFilter,
|
||||||
pkg("com.some.other.package"), DUMMY_CALLING_UID);
|
pkg("com.some.other.package"), DUMMY_CALLING_APPID);
|
||||||
|
|
||||||
assertTrue(appsFilter.shouldFilterApplication(DUMMY_CALLING_UID, calling, target, 0));
|
assertTrue(appsFilter.shouldFilterApplication(DUMMY_CALLING_APPID, calling, target,
|
||||||
|
SYSTEM_USER));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSystemQueryable_DoesntFilter() throws Exception {
|
public void testSystemQueryable_DoesntFilter() throws Exception {
|
||||||
final AppsFilter appsFilter =
|
final AppsFilter appsFilter =
|
||||||
new AppsFilter(mFeatureConfigMock, new String[]{},
|
new AppsFilter(mStateProvider, mFeatureConfigMock, new String[]{},
|
||||||
true /* system force queryable */, null);
|
true /* system force queryable */, null);
|
||||||
simulateAddBasicAndroid(appsFilter);
|
simulateAddBasicAndroid(appsFilter);
|
||||||
appsFilter.onSystemReady();
|
appsFilter.onSystemReady();
|
||||||
|
|
||||||
PackageSetting target = simulateAddPackage(appsFilter,
|
PackageSetting target = simulateAddPackage(appsFilter,
|
||||||
pkg("com.some.package"), DUMMY_TARGET_UID,
|
pkg("com.some.package"), DUMMY_TARGET_APPID,
|
||||||
setting -> setting.setPkgFlags(ApplicationInfo.FLAG_SYSTEM));
|
setting -> setting.setPkgFlags(ApplicationInfo.FLAG_SYSTEM));
|
||||||
PackageSetting calling = simulateAddPackage(appsFilter,
|
PackageSetting calling = simulateAddPackage(appsFilter,
|
||||||
pkg("com.some.other.package"), DUMMY_CALLING_UID);
|
pkg("com.some.other.package"), DUMMY_CALLING_APPID);
|
||||||
|
|
||||||
assertFalse(appsFilter.shouldFilterApplication(DUMMY_CALLING_UID, calling, target, 0));
|
assertFalse(appsFilter.shouldFilterApplication(DUMMY_CALLING_APPID, calling, target,
|
||||||
|
SYSTEM_USER));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testQueriesPackage_DoesntFilter() throws Exception {
|
public void testQueriesPackage_DoesntFilter() throws Exception {
|
||||||
final AppsFilter appsFilter =
|
final AppsFilter appsFilter =
|
||||||
new AppsFilter(mFeatureConfigMock, new String[]{}, false, null);
|
new AppsFilter(mStateProvider, mFeatureConfigMock, new String[]{}, false, null);
|
||||||
simulateAddBasicAndroid(appsFilter);
|
simulateAddBasicAndroid(appsFilter);
|
||||||
appsFilter.onSystemReady();
|
appsFilter.onSystemReady();
|
||||||
|
|
||||||
PackageSetting target = simulateAddPackage(appsFilter,
|
PackageSetting target = simulateAddPackage(appsFilter,
|
||||||
pkg("com.some.package"), DUMMY_TARGET_UID);
|
pkg("com.some.package"), DUMMY_TARGET_APPID);
|
||||||
PackageSetting calling = simulateAddPackage(appsFilter,
|
PackageSetting calling = simulateAddPackage(appsFilter,
|
||||||
pkg("com.some.other.package", "com.some.package"), DUMMY_CALLING_UID);
|
pkg("com.some.other.package", "com.some.package"), DUMMY_CALLING_APPID);
|
||||||
|
|
||||||
assertFalse(appsFilter.shouldFilterApplication(DUMMY_CALLING_UID, calling, target, 0));
|
assertFalse(appsFilter.shouldFilterApplication(DUMMY_CALLING_APPID, calling, target,
|
||||||
|
SYSTEM_USER));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -445,63 +484,67 @@ public class AppsFilterTest {
|
|||||||
when(mFeatureConfigMock.packageIsEnabled(any(AndroidPackage.class)))
|
when(mFeatureConfigMock.packageIsEnabled(any(AndroidPackage.class)))
|
||||||
.thenReturn(false);
|
.thenReturn(false);
|
||||||
final AppsFilter appsFilter =
|
final AppsFilter appsFilter =
|
||||||
new AppsFilter(mFeatureConfigMock, new String[]{}, false, null);
|
new AppsFilter(mStateProvider, mFeatureConfigMock, new String[]{}, false, null);
|
||||||
simulateAddBasicAndroid(appsFilter);
|
simulateAddBasicAndroid(appsFilter);
|
||||||
appsFilter.onSystemReady();
|
appsFilter.onSystemReady();
|
||||||
|
|
||||||
PackageSetting target = simulateAddPackage(
|
PackageSetting target = simulateAddPackage(
|
||||||
appsFilter, pkg("com.some.package"), DUMMY_TARGET_UID);
|
appsFilter, pkg("com.some.package"), DUMMY_TARGET_APPID);
|
||||||
PackageSetting calling = simulateAddPackage(
|
PackageSetting calling = simulateAddPackage(
|
||||||
appsFilter, pkg("com.some.other.package"), DUMMY_CALLING_UID);
|
appsFilter, pkg("com.some.other.package"), DUMMY_CALLING_APPID);
|
||||||
|
|
||||||
assertFalse(appsFilter.shouldFilterApplication(DUMMY_CALLING_UID, calling, target, 0));
|
assertFalse(appsFilter.shouldFilterApplication(DUMMY_CALLING_APPID, calling, target,
|
||||||
|
SYSTEM_USER));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSystemUid_DoesntFilter() throws Exception {
|
public void testSystemUid_DoesntFilter() throws Exception {
|
||||||
final AppsFilter appsFilter =
|
final AppsFilter appsFilter =
|
||||||
new AppsFilter(mFeatureConfigMock, new String[]{}, false, null);
|
new AppsFilter(mStateProvider, mFeatureConfigMock, new String[]{}, false, null);
|
||||||
simulateAddBasicAndroid(appsFilter);
|
simulateAddBasicAndroid(appsFilter);
|
||||||
appsFilter.onSystemReady();
|
appsFilter.onSystemReady();
|
||||||
|
|
||||||
PackageSetting target = simulateAddPackage(appsFilter,
|
PackageSetting target = simulateAddPackage(appsFilter,
|
||||||
pkg("com.some.package"), DUMMY_TARGET_UID);
|
pkg("com.some.package"), DUMMY_TARGET_APPID);
|
||||||
|
|
||||||
assertFalse(appsFilter.shouldFilterApplication(0, null, target, 0));
|
assertFalse(appsFilter.shouldFilterApplication(SYSTEM_USER, null, target, SYSTEM_USER));
|
||||||
assertFalse(appsFilter.shouldFilterApplication(Process.FIRST_APPLICATION_UID - 1,
|
assertFalse(appsFilter.shouldFilterApplication(Process.FIRST_APPLICATION_UID - 1,
|
||||||
null, target, 0));
|
null, target, SYSTEM_USER));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNonSystemUid_NoCallingSetting_Filters() throws Exception {
|
public void testNonSystemUid_NoCallingSetting_Filters() throws Exception {
|
||||||
final AppsFilter appsFilter =
|
final AppsFilter appsFilter =
|
||||||
new AppsFilter(mFeatureConfigMock, new String[]{}, false, null);
|
new AppsFilter(mStateProvider, mFeatureConfigMock, new String[]{}, false, null);
|
||||||
simulateAddBasicAndroid(appsFilter);
|
simulateAddBasicAndroid(appsFilter);
|
||||||
appsFilter.onSystemReady();
|
appsFilter.onSystemReady();
|
||||||
|
|
||||||
PackageSetting target = simulateAddPackage(appsFilter,
|
PackageSetting target = simulateAddPackage(appsFilter,
|
||||||
pkg("com.some.package"), DUMMY_TARGET_UID);
|
pkg("com.some.package"), DUMMY_TARGET_APPID);
|
||||||
|
|
||||||
assertTrue(appsFilter.shouldFilterApplication(DUMMY_CALLING_UID, null, target, 0));
|
assertTrue(appsFilter.shouldFilterApplication(DUMMY_CALLING_APPID, null, target,
|
||||||
|
SYSTEM_USER));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoTargetPackage_filters() throws Exception {
|
public void testNoTargetPackage_filters() throws Exception {
|
||||||
final AppsFilter appsFilter =
|
final AppsFilter appsFilter =
|
||||||
new AppsFilter(mFeatureConfigMock, new String[]{}, false, null);
|
new AppsFilter(mStateProvider, mFeatureConfigMock, new String[]{}, false, null);
|
||||||
simulateAddBasicAndroid(appsFilter);
|
simulateAddBasicAndroid(appsFilter);
|
||||||
appsFilter.onSystemReady();
|
appsFilter.onSystemReady();
|
||||||
|
|
||||||
PackageSetting target = new PackageSettingBuilder()
|
PackageSetting target = new PackageSettingBuilder()
|
||||||
|
.setAppId(DUMMY_TARGET_APPID)
|
||||||
.setName("com.some.package")
|
.setName("com.some.package")
|
||||||
.setCodePath("/")
|
.setCodePath("/")
|
||||||
.setResourcePath("/")
|
.setResourcePath("/")
|
||||||
.setPVersionCode(1L)
|
.setPVersionCode(1L)
|
||||||
.build();
|
.build();
|
||||||
PackageSetting calling = simulateAddPackage(appsFilter,
|
PackageSetting calling = simulateAddPackage(appsFilter,
|
||||||
pkg("com.some.other.package", new Intent("TEST_ACTION")), DUMMY_CALLING_UID);
|
pkg("com.some.other.package", new Intent("TEST_ACTION")), DUMMY_CALLING_APPID);
|
||||||
|
|
||||||
assertTrue(appsFilter.shouldFilterApplication(DUMMY_CALLING_UID, calling, target, 0));
|
assertTrue(appsFilter.shouldFilterApplication(DUMMY_CALLING_APPID, calling, target,
|
||||||
|
SYSTEM_USER));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -516,7 +559,11 @@ public class AppsFilterTest {
|
|||||||
.setOverlayTargetName("overlayableName");
|
.setOverlayTargetName("overlayableName");
|
||||||
ParsingPackage actor = pkg("com.some.package.actor");
|
ParsingPackage actor = pkg("com.some.package.actor");
|
||||||
|
|
||||||
final AppsFilter appsFilter = new AppsFilter(mFeatureConfigMock, new String[]{}, false,
|
final AppsFilter appsFilter = new AppsFilter(
|
||||||
|
mStateProvider,
|
||||||
|
mFeatureConfigMock,
|
||||||
|
new String[]{},
|
||||||
|
false,
|
||||||
new OverlayReferenceMapper.Provider() {
|
new OverlayReferenceMapper.Provider() {
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
@@ -544,31 +591,34 @@ public class AppsFilterTest {
|
|||||||
simulateAddBasicAndroid(appsFilter);
|
simulateAddBasicAndroid(appsFilter);
|
||||||
appsFilter.onSystemReady();
|
appsFilter.onSystemReady();
|
||||||
|
|
||||||
PackageSetting targetSetting = simulateAddPackage(appsFilter, target, DUMMY_TARGET_UID);
|
PackageSetting targetSetting = simulateAddPackage(appsFilter, target, DUMMY_TARGET_APPID);
|
||||||
PackageSetting overlaySetting = simulateAddPackage(appsFilter, overlay, DUMMY_OVERLAY_UID);
|
PackageSetting overlaySetting =
|
||||||
PackageSetting actorSetting = simulateAddPackage(appsFilter, actor, DUMMY_ACTOR_UID);
|
simulateAddPackage(appsFilter, overlay, DUMMY_OVERLAY_APPID);
|
||||||
|
PackageSetting actorSetting = simulateAddPackage(appsFilter, actor, DUMMY_ACTOR_APPID);
|
||||||
|
|
||||||
// Actor can see both target and overlay
|
// Actor can see both target and overlay
|
||||||
assertFalse(appsFilter.shouldFilterApplication(DUMMY_ACTOR_UID, actorSetting,
|
assertFalse(appsFilter.shouldFilterApplication(DUMMY_ACTOR_APPID, actorSetting,
|
||||||
targetSetting, 0));
|
targetSetting, SYSTEM_USER));
|
||||||
assertFalse(appsFilter.shouldFilterApplication(DUMMY_ACTOR_UID, actorSetting,
|
assertFalse(appsFilter.shouldFilterApplication(DUMMY_ACTOR_APPID, actorSetting,
|
||||||
overlaySetting, 0));
|
overlaySetting, SYSTEM_USER));
|
||||||
|
|
||||||
// But target/overlay can't see each other
|
// But target/overlay can't see each other
|
||||||
assertTrue(appsFilter.shouldFilterApplication(DUMMY_TARGET_UID, targetSetting,
|
assertTrue(appsFilter.shouldFilterApplication(DUMMY_TARGET_APPID, targetSetting,
|
||||||
overlaySetting, 0));
|
overlaySetting, SYSTEM_USER));
|
||||||
assertTrue(appsFilter.shouldFilterApplication(DUMMY_OVERLAY_UID, overlaySetting,
|
assertTrue(appsFilter.shouldFilterApplication(DUMMY_OVERLAY_APPID, overlaySetting,
|
||||||
targetSetting, 0));
|
targetSetting, SYSTEM_USER));
|
||||||
|
|
||||||
// And can't see the actor
|
// And can't see the actor
|
||||||
assertTrue(appsFilter.shouldFilterApplication(DUMMY_TARGET_UID, targetSetting,
|
assertTrue(appsFilter.shouldFilterApplication(DUMMY_TARGET_APPID, targetSetting,
|
||||||
actorSetting, 0));
|
actorSetting, SYSTEM_USER));
|
||||||
assertTrue(appsFilter.shouldFilterApplication(DUMMY_OVERLAY_UID, overlaySetting,
|
assertTrue(appsFilter.shouldFilterApplication(DUMMY_OVERLAY_APPID, overlaySetting,
|
||||||
actorSetting, 0));
|
actorSetting, SYSTEM_USER));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testActsOnTargetOfOverlayThroughSharedUser() throws Exception {
|
public void testActsOnTargetOfOverlayThroughSharedUser() throws Exception {
|
||||||
|
// Debug.waitForDebugger();
|
||||||
|
|
||||||
final String actorName = "overlay://test/actorName";
|
final String actorName = "overlay://test/actorName";
|
||||||
|
|
||||||
ParsingPackage target = pkg("com.some.package.target")
|
ParsingPackage target = pkg("com.some.package.target")
|
||||||
@@ -580,7 +630,11 @@ public class AppsFilterTest {
|
|||||||
ParsingPackage actorOne = pkg("com.some.package.actor.one");
|
ParsingPackage actorOne = pkg("com.some.package.actor.one");
|
||||||
ParsingPackage actorTwo = pkg("com.some.package.actor.two");
|
ParsingPackage actorTwo = pkg("com.some.package.actor.two");
|
||||||
|
|
||||||
final AppsFilter appsFilter = new AppsFilter(mFeatureConfigMock, new String[]{}, false,
|
final AppsFilter appsFilter = new AppsFilter(
|
||||||
|
mStateProvider,
|
||||||
|
mFeatureConfigMock,
|
||||||
|
new String[]{},
|
||||||
|
false,
|
||||||
new OverlayReferenceMapper.Provider() {
|
new OverlayReferenceMapper.Provider() {
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
@@ -609,108 +663,114 @@ public class AppsFilterTest {
|
|||||||
simulateAddBasicAndroid(appsFilter);
|
simulateAddBasicAndroid(appsFilter);
|
||||||
appsFilter.onSystemReady();
|
appsFilter.onSystemReady();
|
||||||
|
|
||||||
PackageSetting targetSetting = simulateAddPackage(appsFilter, target, DUMMY_TARGET_UID);
|
PackageSetting targetSetting = simulateAddPackage(appsFilter, target, DUMMY_TARGET_APPID);
|
||||||
PackageSetting overlaySetting = simulateAddPackage(appsFilter, overlay, DUMMY_OVERLAY_UID);
|
|
||||||
PackageSetting actorOneSetting = simulateAddPackage(appsFilter, actorOne, DUMMY_ACTOR_UID);
|
|
||||||
PackageSetting actorTwoSetting = simulateAddPackage(appsFilter, actorTwo,
|
|
||||||
DUMMY_ACTOR_TWO_UID);
|
|
||||||
|
|
||||||
SharedUserSetting actorSharedSetting = new SharedUserSetting("actorSharedUser",
|
SharedUserSetting actorSharedSetting = new SharedUserSetting("actorSharedUser",
|
||||||
actorOneSetting.pkgFlags, actorOneSetting.pkgPrivateFlags);
|
targetSetting.pkgFlags, targetSetting.pkgPrivateFlags);
|
||||||
actorSharedSetting.addPackage(actorOneSetting);
|
PackageSetting overlaySetting =
|
||||||
actorSharedSetting.addPackage(actorTwoSetting);
|
simulateAddPackage(appsFilter, overlay, DUMMY_OVERLAY_APPID);
|
||||||
|
simulateAddPackage(appsFilter, actorOne, DUMMY_ACTOR_APPID,
|
||||||
|
null /*settingBuilder*/, actorSharedSetting);
|
||||||
|
simulateAddPackage(appsFilter, actorTwo, DUMMY_ACTOR_APPID,
|
||||||
|
null /*settingBuilder*/, actorSharedSetting);
|
||||||
|
|
||||||
|
|
||||||
// actorTwo can see both target and overlay
|
// actorTwo can see both target and overlay
|
||||||
assertFalse(appsFilter.shouldFilterApplication(DUMMY_ACTOR_TWO_UID, actorSharedSetting,
|
assertFalse(appsFilter.shouldFilterApplication(DUMMY_ACTOR_APPID, actorSharedSetting,
|
||||||
targetSetting, 0));
|
targetSetting, SYSTEM_USER));
|
||||||
assertFalse(appsFilter.shouldFilterApplication(DUMMY_ACTOR_TWO_UID, actorSharedSetting,
|
assertFalse(appsFilter.shouldFilterApplication(DUMMY_ACTOR_APPID, actorSharedSetting,
|
||||||
overlaySetting, 0));
|
overlaySetting, SYSTEM_USER));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInitiatingApp_DoesntFilter() throws Exception {
|
public void testInitiatingApp_DoesntFilter() throws Exception {
|
||||||
final AppsFilter appsFilter =
|
final AppsFilter appsFilter =
|
||||||
new AppsFilter(mFeatureConfigMock, new String[]{}, false, null);
|
new AppsFilter(mStateProvider, mFeatureConfigMock, new String[]{}, false, null);
|
||||||
simulateAddBasicAndroid(appsFilter);
|
simulateAddBasicAndroid(appsFilter);
|
||||||
appsFilter.onSystemReady();
|
appsFilter.onSystemReady();
|
||||||
|
|
||||||
PackageSetting target = simulateAddPackage(appsFilter, pkg("com.some.package"),
|
PackageSetting target = simulateAddPackage(appsFilter, pkg("com.some.package"),
|
||||||
DUMMY_TARGET_UID);
|
DUMMY_TARGET_APPID);
|
||||||
PackageSetting calling = simulateAddPackage(appsFilter, pkg("com.some.other.package"),
|
PackageSetting calling = simulateAddPackage(appsFilter, pkg("com.some.other.package"),
|
||||||
DUMMY_CALLING_UID, withInstallSource(target.name, null, null, null, false));
|
DUMMY_CALLING_APPID, withInstallSource(target.name, null, null, null, false));
|
||||||
|
|
||||||
assertFalse(appsFilter.shouldFilterApplication(DUMMY_CALLING_UID, calling, target, 0));
|
assertFalse(appsFilter.shouldFilterApplication(DUMMY_CALLING_APPID, calling, target,
|
||||||
|
SYSTEM_USER));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUninstalledInitiatingApp_Filters() throws Exception {
|
public void testUninstalledInitiatingApp_Filters() throws Exception {
|
||||||
final AppsFilter appsFilter =
|
final AppsFilter appsFilter =
|
||||||
new AppsFilter(mFeatureConfigMock, new String[]{}, false, null);
|
new AppsFilter(mStateProvider, mFeatureConfigMock, new String[]{}, false, null);
|
||||||
simulateAddBasicAndroid(appsFilter);
|
simulateAddBasicAndroid(appsFilter);
|
||||||
appsFilter.onSystemReady();
|
appsFilter.onSystemReady();
|
||||||
|
|
||||||
PackageSetting target = simulateAddPackage(appsFilter, pkg("com.some.package"),
|
PackageSetting target = simulateAddPackage(appsFilter, pkg("com.some.package"),
|
||||||
DUMMY_TARGET_UID);
|
DUMMY_TARGET_APPID);
|
||||||
PackageSetting calling = simulateAddPackage(appsFilter, pkg("com.some.other.package"),
|
PackageSetting calling = simulateAddPackage(appsFilter, pkg("com.some.other.package"),
|
||||||
DUMMY_CALLING_UID, withInstallSource(target.name, null, null, null, true));
|
DUMMY_CALLING_APPID, withInstallSource(target.name, null, null, null, true));
|
||||||
|
|
||||||
assertTrue(appsFilter.shouldFilterApplication(DUMMY_CALLING_UID, calling, target, 0));
|
assertTrue(appsFilter.shouldFilterApplication(DUMMY_CALLING_APPID, calling, target,
|
||||||
|
SYSTEM_USER));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOriginatingApp_Filters() throws Exception {
|
public void testOriginatingApp_Filters() throws Exception {
|
||||||
final AppsFilter appsFilter =
|
final AppsFilter appsFilter =
|
||||||
new AppsFilter(mFeatureConfigMock, new String[]{}, false, null);
|
new AppsFilter(mStateProvider, mFeatureConfigMock, new String[]{}, false, null);
|
||||||
simulateAddBasicAndroid(appsFilter);
|
simulateAddBasicAndroid(appsFilter);
|
||||||
appsFilter.onSystemReady();
|
appsFilter.onSystemReady();
|
||||||
|
|
||||||
PackageSetting target = simulateAddPackage(appsFilter, pkg("com.some.package"),
|
PackageSetting target = simulateAddPackage(appsFilter, pkg("com.some.package"),
|
||||||
DUMMY_TARGET_UID);
|
DUMMY_TARGET_APPID);
|
||||||
PackageSetting calling = simulateAddPackage(appsFilter, pkg("com.some.other.package"),
|
PackageSetting calling = simulateAddPackage(appsFilter, pkg("com.some.other.package"),
|
||||||
DUMMY_CALLING_UID, withInstallSource(null, target.name, null, null, false));
|
DUMMY_CALLING_APPID, withInstallSource(null, target.name, null, null, false));
|
||||||
|
|
||||||
assertTrue(appsFilter.shouldFilterApplication(DUMMY_CALLING_UID, calling, target, 0));
|
assertTrue(appsFilter.shouldFilterApplication(DUMMY_CALLING_APPID, calling, target,
|
||||||
|
SYSTEM_USER));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInstallingApp_DoesntFilter() throws Exception {
|
public void testInstallingApp_DoesntFilter() throws Exception {
|
||||||
final AppsFilter appsFilter =
|
final AppsFilter appsFilter =
|
||||||
new AppsFilter(mFeatureConfigMock, new String[]{}, false, null);
|
new AppsFilter(mStateProvider, mFeatureConfigMock, new String[]{}, false, null);
|
||||||
simulateAddBasicAndroid(appsFilter);
|
simulateAddBasicAndroid(appsFilter);
|
||||||
appsFilter.onSystemReady();
|
appsFilter.onSystemReady();
|
||||||
|
|
||||||
PackageSetting target = simulateAddPackage(appsFilter, pkg("com.some.package"),
|
PackageSetting target = simulateAddPackage(appsFilter, pkg("com.some.package"),
|
||||||
DUMMY_TARGET_UID);
|
DUMMY_TARGET_APPID);
|
||||||
PackageSetting calling = simulateAddPackage(appsFilter, pkg("com.some.other.package"),
|
PackageSetting calling = simulateAddPackage(appsFilter, pkg("com.some.other.package"),
|
||||||
DUMMY_CALLING_UID, withInstallSource(null, null, target.name, null, false));
|
DUMMY_CALLING_APPID, withInstallSource(null, null, target.name, null, false));
|
||||||
|
|
||||||
assertFalse(appsFilter.shouldFilterApplication(DUMMY_CALLING_UID, calling, target, 0));
|
assertFalse(appsFilter.shouldFilterApplication(DUMMY_CALLING_APPID, calling, target,
|
||||||
|
SYSTEM_USER));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInstrumentation_DoesntFilter() throws Exception {
|
public void testInstrumentation_DoesntFilter() throws Exception {
|
||||||
final AppsFilter appsFilter =
|
final AppsFilter appsFilter =
|
||||||
new AppsFilter(mFeatureConfigMock, new String[]{}, false, null);
|
new AppsFilter(mStateProvider, mFeatureConfigMock, new String[]{}, false, null);
|
||||||
simulateAddBasicAndroid(appsFilter);
|
simulateAddBasicAndroid(appsFilter);
|
||||||
appsFilter.onSystemReady();
|
appsFilter.onSystemReady();
|
||||||
|
|
||||||
|
|
||||||
PackageSetting target = simulateAddPackage(appsFilter, pkg("com.some.package"),
|
PackageSetting target = simulateAddPackage(appsFilter, pkg("com.some.package"),
|
||||||
DUMMY_TARGET_UID);
|
DUMMY_TARGET_APPID);
|
||||||
PackageSetting instrumentation = simulateAddPackage(appsFilter,
|
PackageSetting instrumentation = simulateAddPackage(appsFilter,
|
||||||
pkgWithInstrumentation("com.some.other.package", "com.some.package"),
|
pkgWithInstrumentation("com.some.other.package", "com.some.package"),
|
||||||
DUMMY_CALLING_UID);
|
DUMMY_CALLING_APPID);
|
||||||
|
|
||||||
assertFalse(
|
assertFalse(
|
||||||
appsFilter.shouldFilterApplication(DUMMY_CALLING_UID, instrumentation, target, 0));
|
appsFilter.shouldFilterApplication(DUMMY_CALLING_APPID, instrumentation, target,
|
||||||
|
SYSTEM_USER));
|
||||||
assertFalse(
|
assertFalse(
|
||||||
appsFilter.shouldFilterApplication(DUMMY_TARGET_UID, target, instrumentation, 0));
|
appsFilter.shouldFilterApplication(DUMMY_TARGET_APPID, target, instrumentation,
|
||||||
|
SYSTEM_USER));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWhoCanSee() throws Exception {
|
public void testWhoCanSee() throws Exception {
|
||||||
final AppsFilter appsFilter =
|
final AppsFilter appsFilter =
|
||||||
new AppsFilter(mFeatureConfigMock, new String[]{}, false, null);
|
new AppsFilter(mStateProvider, mFeatureConfigMock, new String[]{}, false, null);
|
||||||
simulateAddBasicAndroid(appsFilter);
|
simulateAddBasicAndroid(appsFilter);
|
||||||
appsFilter.onSystemReady();
|
appsFilter.onSystemReady();
|
||||||
|
|
||||||
@@ -718,6 +778,7 @@ public class AppsFilterTest {
|
|||||||
final int seesNothingAppId = Process.FIRST_APPLICATION_UID;
|
final int seesNothingAppId = Process.FIRST_APPLICATION_UID;
|
||||||
final int hasProviderAppId = Process.FIRST_APPLICATION_UID + 1;
|
final int hasProviderAppId = Process.FIRST_APPLICATION_UID + 1;
|
||||||
final int queriesProviderAppId = Process.FIRST_APPLICATION_UID + 2;
|
final int queriesProviderAppId = Process.FIRST_APPLICATION_UID + 2;
|
||||||
|
|
||||||
PackageSetting system = simulateAddPackage(appsFilter, pkg("some.system.pkg"), systemAppId);
|
PackageSetting system = simulateAddPackage(appsFilter, pkg("some.system.pkg"), systemAppId);
|
||||||
PackageSetting seesNothing = simulateAddPackage(appsFilter, pkg("com.some.package"),
|
PackageSetting seesNothing = simulateAddPackage(appsFilter, pkg("com.some.package"),
|
||||||
seesNothingAppId);
|
seesNothingAppId);
|
||||||
@@ -727,23 +788,25 @@ public class AppsFilterTest {
|
|||||||
pkgQueriesProvider("com.yet.some.other.package", "com.some.authority"),
|
pkgQueriesProvider("com.yet.some.other.package", "com.some.authority"),
|
||||||
queriesProviderAppId);
|
queriesProviderAppId);
|
||||||
|
|
||||||
final int[] systemFilter =
|
final SparseArray<int[]> systemFilter =
|
||||||
appsFilter.getVisibilityWhitelist(system, new int[]{0}, mExisting).get(0);
|
appsFilter.getVisibilityWhitelist(system, USER_ARRAY, mExisting);
|
||||||
assertThat(toList(systemFilter), empty());
|
assertThat(toList(systemFilter.get(SYSTEM_USER)), empty());
|
||||||
|
|
||||||
final int[] seesNothingFilter =
|
final SparseArray<int[]> seesNothingFilter =
|
||||||
appsFilter.getVisibilityWhitelist(seesNothing, new int[]{0}, mExisting).get(0);
|
appsFilter.getVisibilityWhitelist(seesNothing, USER_ARRAY, mExisting);
|
||||||
assertThat(toList(seesNothingFilter),
|
assertThat(toList(seesNothingFilter.get(SYSTEM_USER)),
|
||||||
|
contains(seesNothingAppId));
|
||||||
|
assertThat(toList(seesNothingFilter.get(SECONDARY_USER)),
|
||||||
contains(seesNothingAppId));
|
contains(seesNothingAppId));
|
||||||
|
|
||||||
final int[] hasProviderFilter =
|
final SparseArray<int[]> hasProviderFilter =
|
||||||
appsFilter.getVisibilityWhitelist(hasProvider, new int[]{0}, mExisting).get(0);
|
appsFilter.getVisibilityWhitelist(hasProvider, USER_ARRAY, mExisting);
|
||||||
assertThat(toList(hasProviderFilter),
|
assertThat(toList(hasProviderFilter.get(SYSTEM_USER)),
|
||||||
contains(hasProviderAppId, queriesProviderAppId));
|
contains(hasProviderAppId, queriesProviderAppId));
|
||||||
|
|
||||||
int[] queriesProviderFilter =
|
SparseArray<int[]> queriesProviderFilter =
|
||||||
appsFilter.getVisibilityWhitelist(queriesProvider, new int[]{0}, mExisting).get(0);
|
appsFilter.getVisibilityWhitelist(queriesProvider, USER_ARRAY, mExisting);
|
||||||
assertThat(toList(queriesProviderFilter),
|
assertThat(toList(queriesProviderFilter.get(SYSTEM_USER)),
|
||||||
contains(queriesProviderAppId));
|
contains(queriesProviderAppId));
|
||||||
|
|
||||||
// provider read
|
// provider read
|
||||||
@@ -751,8 +814,8 @@ public class AppsFilterTest {
|
|||||||
|
|
||||||
// ensure implicit access is included in the filter
|
// ensure implicit access is included in the filter
|
||||||
queriesProviderFilter =
|
queriesProviderFilter =
|
||||||
appsFilter.getVisibilityWhitelist(queriesProvider, new int[]{0}, mExisting).get(0);
|
appsFilter.getVisibilityWhitelist(queriesProvider, USER_ARRAY, mExisting);
|
||||||
assertThat(toList(queriesProviderFilter),
|
assertThat(toList(queriesProviderFilter.get(SYSTEM_USER)),
|
||||||
contains(hasProviderAppId, queriesProviderAppId));
|
contains(hasProviderAppId, queriesProviderAppId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -779,11 +842,17 @@ public class AppsFilterTest {
|
|||||||
|
|
||||||
private PackageSetting simulateAddPackage(AppsFilter filter,
|
private PackageSetting simulateAddPackage(AppsFilter filter,
|
||||||
ParsingPackage newPkgBuilder, int appId) {
|
ParsingPackage newPkgBuilder, int appId) {
|
||||||
return simulateAddPackage(filter, newPkgBuilder, appId, null);
|
return simulateAddPackage(filter, newPkgBuilder, appId, null /*settingBuilder*/);
|
||||||
}
|
}
|
||||||
|
|
||||||
private PackageSetting simulateAddPackage(AppsFilter filter,
|
private PackageSetting simulateAddPackage(AppsFilter filter,
|
||||||
ParsingPackage newPkgBuilder, int appId, @Nullable WithSettingBuilder action) {
|
ParsingPackage newPkgBuilder, int appId, @Nullable WithSettingBuilder action) {
|
||||||
|
return simulateAddPackage(filter, newPkgBuilder, appId, action, null /*sharedUserSetting*/);
|
||||||
|
}
|
||||||
|
|
||||||
|
private PackageSetting simulateAddPackage(AppsFilter filter,
|
||||||
|
ParsingPackage newPkgBuilder, int appId, @Nullable WithSettingBuilder action,
|
||||||
|
@Nullable SharedUserSetting sharedUserSetting) {
|
||||||
AndroidPackage newPkg = ((ParsedPackage) newPkgBuilder.hideAsParsed()).hideAsFinal();
|
AndroidPackage newPkg = ((ParsedPackage) newPkgBuilder.hideAsParsed()).hideAsFinal();
|
||||||
|
|
||||||
final PackageSettingBuilder settingBuilder = new PackageSettingBuilder()
|
final PackageSettingBuilder settingBuilder = new PackageSettingBuilder()
|
||||||
@@ -795,8 +864,12 @@ public class AppsFilterTest {
|
|||||||
.setPVersionCode(1L);
|
.setPVersionCode(1L);
|
||||||
final PackageSetting setting =
|
final PackageSetting setting =
|
||||||
(action == null ? settingBuilder : action.withBuilder(settingBuilder)).build();
|
(action == null ? settingBuilder : action.withBuilder(settingBuilder)).build();
|
||||||
filter.addPackage(setting, mExisting);
|
|
||||||
mExisting.put(newPkg.getPackageName(), setting);
|
mExisting.put(newPkg.getPackageName(), setting);
|
||||||
|
if (sharedUserSetting != null) {
|
||||||
|
sharedUserSetting.addPackage(setting);
|
||||||
|
setting.sharedUser = sharedUserSetting;
|
||||||
|
}
|
||||||
|
filter.addPackage(setting);
|
||||||
return setting;
|
return setting;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -809,4 +882,3 @@ public class AppsFilterTest {
|
|||||||
return setting -> setting.setInstallSource(installSource);
|
return setting -> setting.setInstallSource(installSource);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user