Loading services/core/java/com/android/server/pm/PackageManagerService.java +81 −67 Original line number Diff line number Diff line Loading @@ -12940,6 +12940,8 @@ public class PackageManagerService extends IPackageManager.Stub final List<String> changedPackagesList = new ArrayList<>(packageNames.length); final IntArray changedUids = new IntArray(packageNames.length); final List<String> unactionedPackages = new ArrayList<>(packageNames.length); final boolean[] canRestrict = (restrictionFlags != 0) ? canSuspendPackageForUserInternal( packageNames, userId) : null; for (int i = 0; i < packageNames.length; i++) { final String packageName = packageNames[i]; Loading @@ -12953,7 +12955,7 @@ public class PackageManagerService extends IPackageManager.Stub continue; } } if (restrictionFlags != 0 && !canSuspendPackageForUserInternal(packageName, userId)) { if (canRestrict != null && !canRestrict[i]) { unactionedPackages.add(packageName); continue; } Loading Loading @@ -13010,6 +13012,8 @@ public class PackageManagerService extends IPackageManager.Stub final List<String> changedPackagesList = new ArrayList<>(packageNames.length); final IntArray changedUids = new IntArray(packageNames.length); final List<String> unactionedPackages = new ArrayList<>(packageNames.length); final boolean[] canSuspend = suspended ? canSuspendPackageForUserInternal(packageNames, userId) : null; for (int i = 0; i < packageNames.length; i++) { final String packageName = packageNames[i]; Loading @@ -13029,7 +13033,7 @@ public class PackageManagerService extends IPackageManager.Stub continue; } } if (suspended && !canSuspendPackageForUserInternal(packageName, userId)) { if (canSuspend != null && !canSuspend[i]) { unactionedPackages.add(packageName); continue; } Loading Loading @@ -13193,65 +13197,74 @@ public class PackageManagerService extends IPackageManager.Stub + " cannot query getUnsuspendablePackagesForUser for user " + userId); } final ArraySet<String> unactionablePackages = new ArraySet<>(); for (String packageName : packageNames) { if (!canSuspendPackageForUserInternal(packageName, userId)) { unactionablePackages.add(packageName); final boolean[] canSuspend = canSuspendPackageForUserInternal(packageNames, userId); for (int i = 0; i < packageNames.length; i++) { if (!canSuspend[i]) { unactionablePackages.add(packageNames[i]); } } return unactionablePackages.toArray(new String[unactionablePackages.size()]); } private boolean canSuspendPackageForUserInternal(String packageName, int userId) { /** * Returns an array of booleans, such that the ith boolean denotes whether the ith package can * be suspended or not. * * @param packageNames The package names to check suspendability for. * @param userId The user to check in * @return An array containing results of the checks */ @NonNull private boolean[] canSuspendPackageForUserInternal(@NonNull String[] packageNames, int userId) { final boolean[] canSuspend = new boolean[packageNames.length]; final long callingId = Binder.clearCallingIdentity(); try { final String activeLauncherPackageName = getActiveLauncherPackageName(userId); final String dialerPackageName = getDefaultDialerPackageName(userId); for (int i = 0; i < packageNames.length; i++) { canSuspend[i] = false; final String packageName = packageNames[i]; if (isPackageDeviceAdmin(packageName, userId)) { Slog.w(TAG, "Cannot suspend package \"" + packageName + "\": has an active device admin"); return false; continue; } String activeLauncherPackageName = getActiveLauncherPackageName(userId); if (packageName.equals(activeLauncherPackageName)) { Slog.w(TAG, "Cannot suspend package \"" + packageName + "\": contains the active launcher"); return false; continue; } if (packageName.equals(mRequiredInstallerPackage)) { Slog.w(TAG, "Cannot suspend package \"" + packageName + "\": required for package installation"); return false; continue; } if (packageName.equals(mRequiredUninstallerPackage)) { Slog.w(TAG, "Cannot suspend package \"" + packageName + "\": required for package uninstallation"); return false; continue; } if (packageName.equals(mRequiredVerifierPackage)) { Slog.w(TAG, "Cannot suspend package \"" + packageName + "\": required for package verification"); return false; continue; } if (packageName.equals(getDefaultDialerPackageName(userId))) { if (packageName.equals(dialerPackageName)) { Slog.w(TAG, "Cannot suspend package \"" + packageName + "\": is the default dialer"); return false; continue; } if (packageName.equals(mRequiredPermissionControllerPackage)) { Slog.w(TAG, "Cannot suspend package \"" + packageName + "\": required for permissions management"); return false; continue; } synchronized (mPackages) { if (mProtectedPackages.isPackageStateProtected(userId, packageName)) { Slog.w(TAG, "Cannot suspend package \"" + packageName + "\": protected package"); return false; continue; } // Cannot suspend static shared libs as they are considered Loading @@ -13262,18 +13275,19 @@ public class PackageManagerService extends IPackageManager.Stub Slog.w(TAG, "Cannot suspend package: " + packageName + " providing static shared library: " + pkg.staticSharedLibName); return false; continue; } } if (PLATFORM_PACKAGE_NAME.equals(packageName)) { Slog.w(TAG, "Cannot suspend the platform package: " + packageName); return false; continue; } canSuspend[i] = true; } return true; } finally { Binder.restoreCallingIdentity(callingId); } return canSuspend; } private String getActiveLauncherPackageName(int userId) { Loading
services/core/java/com/android/server/pm/PackageManagerService.java +81 −67 Original line number Diff line number Diff line Loading @@ -12940,6 +12940,8 @@ public class PackageManagerService extends IPackageManager.Stub final List<String> changedPackagesList = new ArrayList<>(packageNames.length); final IntArray changedUids = new IntArray(packageNames.length); final List<String> unactionedPackages = new ArrayList<>(packageNames.length); final boolean[] canRestrict = (restrictionFlags != 0) ? canSuspendPackageForUserInternal( packageNames, userId) : null; for (int i = 0; i < packageNames.length; i++) { final String packageName = packageNames[i]; Loading @@ -12953,7 +12955,7 @@ public class PackageManagerService extends IPackageManager.Stub continue; } } if (restrictionFlags != 0 && !canSuspendPackageForUserInternal(packageName, userId)) { if (canRestrict != null && !canRestrict[i]) { unactionedPackages.add(packageName); continue; } Loading Loading @@ -13010,6 +13012,8 @@ public class PackageManagerService extends IPackageManager.Stub final List<String> changedPackagesList = new ArrayList<>(packageNames.length); final IntArray changedUids = new IntArray(packageNames.length); final List<String> unactionedPackages = new ArrayList<>(packageNames.length); final boolean[] canSuspend = suspended ? canSuspendPackageForUserInternal(packageNames, userId) : null; for (int i = 0; i < packageNames.length; i++) { final String packageName = packageNames[i]; Loading @@ -13029,7 +13033,7 @@ public class PackageManagerService extends IPackageManager.Stub continue; } } if (suspended && !canSuspendPackageForUserInternal(packageName, userId)) { if (canSuspend != null && !canSuspend[i]) { unactionedPackages.add(packageName); continue; } Loading Loading @@ -13193,65 +13197,74 @@ public class PackageManagerService extends IPackageManager.Stub + " cannot query getUnsuspendablePackagesForUser for user " + userId); } final ArraySet<String> unactionablePackages = new ArraySet<>(); for (String packageName : packageNames) { if (!canSuspendPackageForUserInternal(packageName, userId)) { unactionablePackages.add(packageName); final boolean[] canSuspend = canSuspendPackageForUserInternal(packageNames, userId); for (int i = 0; i < packageNames.length; i++) { if (!canSuspend[i]) { unactionablePackages.add(packageNames[i]); } } return unactionablePackages.toArray(new String[unactionablePackages.size()]); } private boolean canSuspendPackageForUserInternal(String packageName, int userId) { /** * Returns an array of booleans, such that the ith boolean denotes whether the ith package can * be suspended or not. * * @param packageNames The package names to check suspendability for. * @param userId The user to check in * @return An array containing results of the checks */ @NonNull private boolean[] canSuspendPackageForUserInternal(@NonNull String[] packageNames, int userId) { final boolean[] canSuspend = new boolean[packageNames.length]; final long callingId = Binder.clearCallingIdentity(); try { final String activeLauncherPackageName = getActiveLauncherPackageName(userId); final String dialerPackageName = getDefaultDialerPackageName(userId); for (int i = 0; i < packageNames.length; i++) { canSuspend[i] = false; final String packageName = packageNames[i]; if (isPackageDeviceAdmin(packageName, userId)) { Slog.w(TAG, "Cannot suspend package \"" + packageName + "\": has an active device admin"); return false; continue; } String activeLauncherPackageName = getActiveLauncherPackageName(userId); if (packageName.equals(activeLauncherPackageName)) { Slog.w(TAG, "Cannot suspend package \"" + packageName + "\": contains the active launcher"); return false; continue; } if (packageName.equals(mRequiredInstallerPackage)) { Slog.w(TAG, "Cannot suspend package \"" + packageName + "\": required for package installation"); return false; continue; } if (packageName.equals(mRequiredUninstallerPackage)) { Slog.w(TAG, "Cannot suspend package \"" + packageName + "\": required for package uninstallation"); return false; continue; } if (packageName.equals(mRequiredVerifierPackage)) { Slog.w(TAG, "Cannot suspend package \"" + packageName + "\": required for package verification"); return false; continue; } if (packageName.equals(getDefaultDialerPackageName(userId))) { if (packageName.equals(dialerPackageName)) { Slog.w(TAG, "Cannot suspend package \"" + packageName + "\": is the default dialer"); return false; continue; } if (packageName.equals(mRequiredPermissionControllerPackage)) { Slog.w(TAG, "Cannot suspend package \"" + packageName + "\": required for permissions management"); return false; continue; } synchronized (mPackages) { if (mProtectedPackages.isPackageStateProtected(userId, packageName)) { Slog.w(TAG, "Cannot suspend package \"" + packageName + "\": protected package"); return false; continue; } // Cannot suspend static shared libs as they are considered Loading @@ -13262,18 +13275,19 @@ public class PackageManagerService extends IPackageManager.Stub Slog.w(TAG, "Cannot suspend package: " + packageName + " providing static shared library: " + pkg.staticSharedLibName); return false; continue; } } if (PLATFORM_PACKAGE_NAME.equals(packageName)) { Slog.w(TAG, "Cannot suspend the platform package: " + packageName); return false; continue; } canSuspend[i] = true; } return true; } finally { Binder.restoreCallingIdentity(callingId); } return canSuspend; } private String getActiveLauncherPackageName(int userId) {