From 88184a6be9461187fe989482d6b6c8247140eb94 Mon Sep 17 00:00:00 2001 From: Richard Uhler Date: Tue, 16 Apr 2019 11:30:25 +0100 Subject: [PATCH] Add -i com.android.shell when --enable-rollback is specified. com.android.shell has the TEST_MANAGE_ROLLBACKS permission needed to enable rollback for non-module packages, which is likely what the user wants when enabling rollback through the shell command. Set the installer to com.android.shell if no installer has been provided so that the user doesn't have to remember to set it themselves. Bug: 129835930 Test: adb install RollbackTestAppAv1.apk adb install --enable-rollback RollbackTestAppAv2.apk adb shell dumpsys rollback, confirming a rollback is available for the test app. Change-Id: I9f42cf0e1dab2efffb6badd6b8ea477887176bca --- .../android/server/pm/PackageManagerShellCommand.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/services/core/java/com/android/server/pm/PackageManagerShellCommand.java b/services/core/java/com/android/server/pm/PackageManagerShellCommand.java index 4e4a0e420d86d..6b804df2e0688 100644 --- a/services/core/java/com/android/server/pm/PackageManagerShellCommand.java +++ b/services/core/java/com/android/server/pm/PackageManagerShellCommand.java @@ -2423,6 +2423,16 @@ class PackageManagerShellCommand extends ShellCommand { sessionParams.setStaged(); break; case "--enable-rollback": + if (params.installerPackageName == null) { + // com.android.shell has the TEST_MANAGE_ROLLBACKS + // permission needed to enable rollback for non-module + // packages, which is likely what the user wants when + // enabling rollback through the shell command. Set + // the installer to com.android.shell if no installer + // has been provided so that the user doesn't have to + // remember to set it themselves. + params.installerPackageName = "com.android.shell"; + } sessionParams.installFlags |= PackageManager.INSTALL_ENABLE_ROLLBACK; break; default: