Loading core/java/android/os/IUserManager.aidl +1 −1 Original line number Diff line number Diff line Loading @@ -113,7 +113,7 @@ interface IUserManager { boolean hasBadge(int userId); boolean isUserUnlocked(int userId); boolean isUserRunning(int userId); boolean isUserForeground(); boolean isUserForeground(int userId); boolean isUserNameSet(int userId); boolean hasRestrictedProfiles(); boolean requestQuietModeEnabled(String callingPackage, boolean enableQuietMode, int userId, in IntentSender target, int flags); Loading core/java/android/os/UserManager.java +4 −3 Original line number Diff line number Diff line Loading @@ -2316,13 +2316,14 @@ public class UserManager { } /** * Checks if the calling user is running on foreground. * Checks if the context user is running in the foreground. * * @return whether the calling user is running on foreground. * @return whether the context user is running in the foreground. */ @UserHandleAware public boolean isUserForeground() { try { return mService.isUserForeground(); return mService.isUserForeground(mUserId); } catch (RemoteException re) { throw re.rethrowFromSystemServer(); } Loading services/core/java/com/android/server/pm/UserManagerService.java +10 −3 Original line number Diff line number Diff line Loading @@ -1526,11 +1526,18 @@ public class UserManagerService extends IUserManager.Stub { } @Override public boolean isUserForeground() { int callingUserId = Binder.getCallingUserHandle().getIdentifier(); public boolean isUserForeground(@UserIdInt int userId) { final int callingUserId = UserHandle.getCallingUserId(); if (callingUserId != userId && !hasManageUsersOrPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)) { throw new SecurityException("Caller from user " + callingUserId + " needs MANAGE_USERS " + "or INTERACT_ACROSS_USERS permission to check if another user (" + userId + ") is running in the foreground"); } int currentUser = Binder.withCleanCallingIdentity(() -> ActivityManager.getCurrentUser()); // TODO(b/179163496): should return true for profile users of the current user as well return currentUser == callingUserId; return currentUser == userId; } @Override Loading Loading
core/java/android/os/IUserManager.aidl +1 −1 Original line number Diff line number Diff line Loading @@ -113,7 +113,7 @@ interface IUserManager { boolean hasBadge(int userId); boolean isUserUnlocked(int userId); boolean isUserRunning(int userId); boolean isUserForeground(); boolean isUserForeground(int userId); boolean isUserNameSet(int userId); boolean hasRestrictedProfiles(); boolean requestQuietModeEnabled(String callingPackage, boolean enableQuietMode, int userId, in IntentSender target, int flags); Loading
core/java/android/os/UserManager.java +4 −3 Original line number Diff line number Diff line Loading @@ -2316,13 +2316,14 @@ public class UserManager { } /** * Checks if the calling user is running on foreground. * Checks if the context user is running in the foreground. * * @return whether the calling user is running on foreground. * @return whether the context user is running in the foreground. */ @UserHandleAware public boolean isUserForeground() { try { return mService.isUserForeground(); return mService.isUserForeground(mUserId); } catch (RemoteException re) { throw re.rethrowFromSystemServer(); } Loading
services/core/java/com/android/server/pm/UserManagerService.java +10 −3 Original line number Diff line number Diff line Loading @@ -1526,11 +1526,18 @@ public class UserManagerService extends IUserManager.Stub { } @Override public boolean isUserForeground() { int callingUserId = Binder.getCallingUserHandle().getIdentifier(); public boolean isUserForeground(@UserIdInt int userId) { final int callingUserId = UserHandle.getCallingUserId(); if (callingUserId != userId && !hasManageUsersOrPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)) { throw new SecurityException("Caller from user " + callingUserId + " needs MANAGE_USERS " + "or INTERACT_ACROSS_USERS permission to check if another user (" + userId + ") is running in the foreground"); } int currentUser = Binder.withCleanCallingIdentity(() -> ActivityManager.getCurrentUser()); // TODO(b/179163496): should return true for profile users of the current user as well return currentUser == callingUserId; return currentUser == userId; } @Override Loading