diff --git a/services/core/java/com/android/server/pm/UserManagerService.java b/services/core/java/com/android/server/pm/UserManagerService.java index 657707400da63..21191919c8e09 100644 --- a/services/core/java/com/android/server/pm/UserManagerService.java +++ b/services/core/java/com/android/server/pm/UserManagerService.java @@ -5519,6 +5519,13 @@ public class UserManagerService extends IUserManager.Stub { private void removeUserState(final @UserIdInt int userId) { Slog.i(LOG_TAG, "Removing user state of user " + userId); + + // Cleanup lock settings. This must happen before destroyUserKey(), since the user's DE + // storage must still be accessible for the lock settings state to be properly cleaned up. + mLockPatternUtils.removeUser(userId); + + // Evict and destroy the user's CE and DE encryption keys. At this point, the user's CE and + // DE storage is made inaccessible, except to delete its contents. try { mContext.getSystemService(StorageManager.class).destroyUserKey(userId); } catch (IllegalStateException e) { @@ -5526,9 +5533,6 @@ public class UserManagerService extends IUserManager.Stub { Slog.i(LOG_TAG, "Destroying key for user " + userId + " failed, continuing anyway", e); } - // Cleanup lock settings - mLockPatternUtils.removeUser(userId); - // Cleanup package manager settings mPm.cleanUpUser(this, userId);