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

Commit 171daff3 authored by Eric Biggers's avatar Eric Biggers Committed by Automerger Merge Worker
Browse files

Merge "StorageManagerService: rename mLocalUnlockedUsers to mCeUnlockedUsers"...

Merge "StorageManagerService: rename mLocalUnlockedUsers to mCeUnlockedUsers" into main am: 5d339d0a am: feff9b27 am: c47b8052

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2786390



Change-Id: I2616137b3e0427adef983957686d01db6419440c
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents b017eaf4 c47b8052
Loading
Loading
Loading
Loading
+27 −25
Original line number Original line Diff line number Diff line
@@ -386,15 +386,14 @@ class StorageManagerService extends IStorageManager.Stub
    private final Object mLock = LockGuard.installNewLock(LockGuard.INDEX_STORAGE);
    private final Object mLock = LockGuard.installNewLock(LockGuard.INDEX_STORAGE);


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


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

    /**
     * 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")
    @GuardedBy("mLock")
    private int[] mSystemUnlockedUsers = EmptyArray.INT;
    private int[] mSystemUnlockedUsers = EmptyArray.INT;


@@ -1144,11 +1147,10 @@ class StorageManagerService extends IStorageManager.Stub
        }
        }
    }
    }


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


        try {
        try {
            mVold.createUserKey(userId, serialNumber, ephemeral);
            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) {
            synchronized (mLock) {
                mLocalUnlockedUsers.append(userId);
                mCeUnlockedUsers.append(userId);
            }
            }
        } catch (Exception e) {
        } catch (Exception e) {
            Slog.wtf(TAG, e);
            Slog.wtf(TAG, e);
@@ -3252,9 +3254,9 @@ class StorageManagerService extends IStorageManager.Stub


        try {
        try {
            mVold.destroyUserKey(userId);
            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) {
            synchronized (mLock) {
                mLocalUnlockedUsers.remove(userId);
                mCeUnlockedUsers.remove(userId);
            }
            }
        } catch (Exception e) {
        } catch (Exception e) {
            Slog.wtf(TAG, e);
            Slog.wtf(TAG, e);
@@ -3281,7 +3283,7 @@ class StorageManagerService extends IStorageManager.Stub
            mVold.unlockUserKey(userId, serialNumber, HexDump.toHexString(secret));
            mVold.unlockUserKey(userId, serialNumber, HexDump.toHexString(secret));
        }
        }
        synchronized (mLock) {
        synchronized (mLock) {
            mLocalUnlockedUsers.append(userId);
            mCeUnlockedUsers.append(userId);
        }
        }
    }
    }


@@ -3310,14 +3312,14 @@ class StorageManagerService extends IStorageManager.Stub
        }
        }


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


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


@@ -4716,7 +4718,7 @@ class StorageManagerService extends IStorageManager.Stub
            }
            }


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