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

Commit 98a942d1 authored by Fyodor Kupolov's avatar Fyodor Kupolov Committed by Android (Google) Code Review
Browse files

Merge "Switch isUserUnlocked/isUserRunning to use UMS.mUserStates"

parents 0fb443b8 2e7e0968
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -87,4 +87,6 @@ interface IUserManager {
            in String[] disallowedPackages);
    boolean isUserUnlockingOrUnlocked(int userId);
    int getManagedProfileBadge(int userId);
    boolean isUserUnlocked(int userId);
    boolean isUserRunning(int userId);
}
+3 −5
Original line number Diff line number Diff line
@@ -996,10 +996,9 @@ public class UserManager {
    }

    /** {@hide} */
    public boolean isUserRunning(int userId) {
        // TODO Switch to using UMS internal isUserRunning
    public boolean isUserRunning(@UserIdInt int userId) {
        try {
            return ActivityManager.getService().isUserRunning(userId, 0);
            return mService.isUserRunning(userId);
        } catch (RemoteException re) {
            throw re.rethrowFromSystemServer();
        }
@@ -1096,8 +1095,7 @@ public class UserManager {
    /** {@hide} */
    public boolean isUserUnlocked(@UserIdInt int userId) {
        try {
            return ActivityManager.getService().isUserRunning(userId,
                    ActivityManager.FLAG_AND_UNLOCKED);
            return mService.isUserUnlocked(userId);
        } catch (RemoteException re) {
            throw re.rethrowFromSystemServer();
        }
+6 −0
Original line number Diff line number Diff line
@@ -141,6 +141,12 @@ public abstract class UserManagerInternal {
     */
    public abstract boolean isUserUnlockingOrUnlocked(int userId);

    /**
     * Return whether the given user is running in an
     * {@code UserState.STATE_RUNNING_UNLOCKED} state.
     */
    public abstract boolean isUserUnlocked(int userId);

    /**
     * Return whether the given user is running
     */
+33 −6
Original line number Diff line number Diff line
@@ -913,14 +913,33 @@ public class UserManagerService extends IUserManager.Stub {

    @Override
    public boolean isUserUnlockingOrUnlocked(int userId) {
        checkManageOrInteractPermIfCallerInOtherProfileGroup(userId, "isUserUnlockingOrUnlocked");
        return mLocalService.isUserUnlockingOrUnlocked(userId);
    }

    @Override
    public boolean isUserUnlocked(int userId) {
        checkManageOrInteractPermIfCallerInOtherProfileGroup(userId, "isUserUnlocked");
        return mLocalService.isUserUnlockingOrUnlocked(userId);
    }

    @Override
    public boolean isUserRunning(int userId) {
        checkManageOrInteractPermIfCallerInOtherProfileGroup(userId, "isUserRunning");
        return mLocalService.isUserRunning(userId);
    }

    private void checkManageOrInteractPermIfCallerInOtherProfileGroup(int userId, String name) {
        int callingUserId = UserHandle.getCallingUserId();
        if (callingUserId != userId && !hasManageUsersPermission()) {
            if (!isSameProfileGroupNoChecks(callingUserId, userId)) {
                throw new SecurityException(
                        "You need MANAGE_USERS permission to: check isUserUnlockingOrUnlocked");
        if (callingUserId == userId || isSameProfileGroupNoChecks(callingUserId, userId) ||
                hasManageUsersPermission()) {
            return;
        }
        if (ActivityManager.checkComponentPermission(Manifest.permission.INTERACT_ACROSS_USERS,
                Binder.getCallingUid(), -1, true) != PackageManager.PERMISSION_GRANTED) {
            throw new SecurityException("You need INTERACT_ACROSS_USERS or MANAGE_USERS permission "
                    + "to: check " + name);
        }
        return mLocalService.isUserUnlockingOrUnlocked(userId);
    }

    @Override
@@ -3641,6 +3660,14 @@ public class UserManagerService extends IUserManager.Stub {
                        || (state == UserState.STATE_RUNNING_UNLOCKED);
            }
        }

        @Override
        public boolean isUserUnlocked(int userId) {
            synchronized (mUserStates) {
                int state = mUserStates.get(userId, -1);
                return state == UserState.STATE_RUNNING_UNLOCKED;
            }
        }
    }

    /* Remove all the users except of the system one. */