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

Commit 9b7a4d81 authored by Eric Biggers's avatar Eric Biggers
Browse files

StorageManagerService: rename mLocalUnlockedUsers to mCeUnlockedUsers

mLocalUnlockedUsers contains the IDs of the users whose CE storage is
unlocked.  Rename it to mCeUnlockedUsers to make this clear.  Also
rename WatchedLockedUsers to WatchedUnlockedUsers.

No change in behavior except s/Local/CE/ in dump().

Bug: 306204742
Flag: exempt, mechanical refactoring
Test: presubmit
Change-Id: I11d13967564b04a9efc2cb20678677e71ef6e91b
parent b0e4f7e7
Loading
Loading
Loading
Loading
+27 −25
Original line number Diff line number Diff line
@@ -377,15 +377,14 @@ class StorageManagerService extends IStorageManager.Stub
    private final Object mLock = LockGuard.installNewLock(LockGuard.INDEX_STORAGE);

    /**
     * mLocalUnlockedUsers affects the return value of isUserUnlocked.  If
     * any value in the array changes, then the binder cache for
     * isUserUnlocked must be invalidated.  When adding mutating methods to
     * WatchedLockedUsers, be sure to invalidate the cache in the new
     * methods.
     * mCeUnlockedUsers affects the return value of {@link UserManager#isUserUnlocked}.  If any
     * value in the array changes, then the binder cache for {@link UserManager#isUserUnlocked} must
     * be invalidated.  When adding mutating methods to this class, be sure to invalidate the cache
     * in the new methods.
     */
    private static class WatchedLockedUsers {
    private static class WatchedUnlockedUsers {
        private int[] users = EmptyArray.INT;
        public WatchedLockedUsers() {
        public WatchedUnlockedUsers() {
            invalidateIsUserUnlockedCache();
        }
        public void append(int userId) {
@@ -417,10 +416,14 @@ class StorageManagerService extends IStorageManager.Stub
        }
    }

    /** Set of users that we know are unlocked. */
    /** Set of users whose CE storage is unlocked. */
    @GuardedBy("mLock")
    private WatchedLockedUsers mLocalUnlockedUsers = new WatchedLockedUsers();
    /** Set of users that system knows are unlocked. */
    private WatchedUnlockedUsers mCeUnlockedUsers = new WatchedUnlockedUsers();

    /**
     * Set of users that are in the RUNNING_UNLOCKED state.  This differs from {@link
     * mCeUnlockedUsers} in that a user can be stopped but still have its CE storage unlocked.
     */
    @GuardedBy("mLock")
    private int[] mSystemUnlockedUsers = EmptyArray.INT;

@@ -1135,11 +1138,10 @@ class StorageManagerService extends IStorageManager.Stub
        }
    }

    // If vold knows that some users have their storage unlocked already (which
    // can happen after a "userspace reboot"), then add those users to
    // mLocalUnlockedUsers.  Do this right away and don't wait until
    // PHASE_BOOT_COMPLETED, since the system may unlock users before then.
    private void restoreLocalUnlockedUsers() {
    // If vold knows that some users have their CE storage unlocked already (which can happen after
    // a "userspace reboot"), then add those users to mCeUnlockedUsers.  Do this right away and
    // don't wait until PHASE_BOOT_COMPLETED, since the system may unlock users before then.
    private void restoreCeUnlockedUsers() {
        final int[] userIds;
        try {
            userIds = mVold.getUnlockedUsers();
@@ -1155,7 +1157,7 @@ class StorageManagerService extends IStorageManager.Stub
                // reconnecting to vold after it crashed and was restarted, in
                // which case things will be the other way around --- we'll know
                // about the unlocked users but vold won't.
                mLocalUnlockedUsers.appendAll(userIds);
                mCeUnlockedUsers.appendAll(userIds);
            }
        }
    }
@@ -2062,7 +2064,7 @@ class StorageManagerService extends IStorageManager.Stub
                connectVold();
            }, DateUtils.SECOND_IN_MILLIS);
        } else {
            restoreLocalUnlockedUsers();
            restoreCeUnlockedUsers();
            onDaemonConnected();
        }
    }
@@ -3212,9 +3214,9 @@ class StorageManagerService extends IStorageManager.Stub

        try {
            mVold.createUserKey(userId, serialNumber, ephemeral);
            // New keys are always unlocked.
            // Since the user's CE key was just created, the user's CE storage is now unlocked.
            synchronized (mLock) {
                mLocalUnlockedUsers.append(userId);
                mCeUnlockedUsers.append(userId);
            }
        } catch (Exception e) {
            Slog.wtf(TAG, e);
@@ -3229,9 +3231,9 @@ class StorageManagerService extends IStorageManager.Stub

        try {
            mVold.destroyUserKey(userId);
            // Destroying a key also locks it.
            // Since the user's CE key was just destroyed, the user's CE storage is now locked.
            synchronized (mLock) {
                mLocalUnlockedUsers.remove(userId);
                mCeUnlockedUsers.remove(userId);
            }
        } catch (Exception e) {
            Slog.wtf(TAG, e);
@@ -3258,7 +3260,7 @@ class StorageManagerService extends IStorageManager.Stub
            mVold.unlockUserKey(userId, serialNumber, HexDump.toHexString(secret));
        }
        synchronized (mLock) {
            mLocalUnlockedUsers.append(userId);
            mCeUnlockedUsers.append(userId);
        }
    }

@@ -3287,14 +3289,14 @@ class StorageManagerService extends IStorageManager.Stub
        }

        synchronized (mLock) {
            mLocalUnlockedUsers.remove(userId);
            mCeUnlockedUsers.remove(userId);
        }
    }

    @Override
    public boolean isUserKeyUnlocked(int userId) {
        synchronized (mLock) {
            return mLocalUnlockedUsers.contains(userId);
            return mCeUnlockedUsers.contains(userId);
        }
    }

@@ -4678,7 +4680,7 @@ class StorageManagerService extends IStorageManager.Stub
            }

            pw.println();
            pw.println("Local unlocked users: " + mLocalUnlockedUsers);
            pw.println("CE unlocked users: " + mCeUnlockedUsers);
            pw.println("System unlocked users: " + Arrays.toString(mSystemUnlockedUsers));
        }