Loading services/core/java/com/android/server/StorageManagerService.java +27 −25 Original line number Diff line number Diff line Loading @@ -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) { Loading Loading @@ -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; Loading Loading @@ -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(); Loading @@ -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); } } } Loading Loading @@ -2062,7 +2064,7 @@ class StorageManagerService extends IStorageManager.Stub connectVold(); }, DateUtils.SECOND_IN_MILLIS); } else { restoreLocalUnlockedUsers(); restoreCeUnlockedUsers(); onDaemonConnected(); } } Loading Loading @@ -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); Loading @@ -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); Loading @@ -3258,7 +3260,7 @@ class StorageManagerService extends IStorageManager.Stub mVold.unlockUserKey(userId, serialNumber, HexDump.toHexString(secret)); } synchronized (mLock) { mLocalUnlockedUsers.append(userId); mCeUnlockedUsers.append(userId); } } Loading Loading @@ -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); } } Loading Loading @@ -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)); } Loading Loading
services/core/java/com/android/server/StorageManagerService.java +27 −25 Original line number Diff line number Diff line Loading @@ -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) { Loading Loading @@ -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; Loading Loading @@ -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(); Loading @@ -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); } } } Loading Loading @@ -2062,7 +2064,7 @@ class StorageManagerService extends IStorageManager.Stub connectVold(); }, DateUtils.SECOND_IN_MILLIS); } else { restoreLocalUnlockedUsers(); restoreCeUnlockedUsers(); onDaemonConnected(); } } Loading Loading @@ -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); Loading @@ -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); Loading @@ -3258,7 +3260,7 @@ class StorageManagerService extends IStorageManager.Stub mVold.unlockUserKey(userId, serialNumber, HexDump.toHexString(secret)); } synchronized (mLock) { mLocalUnlockedUsers.append(userId); mCeUnlockedUsers.append(userId); } } Loading Loading @@ -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); } } Loading Loading @@ -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)); } Loading