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

Commit e154cd37 authored by JW Wang's avatar JW Wang
Browse files

Move #addToken and #hasToken into Rollback (2/n)

Move some methods from NewRollback into Rollack. By reducing the
difference b/t NewRollback and Rollback, it will be easier to merge
them later.

Bug: 147400979
Test: atest RollbackTest
Change-Id: I248f26345cc4070a932909a492d71e5940ed8e66
parent b481075f
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
@@ -171,6 +171,13 @@ class Rollback {
     */
    @Nullable public final String mInstallerPackageName;

    /**
     * This array holds all of the rollback tokens associated with package sessions included in
     * this rollback.
     */
    @GuardedBy("mLock")
    private final IntArray mTokens = new IntArray();

    /**
     * Constructs a new, empty Rollback instance.
     *
@@ -766,6 +773,26 @@ class Rollback {
        }
    }

    /**
     * Adds a rollback token to be associated with this rollback. This may be used to
     * identify which rollback should be removed in case {@link PackageManager} sends an
     * {@link Intent#ACTION_CANCEL_ENABLE_ROLLBACK} intent.
     */
    void addToken(int token) {
        synchronized (mLock) {
            mTokens.add(token);
        }
    }

    /**
     * Returns true if this rollback is associated with the provided {@code token}.
     */
    boolean hasToken(int token) {
        synchronized (mLock) {
            return mTokens.indexOf(token) != -1;
        }
    }

    static String rollbackStateToString(@RollbackState int state) {
        switch (state) {
            case Rollback.ROLLBACK_STATE_ENABLING: return "enabling";
+4 −31
Original line number Diff line number Diff line
@@ -236,9 +236,9 @@ class RollbackManagerServiceImpl extends IRollbackManager.Stub {
                    }
                    synchronized (mLock) {
                        NewRollback found = null;
                        for (NewRollback rollback : mNewRollbacks) {
                            if (rollback.hasToken(token)) {
                                found = rollback;
                        for (NewRollback newRollback : mNewRollbacks) {
                            if (newRollback.rollback.hasToken(token)) {
                                found = newRollback;
                                break;
                            }
                        }
@@ -807,7 +807,7 @@ class RollbackManagerServiceImpl extends IRollbackManager.Stub {
                mNewRollbacks.add(newRollback);
            }
        }
        newRollback.addToken(token);
        newRollback.rollback.addToken(token);

        return enableRollbackForPackageSession(newRollback.rollback, packageSession);
    }
@@ -1337,13 +1337,6 @@ class RollbackManagerServiceImpl extends IRollbackManager.Stub {
    private static class NewRollback {
        public final Rollback rollback;

        /**
         * This array holds all of the rollback tokens associated with package sessions included in
         * this rollback.
         */
        @GuardedBy("mNewRollbackLock")
        private final IntArray mTokens = new IntArray();

        /**
         * Session ids for all packages in the install. For multi-package sessions, this is the list
         * of child session ids. For normal sessions, this list is a single element with the normal
@@ -1366,26 +1359,6 @@ class RollbackManagerServiceImpl extends IRollbackManager.Stub {
            this.mPackageSessionIds = packageSessionIds;
        }

        /**
         * Adds a rollback token to be associated with this NewRollback. This may be used to
         * identify which rollback should be cancelled in case {@link PackageManager} sends an
         * {@link Intent#ACTION_CANCEL_ENABLE_ROLLBACK} intent.
         */
        void addToken(int token) {
            synchronized (mNewRollbackLock) {
                mTokens.add(token);
            }
        }

        /**
         * Returns true if this NewRollback is associated with the provided {@code token}.
         */
        boolean hasToken(int token) {
            synchronized (mNewRollbackLock) {
                return mTokens.indexOf(token) != -1;
            }
        }

        /**
         * Returns true if this NewRollback contains the provided {@code packageSessionId}.
         */