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

Commit 0468ee9e authored by Fyodor Kupolov's avatar Fyodor Kupolov
Browse files

In the stopping/shutdown state return unlock state of the user key

UserManager.isUserUnlocked should return true when user is stopping,
but encryption key is unlocked. Otherwise it causes issues in
non-cryptoaware apps that can can run while user is in STATE_STOPPING

Test: create/start/remove managed profiles in a loop and verify there
      are no app or system crashes
Bug: 38212686

Change-Id: I47aa520269aafe3d3c967b6841ff46e765c446bd
parent 1b581e46
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -1477,6 +1477,10 @@ final class UserController {
                case UserState.STATE_RUNNING_UNLOCKING:
                case UserState.STATE_RUNNING_UNLOCKED:
                    return true;
                // In the stopping/shutdown state return unlock state of the user key
                case UserState.STATE_STOPPING:
                case UserState.STATE_SHUTDOWN:
                    return StorageManager.isUserKeyUnlocked(userId);
                default:
                    return false;
            }
@@ -1485,6 +1489,10 @@ final class UserController {
            switch (state.state) {
                case UserState.STATE_RUNNING_UNLOCKED:
                    return true;
                // In the stopping/shutdown state return unlock state of the user key
                case UserState.STATE_STOPPING:
                case UserState.STATE_SHUTDOWN:
                    return StorageManager.isUserKeyUnlocked(userId);
                default:
                    return false;
            }
+16 −6
Original line number Diff line number Diff line
@@ -949,7 +949,7 @@ public class UserManagerService extends IUserManager.Stub {
    @Override
    public boolean isUserUnlocked(int userId) {
        checkManageOrInteractPermIfCallerInOtherProfileGroup(userId, "isUserUnlocked");
        return mLocalService.isUserUnlockingOrUnlocked(userId);
        return mLocalService.isUserUnlocked(userId);
    }

    @Override
@@ -3692,19 +3692,29 @@ public class UserManagerService extends IUserManager.Stub {

        @Override
        public boolean isUserUnlockingOrUnlocked(int userId) {
            int state;
            synchronized (mUserStates) {
                int state = mUserStates.get(userId, -1);
                state = mUserStates.get(userId, -1);
            }
            // Special case, in the stopping/shutdown state user key can still be unlocked
            if (state == UserState.STATE_STOPPING || state == UserState.STATE_SHUTDOWN) {
                return StorageManager.isUserKeyUnlocked(userId);
            }
            return (state == UserState.STATE_RUNNING_UNLOCKING)
                    || (state == UserState.STATE_RUNNING_UNLOCKED);
        }
        }

        @Override
        public boolean isUserUnlocked(int userId) {
            int state;
            synchronized (mUserStates) {
                int state = mUserStates.get(userId, -1);
                return state == UserState.STATE_RUNNING_UNLOCKED;
                state = mUserStates.get(userId, -1);
            }
            // Special case, in the stopping/shutdown state user key can still be unlocked
            if (state == UserState.STATE_STOPPING || state == UserState.STATE_SHUTDOWN) {
                return StorageManager.isUserKeyUnlocked(userId);
            }
            return state == UserState.STATE_RUNNING_UNLOCKED;
        }
    }