Loading services/core/java/android/content/pm/PackageManagerInternal.java +5 −0 Original line number Diff line number Diff line Loading @@ -983,4 +983,9 @@ public abstract class PackageManagerInternal { * Returns if a package name is a valid system package. */ public abstract boolean isSystemPackage(@NonNull String packageName); /** * Unblocks uninstall for all packages for the user. */ public abstract void clearBlockUninstallForUser(@UserIdInt int userId); } services/core/java/com/android/server/pm/PackageManagerService.java +8 −0 Original line number Diff line number Diff line Loading @@ -24721,6 +24721,14 @@ public class PackageManagerService extends IPackageManager.Stub return packageName.equals( PackageManagerService.this.ensureSystemPackageName(packageName)); } @Override public void clearBlockUninstallForUser(@UserIdInt int userId) { synchronized (mLock) { mSettings.clearBlockUninstallLPw(userId); mSettings.writePackageRestrictionsLPr(userId); } } } @GuardedBy("mLock") services/core/java/com/android/server/pm/Settings.java +4 −0 Original line number Diff line number Diff line Loading @@ -1833,6 +1833,10 @@ public final class Settings { } } void clearBlockUninstallLPw(int userId) { mBlockUninstallPackages.remove(userId); } boolean getBlockUninstallLPr(int userId, String packageName) { ArraySet<String> packages = mBlockUninstallPackages.get(userId); if (packages == null) { Loading services/core/java/com/android/server/pm/UserManagerService.java +16 −5 Original line number Diff line number Diff line Loading @@ -3153,13 +3153,17 @@ public class UserManagerService extends IUserManager.Stub { /** * Removes the app restrictions file for a specific package and user id, if it exists. * * @return whether there were any restrictions. */ private static void cleanAppRestrictionsForPackageLAr(String pkg, @UserIdInt int userId) { File dir = Environment.getUserSystemDirectory(userId); File resFile = new File(dir, packageToRestrictionsFileName(pkg)); private static boolean cleanAppRestrictionsForPackageLAr(String pkg, @UserIdInt int userId) { final File dir = Environment.getUserSystemDirectory(userId); final File resFile = new File(dir, packageToRestrictionsFileName(pkg)); if (resFile.exists()) { resFile.delete(); return true; } return false; } /** Loading Loading @@ -4003,17 +4007,24 @@ public class UserManagerService extends IUserManager.Stub { if (restrictions != null) { restrictions.setDefusable(true); } final boolean changed; synchronized (mAppRestrictionsLock) { if (restrictions == null || restrictions.isEmpty()) { cleanAppRestrictionsForPackageLAr(packageName, userId); changed = cleanAppRestrictionsForPackageLAr(packageName, userId); } else { // Write the restrictions to XML writeApplicationRestrictionsLAr(packageName, restrictions, userId); // TODO(b/154323615): avoid unnecessary broadcast when there is no change. changed = true; } } if (!changed) { return; } // Notify package of changes via an intent - only sent to explicitly registered receivers. Intent changeIntent = new Intent(Intent.ACTION_APPLICATION_RESTRICTIONS_CHANGED); final Intent changeIntent = new Intent(Intent.ACTION_APPLICATION_RESTRICTIONS_CHANGED); changeIntent.setPackage(packageName); changeIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); mContext.sendBroadcastAsUser(changeIntent, UserHandle.of(userId)); Loading services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +16 −1 Original line number Diff line number Diff line Loading @@ -2703,7 +2703,6 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { final ComponentName doAdminReceiver = doAdmin.info.getComponent(); clearDeviceOwnerLocked(doAdmin, doUserId); Slog.i(LOG_TAG, "Removing admin artifacts..."); // TODO(b/149075700): Clean up application restrictions in UserManager. removeAdminArtifacts(doAdminReceiver, doUserId); Slog.i(LOG_TAG, "Migration complete."); Loading Loading @@ -8766,6 +8765,8 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { saveSettingsLocked(UserHandle.USER_SYSTEM); clearUserPoliciesLocked(userId); clearOverrideApnUnchecked(); clearApplicationRestrictions(userId); mInjector.getPackageManagerInternal().clearBlockUninstallForUser(userId); mOwners.clearDeviceOwner(); mOwners.writeDeviceOwner(); Loading @@ -8779,6 +8780,19 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { toggleBackupServiceActive(UserHandle.USER_SYSTEM, true); } private void clearApplicationRestrictions(int userId) { // Changing app restrictions involves disk IO, offload it to the background thread. mBackgroundHandler.post(() -> { final List<PackageInfo> installedPackageInfos = mInjector.getPackageManager(userId) .getInstalledPackages(MATCH_DIRECT_BOOT_AWARE | MATCH_DIRECT_BOOT_UNAWARE); final UserHandle userHandle = UserHandle.of(userId); for (final PackageInfo packageInfo : installedPackageInfos) { mInjector.getUserManager().setApplicationRestrictions( packageInfo.packageName, null /* restrictions */, userHandle); } }); } @Override public boolean setProfileOwner(ComponentName who, String ownerName, int userHandle) { if (!mHasFeature) { Loading Loading @@ -8898,6 +8912,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { policyData.mOwnerInstalledCaCerts.clear(); saveSettingsLocked(userId); clearUserPoliciesLocked(userId); clearApplicationRestrictions(userId); mOwners.removeProfileOwner(userId); mOwners.writeProfileOwner(userId); deleteTransferOwnershipBundleLocked(userId); Loading Loading
services/core/java/android/content/pm/PackageManagerInternal.java +5 −0 Original line number Diff line number Diff line Loading @@ -983,4 +983,9 @@ public abstract class PackageManagerInternal { * Returns if a package name is a valid system package. */ public abstract boolean isSystemPackage(@NonNull String packageName); /** * Unblocks uninstall for all packages for the user. */ public abstract void clearBlockUninstallForUser(@UserIdInt int userId); }
services/core/java/com/android/server/pm/PackageManagerService.java +8 −0 Original line number Diff line number Diff line Loading @@ -24721,6 +24721,14 @@ public class PackageManagerService extends IPackageManager.Stub return packageName.equals( PackageManagerService.this.ensureSystemPackageName(packageName)); } @Override public void clearBlockUninstallForUser(@UserIdInt int userId) { synchronized (mLock) { mSettings.clearBlockUninstallLPw(userId); mSettings.writePackageRestrictionsLPr(userId); } } } @GuardedBy("mLock")
services/core/java/com/android/server/pm/Settings.java +4 −0 Original line number Diff line number Diff line Loading @@ -1833,6 +1833,10 @@ public final class Settings { } } void clearBlockUninstallLPw(int userId) { mBlockUninstallPackages.remove(userId); } boolean getBlockUninstallLPr(int userId, String packageName) { ArraySet<String> packages = mBlockUninstallPackages.get(userId); if (packages == null) { Loading
services/core/java/com/android/server/pm/UserManagerService.java +16 −5 Original line number Diff line number Diff line Loading @@ -3153,13 +3153,17 @@ public class UserManagerService extends IUserManager.Stub { /** * Removes the app restrictions file for a specific package and user id, if it exists. * * @return whether there were any restrictions. */ private static void cleanAppRestrictionsForPackageLAr(String pkg, @UserIdInt int userId) { File dir = Environment.getUserSystemDirectory(userId); File resFile = new File(dir, packageToRestrictionsFileName(pkg)); private static boolean cleanAppRestrictionsForPackageLAr(String pkg, @UserIdInt int userId) { final File dir = Environment.getUserSystemDirectory(userId); final File resFile = new File(dir, packageToRestrictionsFileName(pkg)); if (resFile.exists()) { resFile.delete(); return true; } return false; } /** Loading Loading @@ -4003,17 +4007,24 @@ public class UserManagerService extends IUserManager.Stub { if (restrictions != null) { restrictions.setDefusable(true); } final boolean changed; synchronized (mAppRestrictionsLock) { if (restrictions == null || restrictions.isEmpty()) { cleanAppRestrictionsForPackageLAr(packageName, userId); changed = cleanAppRestrictionsForPackageLAr(packageName, userId); } else { // Write the restrictions to XML writeApplicationRestrictionsLAr(packageName, restrictions, userId); // TODO(b/154323615): avoid unnecessary broadcast when there is no change. changed = true; } } if (!changed) { return; } // Notify package of changes via an intent - only sent to explicitly registered receivers. Intent changeIntent = new Intent(Intent.ACTION_APPLICATION_RESTRICTIONS_CHANGED); final Intent changeIntent = new Intent(Intent.ACTION_APPLICATION_RESTRICTIONS_CHANGED); changeIntent.setPackage(packageName); changeIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); mContext.sendBroadcastAsUser(changeIntent, UserHandle.of(userId)); Loading
services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +16 −1 Original line number Diff line number Diff line Loading @@ -2703,7 +2703,6 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { final ComponentName doAdminReceiver = doAdmin.info.getComponent(); clearDeviceOwnerLocked(doAdmin, doUserId); Slog.i(LOG_TAG, "Removing admin artifacts..."); // TODO(b/149075700): Clean up application restrictions in UserManager. removeAdminArtifacts(doAdminReceiver, doUserId); Slog.i(LOG_TAG, "Migration complete."); Loading Loading @@ -8766,6 +8765,8 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { saveSettingsLocked(UserHandle.USER_SYSTEM); clearUserPoliciesLocked(userId); clearOverrideApnUnchecked(); clearApplicationRestrictions(userId); mInjector.getPackageManagerInternal().clearBlockUninstallForUser(userId); mOwners.clearDeviceOwner(); mOwners.writeDeviceOwner(); Loading @@ -8779,6 +8780,19 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { toggleBackupServiceActive(UserHandle.USER_SYSTEM, true); } private void clearApplicationRestrictions(int userId) { // Changing app restrictions involves disk IO, offload it to the background thread. mBackgroundHandler.post(() -> { final List<PackageInfo> installedPackageInfos = mInjector.getPackageManager(userId) .getInstalledPackages(MATCH_DIRECT_BOOT_AWARE | MATCH_DIRECT_BOOT_UNAWARE); final UserHandle userHandle = UserHandle.of(userId); for (final PackageInfo packageInfo : installedPackageInfos) { mInjector.getUserManager().setApplicationRestrictions( packageInfo.packageName, null /* restrictions */, userHandle); } }); } @Override public boolean setProfileOwner(ComponentName who, String ownerName, int userHandle) { if (!mHasFeature) { Loading Loading @@ -8898,6 +8912,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { policyData.mOwnerInstalledCaCerts.clear(); saveSettingsLocked(userId); clearUserPoliciesLocked(userId); clearApplicationRestrictions(userId); mOwners.removeProfileOwner(userId); mOwners.writeProfileOwner(userId); deleteTransferOwnershipBundleLocked(userId); Loading