Merge "Fixed UserVisibilityMediator so it doesn't suppoort invalid modes." into udc-dev am: c221811a71 am: 39753a4bf4
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/21709724 Change-Id: Ide622ff08dae97bc2c1244695d2abf4f3706cca3 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -2772,7 +2772,8 @@
|
||||
|
||||
<!-- Whether the device allows users to start in background visible on the default display.
|
||||
Should be false for most devices, except passenger-only automotive build (i.e., when
|
||||
Android runs in a separate system in the back seat to manage the passenger displays) -->
|
||||
Android runs in a separate system in the back seat to manage the passenger displays).
|
||||
When set to true, config_multiuserVisibleBackgroundUsers must also be true. -->
|
||||
<bool name="config_multiuserVisibleBackgroundUsersOnDefaultDisplay">false</bool>
|
||||
|
||||
<!-- Whether to automatically switch to the designated Dock User (the user chosen for
|
||||
|
||||
@@ -108,7 +108,7 @@ public final class UserVisibilityMediator implements Dumpable {
|
||||
private final Object mLock = new Object();
|
||||
|
||||
private final boolean mVisibleBackgroundUsersEnabled;
|
||||
private final boolean mVisibleBackgroundUserOnDefaultDisplayAllowed;
|
||||
private final boolean mVisibleBackgroundUserOnDefaultDisplayEnabled;
|
||||
|
||||
@UserIdInt
|
||||
@GuardedBy("mLock")
|
||||
@@ -168,11 +168,17 @@ public final class UserVisibilityMediator implements Dumpable {
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
UserVisibilityMediator(boolean backgroundUsersOnDisplaysEnabled,
|
||||
boolean visibleBackgroundUserOnDefaultDisplayAllowed, Handler handler) {
|
||||
mVisibleBackgroundUsersEnabled = backgroundUsersOnDisplaysEnabled;
|
||||
mVisibleBackgroundUserOnDefaultDisplayAllowed =
|
||||
visibleBackgroundUserOnDefaultDisplayAllowed;
|
||||
UserVisibilityMediator(boolean visibleBackgroundUsersOnDisplaysEnabled,
|
||||
boolean visibleBackgroundUserOnDefaultDisplayEnabled, Handler handler) {
|
||||
mVisibleBackgroundUsersEnabled = visibleBackgroundUsersOnDisplaysEnabled;
|
||||
if (visibleBackgroundUserOnDefaultDisplayEnabled
|
||||
&& !visibleBackgroundUsersOnDisplaysEnabled) {
|
||||
throw new IllegalArgumentException("Cannot have "
|
||||
+ "visibleBackgroundUserOnDefaultDisplayEnabled without "
|
||||
+ "visibleBackgroundUsersOnDisplaysEnabled");
|
||||
}
|
||||
mVisibleBackgroundUserOnDefaultDisplayEnabled =
|
||||
visibleBackgroundUserOnDefaultDisplayEnabled;
|
||||
if (mVisibleBackgroundUsersEnabled) {
|
||||
mUsersAssignedToDisplayOnStart = new SparseIntArray();
|
||||
mExtraDisplaysAssignedToUsers = new SparseIntArray();
|
||||
@@ -318,14 +324,14 @@ public final class UserVisibilityMediator implements Dumpable {
|
||||
|
||||
boolean visibleBackground = userStartMode == USER_START_MODE_BACKGROUND_VISIBLE;
|
||||
if (displayId == DEFAULT_DISPLAY && visibleBackground) {
|
||||
if (mVisibleBackgroundUserOnDefaultDisplayAllowed && isCurrentUserLocked(userId)) {
|
||||
if (mVisibleBackgroundUserOnDefaultDisplayEnabled && isCurrentUserLocked(userId)) {
|
||||
// Shouldn't happen - UserController returns before calling this method
|
||||
Slogf.wtf(TAG, "trying to start current user (%d) visible in background on default"
|
||||
+ " display", userId);
|
||||
return USER_ASSIGNMENT_RESULT_SUCCESS_ALREADY_VISIBLE;
|
||||
|
||||
}
|
||||
if (!mVisibleBackgroundUserOnDefaultDisplayAllowed
|
||||
if (!mVisibleBackgroundUserOnDefaultDisplayEnabled
|
||||
&& !isProfile(userId, profileGroupId)) {
|
||||
Slogf.wtf(TAG, "cannot start full user (%d) visible on default display", userId);
|
||||
return USER_ASSIGNMENT_RESULT_FAILURE;
|
||||
@@ -383,7 +389,7 @@ public final class UserVisibilityMediator implements Dumpable {
|
||||
}
|
||||
|
||||
return foreground || displayId != DEFAULT_DISPLAY
|
||||
|| (visibleBackground && mVisibleBackgroundUserOnDefaultDisplayAllowed)
|
||||
|| (visibleBackground && mVisibleBackgroundUserOnDefaultDisplayEnabled)
|
||||
? USER_ASSIGNMENT_RESULT_SUCCESS_VISIBLE
|
||||
: USER_ASSIGNMENT_RESULT_SUCCESS_INVISIBLE;
|
||||
}
|
||||
@@ -394,7 +400,7 @@ public final class UserVisibilityMediator implements Dumpable {
|
||||
@UserIdInt int profileGroupId, @UserStartMode int userStartMode, int displayId) {
|
||||
if (displayId == DEFAULT_DISPLAY) {
|
||||
boolean mappingNeeded = false;
|
||||
if (mVisibleBackgroundUserOnDefaultDisplayAllowed
|
||||
if (mVisibleBackgroundUserOnDefaultDisplayEnabled
|
||||
&& userStartMode == USER_START_MODE_BACKGROUND_VISIBLE) {
|
||||
int userStartedOnDefaultDisplay = getUserStartedOnDisplay(DEFAULT_DISPLAY);
|
||||
if (userStartedOnDefaultDisplay != USER_NULL
|
||||
@@ -752,7 +758,7 @@ public final class UserVisibilityMediator implements Dumpable {
|
||||
*/
|
||||
public int getDisplayAssignedToUser(@UserIdInt int userId) {
|
||||
if (isCurrentUserOrRunningProfileOfCurrentUser(userId)) {
|
||||
if (mVisibleBackgroundUserOnDefaultDisplayAllowed) {
|
||||
if (mVisibleBackgroundUserOnDefaultDisplayEnabled) {
|
||||
// When device supports visible bg users on default display, the default display is
|
||||
// assigned to the current user, unless a user is started visible on it
|
||||
int userStartedOnDefaultDisplay;
|
||||
@@ -801,7 +807,7 @@ public final class UserVisibilityMediator implements Dumpable {
|
||||
private @UserIdInt int getUserAssignedToDisplay(@UserIdInt int displayId,
|
||||
boolean returnCurrentUserByDefault) {
|
||||
if (returnCurrentUserByDefault
|
||||
&& ((displayId == DEFAULT_DISPLAY && !mVisibleBackgroundUserOnDefaultDisplayAllowed
|
||||
&& ((displayId == DEFAULT_DISPLAY && !mVisibleBackgroundUserOnDefaultDisplayEnabled
|
||||
|| !mVisibleBackgroundUsersEnabled))) {
|
||||
return getCurrentUserId();
|
||||
}
|
||||
@@ -961,8 +967,8 @@ public final class UserVisibilityMediator implements Dumpable {
|
||||
ipw.print("Supports visible background users on displays: ");
|
||||
ipw.println(mVisibleBackgroundUsersEnabled);
|
||||
|
||||
ipw.print("Allows visible background users on default display: ");
|
||||
ipw.println(mVisibleBackgroundUserOnDefaultDisplayAllowed);
|
||||
ipw.print("Supports visible background users on default display: ");
|
||||
ipw.println(mVisibleBackgroundUserOnDefaultDisplayEnabled);
|
||||
|
||||
dumpSparseIntArray(ipw, mUsersAssignedToDisplayOnStart, "user / display", "u", "d");
|
||||
dumpSparseIntArray(ipw, mExtraDisplaysAssignedToUsers, "extra display / user",
|
||||
|
||||
@@ -138,6 +138,13 @@ abstract class UserVisibilityMediatorTestCase extends ExpectableTestCase {
|
||||
mDumpableDumperRule.addDumpable(mMediator);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidMode() {
|
||||
assertThrows(IllegalArgumentException.class, () -> new UserVisibilityMediator(
|
||||
/* visibleBackgroundUsersOnDisplaysEnabled= */ false,
|
||||
/* visibleBackgroundUserOnDefaultDisplayAllowed= */ true, mHandler));
|
||||
}
|
||||
|
||||
@Test
|
||||
public final void testAssignUserToDisplayOnStart_invalidUserIds() {
|
||||
assertThrows(IllegalArgumentException.class, () -> mMediator
|
||||
|
||||
Reference in New Issue
Block a user