DO NOT MERGE - Enable blacklist for headless system user am: f8c0b31524

Change-Id: I9da9ffcb0f8498b3a01295c23e3c78d4f85dbb20
This commit is contained in:
Automerger Merge Worker
2020-02-08 03:48:16 +00:00
2 changed files with 38 additions and 19 deletions

View File

@@ -1274,6 +1274,16 @@ public class UserManager {
return RoSystemProperties.FW_SYSTEM_USER_SPLIT;
}
/**
* @hide
* @return Whether the device is running in a headless system user mode. It means the headless
* user (system user) runs system services and system UI, but is not associated with any real
* person. Secondary users can be created to be associated with real person.
*/
public static boolean isHeadlessSystemUserMode() {
return RoSystemProperties.MULTIUSER_HEADLESS_SYSTEM_USER;
}
/**
* @return Whether guest user is always ephemeral
* @hide

View File

@@ -2363,32 +2363,41 @@ public class PackageManagerService extends IPackageManager.Stub
}
private void enableSystemUserPackages() {
if (!UserManager.isSplitSystemUser()) {
boolean isHeadlessSystemUserMode = UserManager.isHeadlessSystemUserMode();
if (!isHeadlessSystemUserMode && !UserManager.isSplitSystemUser()) {
return;
}
// For system user, enable apps based on the following conditions:
// - app is whitelisted or belong to one of these groups:
// -- system app which has no launcher icons
// -- system app which has INTERACT_ACROSS_USERS permission
// -- system IME app
// - app is not in the blacklist
AppsQueryHelper queryHelper = new AppsQueryHelper(this);
Set<String> enableApps = new ArraySet<>();
enableApps.addAll(queryHelper.queryApps(AppsQueryHelper.GET_NON_LAUNCHABLE_APPS
| AppsQueryHelper.GET_APPS_WITH_INTERACT_ACROSS_USERS_PERM
| AppsQueryHelper.GET_IMES, /* systemAppsOnly */ true, UserHandle.SYSTEM));
ArraySet<String> wlApps = SystemConfig.getInstance().getSystemUserWhitelistedApps();
enableApps.addAll(wlApps);
enableApps.addAll(queryHelper.queryApps(AppsQueryHelper.GET_REQUIRED_FOR_SYSTEM_USER,
/* systemAppsOnly */ false, UserHandle.SYSTEM));
ArraySet<String> blApps = SystemConfig.getInstance().getSystemUserBlacklistedApps();
enableApps.removeAll(blApps);
Log.i(TAG, "Applications installed for system user: " + enableApps);
AppsQueryHelper queryHelper = new AppsQueryHelper(this);
List<String> allAps = queryHelper.queryApps(0, /* systemAppsOnly */ false,
UserHandle.SYSTEM);
if (isHeadlessSystemUserMode) {
enableApps.addAll(allAps);
} else {
// For split system user, select apps based on the following conditions:
// -- system app which has no launcher icons
// -- system app which has INTERACT_ACROSS_USERS permission
// -- system IME app
enableApps.addAll(queryHelper.queryApps(AppsQueryHelper.GET_NON_LAUNCHABLE_APPS
| AppsQueryHelper.GET_APPS_WITH_INTERACT_ACROSS_USERS_PERM
| AppsQueryHelper.GET_IMES, /* systemAppsOnly */ true, UserHandle.SYSTEM));
enableApps.addAll(queryHelper.queryApps(AppsQueryHelper.GET_REQUIRED_FOR_SYSTEM_USER,
/* systemAppsOnly */ false, UserHandle.SYSTEM));
// Apply whitelist for split system user
ArraySet<String> wlApps = SystemConfig.getInstance().getSystemUserWhitelistedApps();
enableApps.addAll(wlApps);
}
// Apply blacklist for split system user/headless system user
ArraySet<String> blApps = SystemConfig.getInstance().getSystemUserBlacklistedApps();
enableApps.removeAll(blApps);
Log.i(TAG, "Blacklisted packages: " + blApps);
final int allAppsSize = allAps.size();
synchronized (mPackages) {
for (int i = 0; i < allAppsSize; i++) {
for (int i = 0; i < allAppsSize; i++) {
String pName = allAps.get(i);
PackageSetting pkgSetting = mSettings.mPackages.get(pName);
// Should not happen, but we shouldn't be failing if it does