OSDN Git Service

Use USER_SYSTEM instead of USER_ALL when enabling rollback.
authorRichard Uhler <ruhler@google.com>
Tue, 16 Apr 2019 09:30:07 +0000 (10:30 +0100)
committerRichard Uhler <ruhler@google.com>
Wed, 17 Apr 2019 12:59:13 +0000 (13:59 +0100)
The rollback manager needs to know the user that the install session is
associated with. When installing a package for USER_ALL, the install
session is associated with USER_SYSTEM.

This fixes an IllegalArgumentException that would otherwise be thrown if
we ask for all the sessions associated with USER_ALL.

Bug: 130530159
Test: adb install RollbackTestAppAv1.apk
      adb install -i com.android.shell --enable-rollback RollbackTestAppAv2.apk,
          run from both primary and secondary users.

Change-Id: I4a778ffb96cd79875a54da9de9d348d4744a7efb

services/core/java/com/android/server/pm/PackageManagerService.java

index c1587dc..ee8c4be 100644 (file)
@@ -14608,6 +14608,20 @@ public class PackageManagerService extends IPackageManager.Stub
             return mUser;
         }
 
+        /**
+         * Gets the user handle for the user that the rollback agent should
+         * use to look up information about this installation when enabling
+         * rollback.
+         */
+        UserHandle getRollbackUser() {
+            // The session for packages installed for "all" users is
+            // associated with the "system" user.
+            if (mUser == UserHandle.ALL) {
+                return UserHandle.SYSTEM;
+            }
+            return mUser;
+        }
+
         HandlerParams setTraceMethod(String traceMethod) {
             this.traceMethod = traceMethod;
             return this;
@@ -15226,7 +15240,7 @@ public class PackageManagerService extends IPackageManager.Stub
                             installedUsers);
                     enableRollbackIntent.putExtra(
                             PackageManagerInternal.EXTRA_ENABLE_ROLLBACK_USER,
-                            getUser().getIdentifier());
+                            getRollbackUser().getIdentifier());
                     enableRollbackIntent.setDataAndType(Uri.fromFile(new File(origin.resolvedPath)),
                             PACKAGE_MIME_TYPE);
                     enableRollbackIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);