Use USER_SYSTEM instead of USER_ALL when enabling rollback.

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
This commit is contained in:
Richard Uhler
2019-04-16 10:30:07 +01:00
parent 6243f0aa27
commit d6f83bb511

View 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);