Loading core/java/android/os/UserManager.java +1 −1 Original line number Diff line number Diff line Loading @@ -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. Loading services/core/java/com/android/server/pm/UserManagerService.java +18 −4 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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! Loading @@ -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"); Loading Loading
core/java/android/os/UserManager.java +1 −1 Original line number Diff line number Diff line Loading @@ -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. Loading
services/core/java/com/android/server/pm/UserManagerService.java +18 −4 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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! Loading @@ -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"); Loading