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

Commit 0d831306 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

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

parents e89b53ff 69e1b3a0
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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();
+1 −0
Original line number Diff line number Diff line
@@ -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);
+13 −0
Original line number Diff line number Diff line
@@ -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>
+8 −0
Original line number Diff line number Diff line
@@ -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)) {