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

Commit e6aa1016 authored by Felipe Leme's avatar Felipe Leme
Browse files

UserVisibilityMediator refactoring, step 3.

This CL improves startUser() so it does all checks before setting the
state (atomically).

It also "fixes" 2 issues in that method:

- Return USER_ASSIGNMENT_RESULT_SUCCESS_INVISIBLE when the profile
  is started but its parent is not visible (this could happen when
  the profile is started in the background for maintenance purposes,
  like garage mode).
- Don't throw RuntimeExceptions in case of error (but rather
  USER_ASSIGNMENT_RESULT_FAILURE).

This is the last refactoring per se - further changes will either
modify the behavior of the class (for example, to allow background
users starting in the main display) or improve the test cases (for
example, to make sure subclasses of UserVisibilityMediatorTestCase
test all use case scenarios).

Test: atest FrameworksMockingServicesTests:com.android.server.pm.UserManagerServiceTest UserVisibilityMediatorMUMDTest UserVisibilityMediatorSUSDTest UserControllerTest
Test: atest CtsMultiUserTestCases:android.multiuser.cts.MultipleUsersOnMultipleDisplaysTest
Test: adb shell dumpsys user --visibility-mediator

Bug: 244644281

Change-Id: Ia09b58607f93c4dd02a7a646da9359af58e3d0e7
parent d16bc3ee
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -4398,8 +4398,6 @@ public class ActivityManager {
     *
     * @throws UnsupportedOperationException if the device does not support background users on
     * secondary displays.
     * @throws IllegalArgumentException if the display doesn't exist or is not a valid display to
     * start secondary users on.
     *
     * @hide
     */
+1 −1
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@ public abstract class UserManagerInternal {
    public static final int USER_ASSIGNMENT_RESULT_SUCCESS_INVISIBLE = 2;
    public static final int USER_ASSIGNMENT_RESULT_FAILURE = -1;

    private static final String PREFIX_USER_ASSIGNMENT_RESULT = "USER_ASSIGNMENT_RESULT";
    private static final String PREFIX_USER_ASSIGNMENT_RESULT = "USER_ASSIGNMENT_RESULT_";
    @IntDef(flag = false, prefix = {PREFIX_USER_ASSIGNMENT_RESULT}, value = {
            USER_ASSIGNMENT_RESULT_SUCCESS_VISIBLE,
            USER_ASSIGNMENT_RESULT_SUCCESS_INVISIBLE,
+1 −2
Original line number Diff line number Diff line
@@ -1644,8 +1644,7 @@ public class UserManagerService extends IUserManager.Stub {
        return isProfileUnchecked(userId);
    }

    // TODO(b/244644281): make it private once UserVisibilityMediator don't use it anymore
    boolean isProfileUnchecked(@UserIdInt int userId) {
    private boolean isProfileUnchecked(@UserIdInt int userId) {
        synchronized (mUsersLock) {
            UserInfo userInfo = getUserInfoLU(userId);
            return userInfo != null && userInfo.isProfile();
+188 −144

File changed.

Preview size limit exceeded, changes collapsed.

+63 −100

File changed.

Preview size limit exceeded, changes collapsed.

Loading