Merge "New API: UserManager.isUserForeground()." into sc-dev

This commit is contained in:
TreeHugger Robot
2021-02-17 20:27:56 +00:00
committed by Android (Google) Code Review
4 changed files with 23 additions and 0 deletions

View File

@@ -31638,6 +31638,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();

View File

@@ -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);

View File

@@ -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>

View File

@@ -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)) {