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

Commit f34a4933 authored by Alex Buynytskyy's avatar Alex Buynytskyy
Browse files

New package flag to indicate that data was not restored.

Bug: 321279009
Test: atest PackageManagerTest
Change-Id: If06a93100ff142b4030d19734b23f0bcf4b29a8c
parent 984306a8
Loading
Loading
Loading
Loading
+27 −4
Original line number Diff line number Diff line
@@ -800,10 +800,27 @@ final class InstallPackageHelper {
                    "restoreAndPostInstall userId=" + userId + " package=" + request.getPkg());
        }

        // A restore should be requested at this point if (a) the install
        // succeeded, (b) the operation is not an update.
        PackageSetting packageSetting = null;

        final boolean update = request.isUpdate();
        boolean doRestore = !update && request.getPkg() != null;
        boolean doRestore = false;
        if (request.getPkg() != null && !request.isArchived()) {
            // A restore should be requested at this point:
            // if the install succeeded and it's not an archived install
            if (!update) {
                // AND the operation is not an update,
                doRestore = true;
            } else {
                // OR the package has never been restored.
                String packageName = request.getPkg().getPackageName();
                synchronized (mPm.mLock) {
                    packageSetting = mPm.mSettings.getPackageLPr(packageName);
                    if (packageSetting != null && packageSetting.isPendingRestore()) {
                        doRestore = true;
                    }
                }
            }
        }

        // Set up the post-install work request bookkeeping.  This will be used
        // and cleaned up by the post-install event handling regardless of whether
@@ -833,7 +850,13 @@ final class InstallPackageHelper {
            doRestore = performRollbackManagerRestore(userId, token, request);
        }

        if (!doRestore) {
        if (doRestore) {
            if (packageSetting != null) {
                synchronized (mPm.mLock) {
                    packageSetting.setPendingRestore(false);
                }
            }
        } else {
            // No restore possible, or the Backup Manager was mysteriously not
            // available -- just fire the post-install work request directly.
            if (DEBUG_INSTALL) Log.v(TAG, "No restore - queue post-install for " + token);
+2 −0
Original line number Diff line number Diff line
@@ -1550,6 +1550,8 @@ public class PackageManagerService implements PackageSender, TestUtilityService
            }
            pkgSetting
                    .setPkg(null)
                    // This package was installed as archived. Need to mark it for later restore.
                    .setPendingRestore(true)
                    .modifyUserState(userId)
                    .setInstalled(false)
                    .setArchiveState(archiveState);
+17 −1
Original line number Diff line number Diff line
@@ -94,7 +94,8 @@ public class PackageSetting extends SettingBase implements PackageStateInternal
                INSTALL_PERMISSION_FIXED,
                UPDATE_AVAILABLE,
                FORCE_QUERYABLE_OVERRIDE,
                SCANNED_AS_STOPPED_SYSTEM_APP
                SCANNED_AS_STOPPED_SYSTEM_APP,
                PENDING_RESTORE,
        })
        public @interface Flags {
        }
@@ -102,6 +103,7 @@ public class PackageSetting extends SettingBase implements PackageStateInternal
        private static final int UPDATE_AVAILABLE = 1 << 1;
        private static final int FORCE_QUERYABLE_OVERRIDE = 1 << 2;
        private static final int SCANNED_AS_STOPPED_SYSTEM_APP = 1 << 3;
        private static final int PENDING_RESTORE = 1 << 4;
    }
    private int mBooleans;

@@ -543,6 +545,20 @@ public class PackageSetting extends SettingBase implements PackageStateInternal
        return mSharedUserAppId > 0;
    }

    /**
     * @see PackageState#isPendingRestore()
     */
    public PackageSetting setPendingRestore(boolean value) {
        setBoolean(Booleans.PENDING_RESTORE, value);
        onChanged();
        return this;
    }

    @Override
    public boolean isPendingRestore() {
        return getBoolean(Booleans.PENDING_RESTORE);
    }

    @Override
    public String toString() {
        return "PackageSetting{"
+8 −1
Original line number Diff line number Diff line
@@ -4883,7 +4883,7 @@ public final class Settings implements Watchable, Snappable, ResilientAtomicFile

    @NeverCompile // Avoid size overhead of debugging code.
    void dumpPackageLPr(PrintWriter pw, String prefix, String checkinTag,
            ArraySet<String> permissionNames, PackageSetting ps,
            ArraySet<String> permissionNames, @NonNull PackageSetting ps,
            LegacyPermissionState permissionsState, SimpleDateFormat sdf, Date date,
            List<UserInfo> users, boolean dumpAll, boolean dumpAllComponents) {
        AndroidPackage pkg = ps.getPkg();
@@ -5022,6 +5022,10 @@ public final class Settings implements Watchable, Snappable, ResilientAtomicFile
                pw.print(prefix); pw.print("  privateFlags="); printFlags(pw,
                        privateFlags, PRIVATE_FLAG_DUMP_SPEC); pw.println();
            }
            if (ps.isPendingRestore()) {
                pw.print(prefix); pw.print("  pendingRestore=true");
                pw.println();
            }
            if (!pkg.isUpdatableSystem()) {
                pw.print(prefix); pw.print("  updatableSystem=false");
                pw.println();
@@ -5232,6 +5236,9 @@ public final class Settings implements Watchable, Snappable, ResilientAtomicFile
        pw.print(prefix); pw.print("  privatePkgFlags="); printFlags(pw, ps.getPrivateFlags(),
                PRIVATE_FLAG_DUMP_SPEC);
        pw.println();
        if (ps.isPendingRestore()) {
            pw.print(prefix); pw.println("  pendingRestore=true");
        }
        pw.print(prefix); pw.print("  apexModuleName="); pw.println(ps.getApexModuleName());

        if (pkg != null && pkg.getOverlayTarget() != null) {
+8 −0
Original line number Diff line number Diff line
@@ -265,6 +265,14 @@ public interface PackageState {
     */
    boolean hasSharedUser();


    /**
     * Whether this app needs to be restore during next install/update.
     * E.g. if an app was installed as archived and never had a chance to restore its data.
     * @hide
     */
    boolean isPendingRestore();

    /**
     * Retrieves the shared user app ID. Note that the actual shared user data is not available here
     * and must be queried separately.