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

Commit 7cb8753c authored by Adam Bookatz's avatar Adam Bookatz Committed by Android (Google) Code Review
Browse files

Merge "Update documentation for previous foreground user" into main

parents afc06020 7ce8fc0d
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -5212,7 +5212,7 @@ public class UserManager {
     * including profiles.
     *
     * <p>Returns {@code null} if there is no previous user, for example if there
     * is only one full user (i.e. only one user which is not a profile) on the device.
     * is only one user capable of being in the foreground on the device.
     *
     * <p>This method may be used for example to find the user to switch back to if the
     * current user is removed, or if creating a new user is aborted.
+18 −4
Original line number Diff line number Diff line
@@ -455,7 +455,12 @@ public class UserManagerService extends IUserManager.Stub {
        /** Elapsed realtime since boot when the user was unlocked. */
        long unlockRealtime;

        /** Wall clock time in millis when the user last entered the foreground. */
        /**
         * Wall clock time in millis when the user last entered the foreground.
         *
         * Applicable for any user that can be switched-to;
         * will be 0 otherwise (i.e. for profiles and a non-interactive headless system user).
         */
        long mLastEnteredForegroundTimeMillis;

        private long mLastRequestQuietModeEnabledMillis;
@@ -1499,19 +1504,22 @@ public class UserManagerService extends IUserManager.Stub {
        }
    }

    /**
     * Returns the previous foreground user, or if there isn't one, the first switchable user.
     * The user need not be a full user; the HSU counts if it is switchable.
     */
    private @UserIdInt int getPreviousOrFirstSwitchableUser()
            throws UserManager.CheckedUserOperationException {
        // Return the previous foreground user, if there is one.
        final int previousUser = getPreviousUserToEnterForeground();
        if (previousUser != UserHandle.USER_NULL) {
            Slogf.i(LOG_TAG, "Boot user is previous user %d", previousUser);
            Slogf.i(LOG_TAG, "Previous foreground user was %d", previousUser);
            return previousUser;
        }
        // No previous user. Return the first switchable user if there is one.
        final int firstSwitchableUser = getFirstSwitchableUser(false);
        if (firstSwitchableUser != UserHandle.USER_NULL) {
            Slogf.i(LOG_TAG,
                    "Boot user is first switchable user %d", firstSwitchableUser);
            Slogf.i(LOG_TAG, "No previous user. First switchable user is %d", firstSwitchableUser);
            return firstSwitchableUser;
        }
        // No switchable users found. Uh oh!
@@ -1533,6 +1541,12 @@ public class UserManagerService extends IUserManager.Stub {
       return UserHandle.USER_NULL;
   }

    /**
     * Returns the previous foreground user,
     * i.e. the user that was in the foreground (possibly even prior to a reboot) before the current
     * foreground user. The user need not be a full user; the HSU counts if it is switchable.
     * @see UserManager#getPreviousForegroundUser()
     */
    @Override
    public @CanBeNULL @UserIdInt int getPreviousUserToEnterForeground() {
        checkQueryOrCreateUsersPermission("get previous user");