Merge "Add a guard on UserController to avoid user switches when not ready." into rvc-dev

This commit is contained in:
TreeHugger Robot
2020-06-22 19:19:20 +00:00
committed by Android (Google) Code Review

View File

@@ -348,6 +348,17 @@ class UserController implements Handler.Callback {
@GuardedBy("mUserIdToUserJourneyMap")
private final SparseArray<UserJourneySession> mUserIdToUserJourneyMap = new SparseArray<>();
/**
* Sets on {@link #setInitialConfig(boolean, int, boolean)}, which is called by
* {@code ActivityManager} when the system is started.
*
* <p>It's useful to ignore external operations (i.e., originated outside {@code system_server},
* like from {@code adb shell am switch-user})) that could happen before such call is made and
* the system is ready.
*/
@GuardedBy("mLock")
private boolean mInitialized;
UserController(ActivityManagerService service) {
this(new Injector(service));
}
@@ -372,6 +383,7 @@ class UserController implements Handler.Callback {
mUserSwitchUiEnabled = userSwitchUiEnabled;
mMaxRunningUsers = maxRunningUsers;
mDelayUserDataLocking = delayUserDataLocking;
mInitialized = true;
}
}
@@ -1587,6 +1599,11 @@ class UserController implements Handler.Callback {
}
boolean userSwitchUiEnabled;
synchronized (mLock) {
if (!mInitialized) {
Slog.e(TAG, "Cannot switch to User #" + targetUserId
+ ": UserController not ready yet");
return false;
}
mTargetUserId = targetUserId;
userSwitchUiEnabled = mUserSwitchUiEnabled;
}
@@ -2422,6 +2439,7 @@ class UserController implements Handler.Callback {
pw.println(" mDelayUserDataLocking:" + mDelayUserDataLocking);
pw.println(" mMaxRunningUsers:" + mMaxRunningUsers);
pw.println(" mUserSwitchUiEnabled:" + mUserSwitchUiEnabled);
pw.println(" mInitialized:" + mInitialized);
}
}