Merge "Fix cleanup when an app with SUSPEND_APPS is deleted" into rvc-dev

This commit is contained in:
Suprabh Shukla
2020-07-01 20:41:04 +00:00
committed by Android (Google) Code Review
2 changed files with 37 additions and 19 deletions

View File

@@ -19165,9 +19165,7 @@ public class PackageManagerService extends IPackageManager.Stub
final boolean systemApp = isSystemApp(ps);
final int userId = user == null ? UserHandle.USER_ALL : user.getIdentifier();
if (ps.getPermissionsState().hasPermission(Manifest.permission.SUSPEND_APPS, userId)) {
unsuspendForSuspendingPackage(packageName, userId);
}
if ((!systemApp || (flags & PackageManager.DELETE_SYSTEM_APP) != 0)
&& userId != UserHandle.USER_ALL) {
// The caller is asking that the package only be deleted for a single
@@ -19225,6 +19223,20 @@ public class PackageManagerService extends IPackageManager.Stub
outInfo, writeSettings);
}
// If the package removed had SUSPEND_APPS, unset any restrictions that might have been in
// place for all affected users.
int[] affectedUserIds = (outInfo != null) ? outInfo.removedUsers : null;
if (affectedUserIds == null) {
affectedUserIds = resolveUserIds(userId);
}
for (final int affectedUserId : affectedUserIds) {
if (ps.getPermissionsState().hasPermission(Manifest.permission.SUSPEND_APPS,
affectedUserId)) {
unsuspendForSuspendingPackage(packageName, affectedUserId);
removeAllDistractingPackageRestrictions(affectedUserId);
}
}
// Take a note whether we deleted the package for all users
if (outInfo != null) {
outInfo.removedForAllUsers = mPackages.get(ps.name) == null;

View File

@@ -125,7 +125,6 @@ import java.util.Base64;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -291,7 +290,8 @@ class PackageManagerShellCommand extends ShellCommand {
case "get-stagedsessions":
return runListStagedSessions();
case "uninstall-system-updates":
return uninstallSystemUpdates();
String packageName = getNextArg();
return uninstallSystemUpdates(packageName);
case "rollback-app":
return runRollbackApp();
case "get-moduleinfo":
@@ -409,15 +409,22 @@ class PackageManagerShellCommand extends ShellCommand {
}
}
private int uninstallSystemUpdates() {
private int uninstallSystemUpdates(String packageName) {
final PrintWriter pw = getOutPrintWriter();
List<String> failedUninstalls = new LinkedList<>();
boolean failedUninstalls = false;
try {
final ParceledListSlice<ApplicationInfo> packages =
mInterface.getInstalledApplications(
PackageManager.MATCH_SYSTEM_ONLY, UserHandle.USER_SYSTEM);
final IPackageInstaller installer = mInterface.getPackageInstaller();
List<ApplicationInfo> list = packages.getList();
final List<ApplicationInfo> list;
if (packageName == null) {
final ParceledListSlice<ApplicationInfo> packages =
mInterface.getInstalledApplications(
PackageManager.MATCH_SYSTEM_ONLY, UserHandle.USER_SYSTEM);
list = packages.getList();
} else {
list = new ArrayList<>(1);
list.add(mInterface.getApplicationInfo(packageName,
PackageManager.MATCH_SYSTEM_ONLY, UserHandle.USER_SYSTEM));
}
for (ApplicationInfo info : list) {
if (info.isUpdatedSystemApp()) {
pw.println("Uninstalling updates to " + info.packageName + "...");
@@ -430,7 +437,8 @@ class PackageManagerShellCommand extends ShellCommand {
final int status = result.getIntExtra(PackageInstaller.EXTRA_STATUS,
PackageInstaller.STATUS_FAILURE);
if (status != PackageInstaller.STATUS_SUCCESS) {
failedUninstalls.add(info.packageName);
failedUninstalls = true;
pw.println("Couldn't uninstall package: " + info.packageName);
}
}
}
@@ -440,10 +448,7 @@ class PackageManagerShellCommand extends ShellCommand {
+ e.getMessage() + "]");
return 0;
}
if (!failedUninstalls.isEmpty()) {
pw.println("Failure [Couldn't uninstall packages: "
+ TextUtils.join(", ", failedUninstalls)
+ "]");
if (failedUninstalls) {
return 0;
}
pw.println("Success");
@@ -3824,9 +3829,10 @@ class PackageManagerShellCommand extends ShellCommand {
pw.println(" get-harmful-app-warning [--user <USER_ID>] <PACKAGE>");
pw.println(" Return the harmful app warning message for the given app, if present");
pw.println();
pw.println(" uninstall-system-updates");
pw.println(" Remove updates to all system applications and fall back to their /system " +
"version.");
pw.println(" uninstall-system-updates [<PACKAGE>]");
pw.println(" Removes updates to the given system application and falls back to its");
pw.println(" /system version. Does nothing if the given package is not a system app.");
pw.println(" If no package is specified, removes updates to all system applications.");
pw.println("");
pw.println(" get-moduleinfo [--all | --installed] [module-name]");
pw.println(" Displays module info. If module-name is specified only that info is shown");