Merge "Improvements in UMS.isUserRunning()"

This commit is contained in:
Nikhil Kumar
2022-09-13 09:39:12 +00:00
committed by Android (Google) Code Review
3 changed files with 15 additions and 9 deletions

View File

@@ -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<>();

View File

@@ -6578,9 +6578,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

View File

@@ -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