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

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

Improvements on "start bg user on secondary display":

- Adds hidden API on ActivityManager
- Checks if feature is supported
- Adds shell command to check if user is visible
- Includes (visible) on 'cmd user list -v'

Test: atest CtsMultiUserTestCases:android.multiuser.cts.UserManagerTest#testIsUserVisible_backgroundUserOnSecondaryDisplay
Test: m update-api
Test: adb shell cmd user is-user-visible --display 0 cur

Bug: 239982558

Change-Id: Ie7fe8c832ef2a3ffe4869a67fd35a0da363d0039
parent 4264560e
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -131,6 +131,7 @@ package android.app {
    method public static void resumeAppSwitches() throws android.os.RemoteException;
    method @RequiresPermission(android.Manifest.permission.CHANGE_CONFIGURATION) public void scheduleApplicationInfoChanged(java.util.List<java.lang.String>, int);
    method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.INTERACT_ACROSS_USERS}) public void setStopUserOnSwitch(int);
    method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.CREATE_USERS}) public boolean startUserInBackgroundOnSecondaryDisplay(int, int);
    method @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL) public boolean stopUser(int, boolean);
    method @RequiresPermission(android.Manifest.permission.CHANGE_CONFIGURATION) public boolean updateMccMncConfiguration(@NonNull String, @NonNull String);
    method @RequiresPermission(android.Manifest.permission.DUMP) public void waitForBroadcastIdle();
@@ -1874,6 +1875,7 @@ package android.os {
    method @NonNull @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.CREATE_USERS}) public java.util.List<android.content.pm.UserInfo> getUsers(boolean, boolean, boolean);
    method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.CREATE_USERS}) public boolean hasBaseUserRestriction(@NonNull String, @NonNull android.os.UserHandle);
    method public static boolean isSplitSystemUser();
    method public static boolean isUsersOnSecondaryDisplaysEnabled();
    method @NonNull @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.CREATE_USERS}) public android.content.pm.UserInfo preCreateUser(@NonNull String) throws android.os.UserManager.UserOperationException;
  }

+32 −3
Original line number Diff line number Diff line
@@ -4336,12 +4336,41 @@ public class ActivityManager {
    @RequiresPermission(anyOf = {android.Manifest.permission.MANAGE_USERS,
            android.Manifest.permission.CREATE_USERS})
    public boolean switchUser(@NonNull UserHandle user) {
        if (user == null) {
            throw new IllegalArgumentException("UserHandle cannot be null.");
        }
        Preconditions.checkNotNull(user, "UserHandle cannot be null.");

        return switchUser(user.getIdentifier());
    }

    /**
     * Starts the given user in background and associate the user with the given display.
     *
     * <p>This method will allow the user to launch activities on that display, and it's typically
     * used only on automotive builds when the vehicle has multiple displays (you can verify if it's
     * supported by calling {@link UserManager#isBackgroundUsersOnSecondaryDisplaysSupported()}).
     *
     * @return whether the user was started.
     *
     * @throws UnsupportedOperationException if the device does not support background users on
     * secondary displays.
     * @throws IllegalArgumentException if the display does not exist.
     * @throws IllegalStateException if the user cannot be started on that display (for example, if
     * there's already a user using that display or if the user is already associated with other
     * display).
     *
     * @hide
     */
    @TestApi
    @RequiresPermission(anyOf = {android.Manifest.permission.MANAGE_USERS,
            android.Manifest.permission.CREATE_USERS})
    public boolean startUserInBackgroundOnSecondaryDisplay(@UserIdInt int userId,
            int displayId) {
        try {
            return getService().startUserInBackgroundOnSecondaryDisplay(userId, displayId);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Gets the message that is shown when a user is switched from.
     *
+1 −1
Original line number Diff line number Diff line
@@ -769,6 +769,6 @@ interface IActivityManager {
     *
     * <p>Typically used only by automotive builds when the vehicle has multiple displays.
     */
    boolean startUserInBackgroundOnSecondaryDisplay(int userid, int displayId, IProgressListener unlockProgressListener);
    boolean startUserInBackgroundOnSecondaryDisplay(int userid, int displayId);

}
+1 −0
Original line number Diff line number Diff line
@@ -2840,6 +2840,7 @@ public class UserManager {
    /**
     * @hide
     */
    @TestApi
    public static boolean isUsersOnSecondaryDisplaysEnabled() {
        return SystemProperties.getBoolean("fw.users_on_secondary_displays",
                Resources.getSystem()
+3 −3
Original line number Diff line number Diff line
@@ -16197,10 +16197,10 @@ public class ActivityManagerService extends IActivityManager.Stub
    }
    @Override
    public boolean startUserInBackgroundOnSecondaryDisplay(int userId, int displayId,
            @Nullable IProgressListener unlockListener) {
    public boolean startUserInBackgroundOnSecondaryDisplay(int userId, int displayId) {
        // Permission check done inside UserController.
        return mUserController.startUserOnSecondaryDisplay(userId, displayId, unlockListener);
        return mUserController.startUserOnSecondaryDisplay(userId, displayId,
                /* unlockListener= */ null);
    }
    /**
Loading