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