Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e75c0b98 authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Fix two multi-user bugs in package upgrade.

When upgrading a package, we need to fill in the "origUsers" field
so that we can clone the installed state correctly.  This was done
for child package, but never set for the parent package.

Also fix a bug where a secondary user requested a package to be
moved.  Because that move was pushed onto a Handler, the calling
userId appeared to be the device owner instead of the user that
actually requested the move.  (Later in the upgrade flow there is
code that force-installs the package for the requesting user.)

Bug: 26729822
Change-Id: I2d2a007c73558f29a3f8c1408ec373fce6e87761
parent af8be42b
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -13794,6 +13794,7 @@ public class PackageManagerService extends IPackageManager.Stub {
        final PackageParser.Package oldPackage;
        final String pkgName = pkg.packageName;
        final int[] allUsers;
        final int[] installedUsers;
        // First find the old package info and check signatures
        synchronized(mPackages) {
@@ -13836,6 +13837,7 @@ public class PackageManagerService extends IPackageManager.Stub {
            // In case of rollback, remember per-user/profile install state
            allUsers = sUserManager.getUserIds();
            installedUsers = ps.queryInstalledUsers(allUsers, true);
        }
        // Update what is removed
@@ -13843,6 +13845,7 @@ public class PackageManagerService extends IPackageManager.Stub {
        res.removedInfo.uid = oldPackage.applicationInfo.uid;
        res.removedInfo.removedPackage = oldPackage.packageName;
        res.removedInfo.isUpdate = true;
        res.removedInfo.origUsers = installedUsers;
        final int childCount = (oldPackage.childPackages != null)
                ? oldPackage.childPackages.size() : 0;
        for (int i = 0; i < childCount; i++) {
@@ -19397,12 +19400,13 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName());
    public int movePackage(final String packageName, final String volumeUuid) {
        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MOVE_PACKAGE, null);
        final UserHandle user = new UserHandle(UserHandle.getCallingUserId());
        final int moveId = mNextMoveId.getAndIncrement();
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                try {
                    movePackageInternal(packageName, volumeUuid, moveId);
                    movePackageInternal(packageName, volumeUuid, moveId, user);
                } catch (PackageManagerException e) {
                    Slog.w(TAG, "Failed to move " + packageName, e);
                    mMoveCallbacks.notifyStatusChanged(moveId,
@@ -19414,8 +19418,7 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName());
    }
    private void movePackageInternal(final String packageName, final String volumeUuid,
            final int moveId) throws PackageManagerException {
        final UserHandle user = new UserHandle(UserHandle.getCallingUserId());
            final int moveId, UserHandle user) throws PackageManagerException {
        final StorageManager storage = mContext.getSystemService(StorageManager.class);
        final PackageManager pm = mContext.getPackageManager();