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

Commit 3ffedc45 authored by Mohammad Samiul Islam's avatar Mohammad Samiul Islam
Browse files

Check if number of packages enabled for rollback is equal to number of sessions

The check was disabled in ag/9974518. It is now being re-enabled.

Bug: 142712057
Test: atest StagedRollbackTest
Test: atest RollbackTest
Change-Id: If45347ed330c627c6dc777c7d560611a7f9daaf7
parent 3fcecfc1
Loading
Loading
Loading
Loading
+37 −3
Original line number Diff line number Diff line
@@ -62,7 +62,7 @@ class Rollback {

    private static final String TAG = "RollbackManager";

    @IntDef(flag = true, prefix = { "ROLLBACK_STATE_" }, value = {
    @IntDef(prefix = { "ROLLBACK_STATE_" }, value = {
            ROLLBACK_STATE_ENABLING,
            ROLLBACK_STATE_AVAILABLE,
            ROLLBACK_STATE_COMMITTED,
@@ -92,6 +92,19 @@ class Rollback {
     */
    static final int ROLLBACK_STATE_DELETED = 4;

    @IntDef(flag = true, prefix = { "MATCH_" }, value = {
            MATCH_APK_IN_APEX,
    })
    @Retention(RetentionPolicy.SOURCE)
    @interface RollbackInfoFlags {}

    /**
     * {@link RollbackInfo} flag: include {@code RollbackInfo} packages that are apk-in-apex.
     * These packages do not have their own sessions. They are embedded in an apex which has a
     * session id.
     */
    static final int MATCH_APK_IN_APEX = 1;

    /**
     * The session ID for the staged session if this rollback data represents a staged session,
     * {@code -1} otherwise.
@@ -726,9 +739,30 @@ class Rollback {
        }
    }

    int getPackageCount() {
    /**
     * Returns the number of {@link PackageRollbackInfo} we are storing in this {@link Rollback}
     * instance. By default, this method does not include apk-in-apex package in the count.
     *
     * @param flags Apk-in-apex packages can be included in the count by passing
     * {@link Rollback#MATCH_APK_IN_APEX}
     *
     * @return Counts number of {@link PackageRollbackInfo} stored in the {@link Rollback}
     * according to {@code flags} passed
     */
    int getPackageCount(@RollbackInfoFlags int flags) {
        synchronized (mLock) {
            return info.getPackages().size();
            List<PackageRollbackInfo> packages = info.getPackages();
            if ((flags & MATCH_APK_IN_APEX) != 0) {
                return packages.size();
            }

            int packagesWithoutApkInApex = 0;
            for (PackageRollbackInfo rollbackInfo : packages) {
                if (!rollbackInfo.isApkInApex()) {
                    packagesWithoutApkInApex++;
                }
            }
            return packagesWithoutApkInApex;
        }
    }

+9 −6
Original line number Diff line number Diff line
@@ -1226,12 +1226,15 @@ class RollbackManagerServiceImpl extends IRollbackManager.Stub {
            return null;
        }

        // TODO(b/142712057): Re-enable this check. For that we need count of apks-in-apex
//        if (rollback.getPackageCount() != newRollback.getPackageSessionIdCount()) {
//            Slog.e(TAG, "Failed to enable rollback for all packages in session.");
//            rollback.delete(mAppDataRollbackHelper);
//            return null;
//        }
        // We are checking if number of packages (excluding apk-in-apex) we enabled for rollback is
        // equal to the number of sessions we are installing, to ensure we didn't skip enabling
        // of any sessions. If we successfully enable an apex, then we can assume we enabled
        // rollback for the embedded apk-in-apex, if any.
        if (rollback.getPackageCount(0 /*flags*/) != newRollback.getPackageSessionIdCount()) {
            Slog.e(TAG, "Failed to enable rollback for all packages in session.");
            rollback.delete(mAppDataRollbackHelper);
            return null;
        }

        rollback.saveRollback();
        synchronized (mLock) {