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

Commit a9d4b676 authored by Songchun Fan's avatar Songchun Fan
Browse files

[archive] fix permission restoration on unarchive after install-archived

Use updated users for permission restoration if the app being updated is
previously installed as archived. This change slightly changes the order
of things. Previously: 1) restoreAndPostInstall 2)
handlePackagePostInstall on handler thread 3) restore permission in the
middle of handlePackagePostInstall. After this CL: 1)
restoreAndPostIntall 2) restore permisison on handler thread 3)
handlePackagePostInstall on the handler thread.

BUG: 325618438
Test: manual

Change-Id: Ida9b51932b26efc60c1867b0d4e513a8fd8575b3
parent 1d8fc144
Loading
Loading
Loading
Loading
+20 −9
Original line number Diff line number Diff line
@@ -829,7 +829,8 @@ final class InstallPackageHelper {

        if (DEBUG_INSTALL) Log.v(TAG, "+ starting restore round-trip " + token);

        if (request.getReturnCode() == PackageManager.INSTALL_SUCCEEDED && doRestore) {
        final boolean succeeded = request.getReturnCode() == PackageManager.INSTALL_SUCCEEDED;
        if (succeeded && doRestore) {
            // Pass responsibility to the Backup Manager.  It will perform a
            // restore if appropriate, then pass responsibility back to the
            // Package Manager to run the post-install observer callbacks
@@ -843,10 +844,27 @@ final class InstallPackageHelper {
        // need to be snapshotted or restored for the package.
        //
        // TODO(narayan): Get this working for cases where userId == UserHandle.USER_ALL.
        if (request.getReturnCode() == PackageManager.INSTALL_SUCCEEDED && !doRestore && update) {
        if (succeeded && !doRestore && update) {
            doRestore = performRollbackManagerRestore(userId, token, request);
        }

        if (succeeded && !request.hasPostInstallRunnable()) {
            boolean hasNeverBeenRestored =
                    packageSetting != null && packageSetting.isPendingRestore();
            request.setPostInstallRunnable(() -> {
                // Permissions should be restored on each user that has the app installed for the
                // first time, unless it's an unarchive install for an archived app, in which case
                // the permissions should be restored on each user that has the app updated.
                int[] userIdsToRestorePermissions = hasNeverBeenRestored
                        ? request.getUpdateBroadcastUserIds()
                        : request.getFirstTimeBroadcastUserIds();
                for (int restorePermissionUserId : userIdsToRestorePermissions) {
                    mPm.restorePermissionsAndUpdateRolesForNewUserInstall(request.getName(),
                            restorePermissionUserId);
                }
            });
        }

        if (doRestore) {
            if (packageSetting != null) {
                synchronized (mPm.mLock) {
@@ -2851,7 +2869,6 @@ final class InstallPackageHelper {
            mPm.notifyInstantAppPackageInstalled(request.getPkg().getPackageName(),
                    request.getNewUsers());

            request.populateBroadcastUsers();
            final int[] firstUserIds = request.getFirstTimeBroadcastUserIds();

            if (request.getPkg().getStaticSharedLibraryName() == null) {
@@ -2863,12 +2880,6 @@ final class InstallPackageHelper {
                    mPm.mRequiredInstallerPackage,
                    /* packageSender= */ mPm, launchedForRestore, killApp, update, archived);

            // Work that needs to happen on first install within each user
            for (int userId : firstUserIds) {
                mPm.restorePermissionsAndUpdateRolesForNewUserInstall(packageName,
                        userId);
            }

            if (request.isAllNewUsers() && !update) {
                mPm.notifyPackageAdded(packageName, request.getAppId());
            } else {
+13 −3
Original line number Diff line number Diff line
@@ -692,6 +692,14 @@ final class InstallRequest {
        }
    }

    public void setPostInstallRunnable(Runnable runnable) {
        mPostInstallRunnable = runnable;
    }

    public boolean hasPostInstallRunnable() {
        return mPostInstallRunnable != null;
    }

    public void runPostInstallRunnable() {
        if (mPostInstallRunnable != null) {
            mPostInstallRunnable.run();
@@ -753,6 +761,7 @@ final class InstallRequest {

    public void setNewUsers(int[] newUsers) {
        mNewUsers = newUsers;
        populateBroadcastUsers();
    }

    public void setOriginPackage(String originPackage) {
@@ -829,10 +838,11 @@ final class InstallRequest {
    }

    /**
     *  Determine the set of users who are adding this package for the first time vs. those who are
     *  seeing an update.
     *  Determine the set of users who are adding this package for the first time (aka "new" users)
     *  vs. those who are seeing an update (aka "update" users). The lists can be calculated as soon
     *  as the "new" users are set.
     */
    public void populateBroadcastUsers() {
    private void populateBroadcastUsers() {
        assertScanResultExists();
        mFirstTimeBroadcastUserIds = EMPTY_INT_ARRAY;
        mFirstTimeBroadcastInstantUserIds = EMPTY_INT_ARRAY;