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

Commit 7fcc730e authored by JW Wang's avatar JW Wang
Browse files

Always enable apk-in-apex before the apex (2/n)

To keep a rollback object in a consistent state, an apex shouldn't be
enabled (for rollback) until all its embedded apk-in-apex are enabled
successfully.

Bug: 149352598
Test: test RollbackTest StagedRollbackTest
Change-Id: I4d0208118050f948675093f4ed67de8ae148f41b
parent b3ea9a61
Loading
Loading
Loading
Loading
+16 −12
Original line number Diff line number Diff line
@@ -869,14 +869,6 @@ class RollbackManagerServiceImpl extends IRollbackManager.Stub {
            return false;
        }

        ApplicationInfo appInfo = pkgInfo.applicationInfo;
        boolean success = rollback.enableForPackage(packageName, newPackage.versionCode,
                pkgInfo.getLongVersionCode(), isApex, appInfo.sourceDir,
                appInfo.splitSourceDirs, session.rollbackDataPolicy);
        if (!success) {
            return success;
        }

        if (isApex) {
            // Check if this apex contains apks inside it. If true, then they should be added as
            // a RollbackPackageInfo into this rollback
@@ -894,12 +886,24 @@ class RollbackManagerServiceImpl extends IRollbackManager.Stub {
                    Slog.e(TAG, apkInApex + " is not installed");
                    return false;
                }
                success = rollback.enableForPackageInApex(
                        apkInApex, apkPkgInfo.getLongVersionCode(), session.rollbackDataPolicy);
                if (!success) return success;
                if (!rollback.enableForPackageInApex(
                        apkInApex, apkPkgInfo.getLongVersionCode(), session.rollbackDataPolicy)) {
                    return false;
                }
            }
        return true;
        }

        /**
         * The order is important here! Always enable the embedded apk-in-apex (if any) before
         * enabling the embedding apex. Otherwise the rollback object might be in an inconsistent
         * state where an embedding apex is successfully enabled while one of its embedded
         * apk-in-apex failed. Note {@link Rollback#allPackagesEnabled()} won't behave correctly if
         * a rollback object is inconsistent because it doesn't count apk-in-apex.
         */
        ApplicationInfo appInfo = pkgInfo.applicationInfo;
        return rollback.enableForPackage(packageName, newPackage.versionCode,
                pkgInfo.getLongVersionCode(), isApex, appInfo.sourceDir,
                appInfo.splitSourceDirs, session.rollbackDataPolicy);
    }

    @Override