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

Commit 060f8f38 authored by Nikhil Kumar's avatar Nikhil Kumar
Browse files

Improvements in UMS.isUserRunning()

Modified isUserRunning() to return false when user is in state of STOPPING or SHUTDOWN even if the user is present in mUserStates.

Defined a new STATE_NONE state in UserState to discard the use of "-1" where we want to return an unknown state when user is no more available.

Test: atest FrameworksMockingServicesTests:com.android.server.pm.UserManagerServiceTest
Test: atest CtsMultiUserTestCases:android.multiuser.cts.UserManagerTest

Bug: 244798930
Change-Id: If5b9098f88a1f58cc3f74d0067cbcce6aa1062a6
parent 636c721c
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -35,18 +35,20 @@ import java.util.ArrayList;
public final class UserState {
    private static final String TAG = TAG_WITH_CLASS_NAME ? "UserState" : TAG_AM;

    // user doesn't exist.
    public static final int STATE_NONE = -1;
    // User is first coming up.
    public final static int STATE_BOOTING = 0;
    public static final int STATE_BOOTING = 0;
    // User is in the locked state.
    public final static int STATE_RUNNING_LOCKED = 1;
    public static final int STATE_RUNNING_LOCKED = 1;
    // User is in the unlocking state.
    public final static int STATE_RUNNING_UNLOCKING = 2;
    public static final int STATE_RUNNING_UNLOCKING = 2;
    // User is in the running state.
    public final static int STATE_RUNNING_UNLOCKED = 3;
    public static final int STATE_RUNNING_UNLOCKED = 3;
    // User is in the initial process of being stopped.
    public final static int STATE_STOPPING = 4;
    public static final int STATE_STOPPING = 4;
    // User is in the final phase of stopping, sending Intent.ACTION_SHUTDOWN.
    public final static int STATE_SHUTDOWN = 5;
    public static final int STATE_SHUTDOWN = 5;

    public final UserHandle mHandle;
    public final ArrayList<IStopUserCallback> mStopCallbacks = new ArrayList<>();
+6 −1
Original line number Diff line number Diff line
@@ -6560,9 +6560,14 @@ public class UserManagerService extends IUserManager.Stub {

        @Override
        public boolean isUserRunning(@UserIdInt int userId) {
            int state;
            synchronized (mUserStates) {
                return mUserStates.get(userId, -1) >= 0;
                state =  mUserStates.get(userId, UserState.STATE_NONE);
            }

            return state != UserState.STATE_NONE
                    && state != UserState.STATE_STOPPING
                    && state != UserState.STATE_SHUTDOWN;
        }

        @Override
+1 −2
Original line number Diff line number Diff line
@@ -535,8 +535,7 @@ abstract class UserManagerServiceOrInternalTestCase extends ExtendedMockitoTestC
    }

    protected final void stopDefaultProfile() {
        // TODO(b/244798930): should set it to STATE_STOPPING or STATE_SHUTDOWN instead
        removeUserState(PROFILE_USER_ID);
        setUserState(PROFILE_USER_ID, UserState.STATE_STOPPING);
    }

    // NOTE: should only called by tests that indirectly needs to check user assignments (like