New API: UserManager.isUserForeground().
Test: m update-api Test: atest android.multiuser.cts.UserManagerTest#testIsUserForeground_currentUser Bug: 173541467 Bug: 179163496 Change-Id: Id44f37c9c105b319f308c927ddefcc6671293a46
This commit is contained in:
@@ -31482,6 +31482,7 @@ package android.os {
|
||||
method public boolean isQuietModeEnabled(android.os.UserHandle);
|
||||
method public boolean isSystemUser();
|
||||
method public boolean isUserAGoat();
|
||||
method public boolean isUserForeground();
|
||||
method @RequiresPermission(anyOf={"android.permission.MANAGE_USERS", "android.permission.INTERACT_ACROSS_USERS"}, conditional=true) public boolean isUserRunning(android.os.UserHandle);
|
||||
method @RequiresPermission(anyOf={"android.permission.MANAGE_USERS", "android.permission.INTERACT_ACROSS_USERS"}, conditional=true) public boolean isUserRunningOrStopping(android.os.UserHandle);
|
||||
method public boolean isUserUnlocked();
|
||||
|
||||
@@ -113,6 +113,7 @@ interface IUserManager {
|
||||
boolean hasBadge(int userId);
|
||||
boolean isUserUnlocked(int userId);
|
||||
boolean isUserRunning(int userId);
|
||||
boolean isUserForeground();
|
||||
boolean isUserNameSet(int userId);
|
||||
boolean hasRestrictedProfiles();
|
||||
boolean requestQuietModeEnabled(String callingPackage, boolean enableQuietMode, int userId, in IntentSender target, int flags);
|
||||
|
||||
@@ -2299,6 +2299,19 @@ public class UserManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the calling user is running on foreground.
|
||||
*
|
||||
* @return whether the calling user is running on foreground.
|
||||
*/
|
||||
public boolean isUserForeground() {
|
||||
try {
|
||||
return mService.isUserForeground();
|
||||
} catch (RemoteException re) {
|
||||
throw re.rethrowFromSystemServer();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the calling user is running in an "unlocked" state.
|
||||
* <p>
|
||||
|
||||
@@ -1521,6 +1521,14 @@ public class UserManagerService extends IUserManager.Stub {
|
||||
return mLocalService.isUserRunning(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUserForeground() {
|
||||
int callingUserId = Binder.getCallingUserHandle().getIdentifier();
|
||||
int currentUser = Binder.withCleanCallingIdentity(() -> ActivityManager.getCurrentUser());
|
||||
// TODO(b/179163496): should return true for profile users of the current user as well
|
||||
return currentUser == callingUserId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUserName() {
|
||||
if (!hasManageUsersOrPermission(android.Manifest.permission.GET_ACCOUNTS_PRIVILEGED)) {
|
||||
|
||||
Reference in New Issue
Block a user