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

Commit fd42d3c9 authored by Gavin Corkery's avatar Gavin Corkery
Browse files

Check eligibility before calling snapshotAndRestoreUserData

In cases where a rollback is not being enabled or a downgrade
is not taking place, PackageManagerService needlessly calls
into RollbackManagerService, giving the impression that a
userdata backup/restore is taking place. Performing this
eligibility check should make the post-install flow clearer.

Test: atest RollbackTest
Bug: 139920268
Change-Id: I7ccea264aefa24df52751647f45f38df4ae15cf4
parent 2c833c2b
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -13853,7 +13853,7 @@ public class PackageManagerService extends IPackageManager.Stub
        // If this is an update to a package that might be potentially downgraded, then we
        // need to check with the rollback manager whether there's any userdata that might
        // need to be restored for the package.
        // need to be snapshotted or restored for the package.
        //
        // TODO(narayan): Get this working for cases where userId == UserHandle.USER_ALL.
        if (res.returnCode == PackageManager.INSTALL_SUCCEEDED && !doRestore && update) {
@@ -13880,12 +13880,16 @@ public class PackageManagerService extends IPackageManager.Stub
                installedUsers = ps.queryInstalledUsers(allUsers, true);
            }
            if (ps != null) {
            boolean doSnapshotOrRestore = data != null && data.args != null
                    && ((data.args.installFlags & PackageManager.INSTALL_ENABLE_ROLLBACK) != 0
                    || (data.args.installFlags & PackageManager.INSTALL_REQUEST_DOWNGRADE) != 0);
            if (ps != null && doSnapshotOrRestore) {
                try {
                    rm.snapshotAndRestoreUserData(packageName, installedUsers, appId, ceDataInode,
                            seInfo, token);
                } catch (RemoteException re) {
                    // Cannot happen, the RollbackManager is hosted in the same process.
                    Log.e(TAG, "Error snapshotting/restoring user data: " + re);
                }
                doRestore = true;
            }