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

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

Changes on am / cmd user for ITestDevice integration

- Added (optional) listener to startUserInBackgroundVisibleOnDisplay
- Added cmd user is-visible-background-users-supported

It will used by shell command and ITestDevice (which uses the cmd).

Test: adb shell cmd user is-visible-background-users-supported
Test: adb shell am start-user --display 2 -w 10
Test: atest -it com.android.server.am.ActivityManagerServiceTest UserControllerTest

Bug: 266851112

Change-Id: I04648a0ba91ec883273cf519c77b081eabfd5187
parent 541bb486
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -4417,7 +4417,8 @@ public class ActivityManager {
                    "device does not support users on secondary displays");
        }
        try {
            return getService().startUserInBackgroundVisibleOnDisplay(userId, displayId);
            return getService().startUserInBackgroundVisibleOnDisplay(userId, displayId,
                    /* unlockProgressListener= */ null);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
+1 −1
Original line number Diff line number Diff line
@@ -803,7 +803,7 @@ interface IActivityManager {
     */
    @JavaPassthrough(annotation=
            "@android.annotation.RequiresPermission(anyOf = {android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.CREATE_USERS}, conditional = true)")
    boolean startUserInBackgroundVisibleOnDisplay(int userid, int displayId);
    boolean startUserInBackgroundVisibleOnDisplay(int userid, int displayId, IProgressListener unlockProgressListener);

    /**
     * Similar to {@link #startProfile(int userId)}, but with a listener to report user unlock
+9 −6
Original line number Diff line number Diff line
@@ -16629,7 +16629,8 @@ public class ActivityManagerService extends IActivityManager.Stub
    }
    @Override
    public boolean startUserInBackgroundVisibleOnDisplay(int userId, int displayId) {
    public boolean startUserInBackgroundVisibleOnDisplay(int userId, int displayId,
            @Nullable IProgressListener unlockListener) {
        int[] displayIds = getDisplayIdsForStartingVisibleBackgroundUsers();
        boolean validDisplay = false;
        if (displayIds != null) {
@@ -16646,11 +16647,11 @@ public class ActivityManagerService extends IActivityManager.Stub
        }
        if (DEBUG_MU) {
            Slogf.d(TAG_MU, "Calling startUserOnSecondaryDisplay(%d, %d) using injector %s", userId,
                    displayId, mInjector);
            Slogf.d(TAG_MU, "Calling startUserOnSecondaryDisplay(%d, %d, %s) using injector %s",
                    userId, displayId, unlockListener, mInjector);
        }
        // Permission check done inside UserController.
        return mInjector.startUserInBackgroundVisibleOnDisplay(userId, displayId);
        return mInjector.startUserInBackgroundVisibleOnDisplay(userId, displayId, unlockListener);
    }
    @Override
@@ -19031,8 +19032,10 @@ public class ActivityManagerService extends IActivityManager.Stub
        /**
         * Called by {@code AMS.startUserInBackgroundVisibleOnDisplay()}.
         */
        public boolean startUserInBackgroundVisibleOnDisplay(int userId, int displayId) {
            return mUserController.startUserVisibleOnDisplay(userId, displayId);
        public boolean startUserInBackgroundVisibleOnDisplay(int userId, int displayId,
                @Nullable IProgressListener unlockProgressListener) {
            return mUserController.startUserVisibleOnDisplay(userId, displayId,
                    unlockProgressListener);
        }
        /**
+5 −3
Original line number Diff line number Diff line
@@ -2243,9 +2243,10 @@ final class ActivityManagerShellCommand extends ShellCommand {
                    pw.println("Not supported");
                    return -1;
                }
                Slogf.d(TAG, "calling startUserInBackgroundVisibleOnDisplay(%d,%d)", userId,
                        displayId);
                success = mInterface.startUserInBackgroundVisibleOnDisplay(userId, displayId);
                Slogf.d(TAG, "calling startUserInBackgroundVisibleOnDisplay(%d, %d, %s)", userId,
                        displayId, waiter);
                success = mInterface.startUserInBackgroundVisibleOnDisplay(userId, displayId,
                        waiter);
                displaySuffix = " on display " + displayId;
            }
            if (wait && success) {
@@ -3849,6 +3850,7 @@ final class ActivityManagerShellCommand extends ShellCommand {

    int runListDisplaysForStartingUsers(PrintWriter pw) throws RemoteException {
        int[] displayIds = mInterface.getDisplayIdsForStartingVisibleBackgroundUsers();
        // NOTE: format below cannot be changed as it's used by ITestDevice
        pw.println(displayIds == null || displayIds.length == 0
                ? "none"
                : Arrays.toString(displayIds));
+4 −2
Original line number Diff line number Diff line
@@ -1560,16 +1560,18 @@ class UserController implements Handler.Callback {
     *
     * @param userId user to be started
     * @param displayId display where the user will be visible
     * @param unlockListener Listener to be informed when the user has started and unlocked.
     *
     * @return whether the user was started
     */
    boolean startUserVisibleOnDisplay(@UserIdInt int userId, int displayId) {
    boolean startUserVisibleOnDisplay(@UserIdInt int userId, int displayId,
            @Nullable IProgressListener unlockListener) {
        checkCallingHasOneOfThosePermissions("startUserOnDisplay",
                MANAGE_USERS, INTERACT_ACROSS_USERS);

        try {
            return startUserNoChecks(userId, displayId, USER_START_MODE_BACKGROUND_VISIBLE,
                    /* unlockListener= */ null);
                    unlockListener);
        } catch (RuntimeException e) {
            Slogf.e(TAG, "startUserOnSecondaryDisplay(%d, %d) failed: %s", userId, displayId, e);
            return false;
Loading