Keep enabled state across system uninstall
This change retains the original application state when uninstalling updates. This ensures that if the user explicitly disabled the application prior to uninstall updates, it remains that way after the system version is re-installed. Prior to this change, an updated system app, when uninstalled would have its PackageUserState removed. When the system version was later installed again, a new PackageUserState would be constructed with the default state (enabled). Bug: 190343571 Test: Manual; disable, uninstall update to system app Change-Id: I5808dd7dfdad98bc9cbe5ec035249cc24ec2619f
This commit is contained in:
@@ -21342,6 +21342,8 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
// for the uninstall-updates case and restricted profiles, remember the per-
|
||||
// user handle installed state
|
||||
int[] allUsers;
|
||||
final int freezeUser;
|
||||
final SparseArray<Pair<Integer, String>> enabledStateAndCallerPerUser;
|
||||
/** enabled state of the uninstalled application */
|
||||
synchronized (mLock) {
|
||||
uninstalledPs = mSettings.getPackageLPr(packageName);
|
||||
@@ -21386,16 +21388,23 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
}
|
||||
|
||||
info.origUsers = uninstalledPs.queryInstalledUsers(allUsers, true);
|
||||
}
|
||||
|
||||
final int freezeUser;
|
||||
if (isUpdatedSystemApp(uninstalledPs)
|
||||
&& ((deleteFlags & PackageManager.DELETE_SYSTEM_APP) == 0)) {
|
||||
// We're downgrading a system app, which will apply to all users, so
|
||||
// freeze them all during the downgrade
|
||||
freezeUser = UserHandle.USER_ALL;
|
||||
} else {
|
||||
freezeUser = removeUser;
|
||||
if (isUpdatedSystemApp(uninstalledPs)
|
||||
&& ((deleteFlags & PackageManager.DELETE_SYSTEM_APP) == 0)) {
|
||||
// We're downgrading a system app, which will apply to all users, so
|
||||
// freeze them all during the downgrade
|
||||
freezeUser = UserHandle.USER_ALL;
|
||||
enabledStateAndCallerPerUser = new SparseArray<>();
|
||||
for (int i = 0; i < allUsers.length; i++) {
|
||||
PackageUserState userState = uninstalledPs.readUserState(allUsers[i]);
|
||||
Pair<Integer, String> enabledStateAndCaller =
|
||||
new Pair<>(userState.enabled, userState.lastDisableAppCaller);
|
||||
enabledStateAndCallerPerUser.put(allUsers[i], enabledStateAndCaller);
|
||||
}
|
||||
} else {
|
||||
freezeUser = removeUser;
|
||||
enabledStateAndCallerPerUser = null;
|
||||
}
|
||||
}
|
||||
|
||||
synchronized (mInstallLock) {
|
||||
@@ -21464,6 +21473,19 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
}
|
||||
}
|
||||
}
|
||||
if (enabledStateAndCallerPerUser != null) {
|
||||
synchronized (mLock) {
|
||||
for (int i = 0; i < allUsers.length; i++) {
|
||||
Pair<Integer, String> enabledStateAndCaller =
|
||||
enabledStateAndCallerPerUser.get(allUsers[i]);
|
||||
getPackageSetting(packageName)
|
||||
.setEnabled(enabledStateAndCaller.first,
|
||||
allUsers[i],
|
||||
enabledStateAndCaller.second);
|
||||
}
|
||||
mSettings.writeAllUsersPackageRestrictionsLPr();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return res ? PackageManager.DELETE_SUCCEEDED : PackageManager.DELETE_FAILED_INTERNAL_ERROR;
|
||||
|
||||
Reference in New Issue
Block a user