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

Commit c413f707 authored by Fyodor Kupolov's avatar Fyodor Kupolov
Browse files

Switch UM to internal isUserUnlockingOrUnlocked

Internal version of UMS maintains a self-locking data-structure of user
states that  is pushed from ActivityManager. Previously there could
be discrepancies between UMS.isUserUnlockingOrUnlocked and
UM.isUserUnlockingOrUnlocked, which is calling a blocking version
in ActivityManager.

Test: manual + UserManagerTests

Bug: 31995235
Bug: 31833240
Change-Id: Ibafe403f57cd32d9052bb55fe7273a861be1d037
parent 6e68beda
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -85,4 +85,5 @@ interface IUserManager {
    boolean isDemoUser(int userId);
    UserInfo createProfileForUserEvenWhenDisallowed(in String name, int flags, int userHandle,
            in String[] disallowedPackages);
    boolean isUserUnlockingOrUnlocked(int userId);
}
+1 −3
Original line number Diff line number Diff line
@@ -1094,10 +1094,8 @@ public class UserManager {

    /** {@hide} */
    public boolean isUserUnlockingOrUnlocked(@UserIdInt int userId) {
        // TODO Switch to using UMS internal isUserUnlockingOrUnlocked
        try {
            return ActivityManagerNative.getDefault().isUserRunning(userId,
                    ActivityManager.FLAG_AND_UNLOCKING_OR_UNLOCKED);
            return mService.isUserUnlockingOrUnlocked(userId);
        } catch (RemoteException re) {
            throw re.rethrowFromSystemServer();
        }
+2 −7
Original line number Diff line number Diff line
@@ -64,6 +64,7 @@ import android.os.RemoteException;
import android.os.SystemClock;
import android.os.UserHandle;
import android.os.UserManager;
import android.os.UserManagerInternal;
import android.provider.Settings;
import android.text.TextUtils;
import android.text.TextUtils.SimpleStringSplitter;
@@ -1301,14 +1302,8 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub {
    private void updateServicesLocked(UserState userState) {
        Map<ComponentName, Service> componentNameToServiceMap =
                userState.mComponentNameToServiceMap;
        boolean isUnlockingOrUnlocked;
        final long identity = Binder.clearCallingIdentity();
        try {
            isUnlockingOrUnlocked = mContext.getSystemService(UserManager.class)
        boolean isUnlockingOrUnlocked = LocalServices.getService(UserManagerInternal.class)
                    .isUserUnlockingOrUnlocked(userState.mUserId);
        } finally {
            Binder.restoreCallingIdentity(identity);
        }

        for (int i = 0, count = userState.mInstalledServices.size(); i < count; i++) {
            AccessibilityServiceInfo installedService = userState.mInstalledServices.get(i);
+16 −12
Original line number Diff line number Diff line
@@ -673,12 +673,6 @@ public class UserManagerService extends IUserManager.Stub {
    public boolean isSameProfileGroup(int userId, int otherUserId) {
        if (userId == otherUserId) return true;
        checkManageUsersPermission("check if in the same profile group");
        synchronized (mPackagesLock) {
            return isSameProfileGroupLP(userId, otherUserId);
        }
    }

    private boolean isSameProfileGroupLP(int userId, int otherUserId) {
        synchronized (mUsersLock) {
            UserInfo userInfo = getUserInfoLU(userId);
            if (userInfo == null || userInfo.profileGroupId == UserInfo.NO_PROFILE_GROUP_ID) {
@@ -880,20 +874,30 @@ public class UserManagerService extends IUserManager.Stub {
    public boolean isManagedProfile(int userId) {
        int callingUserId = UserHandle.getCallingUserId();
        if (callingUserId != userId && !hasManageUsersPermission()) {
            synchronized (mPackagesLock) {
                if (!isSameProfileGroupLP(callingUserId, userId)) {
            if (!isSameProfileGroup(callingUserId, userId)) {
                throw new SecurityException(
                        "You need MANAGE_USERS permission to: check if specified user a " +
                        "managed profile outside your profile group");
            }
        }
        }
        synchronized (mUsersLock) {
            UserInfo userInfo = getUserInfoLU(userId);
            return userInfo != null && userInfo.isManagedProfile();
        }
    }

    @Override
    public boolean isUserUnlockingOrUnlocked(int userId) {
        int callingUserId = UserHandle.getCallingUserId();
        if (callingUserId != userId && !hasManageUsersPermission()) {
            if (!isSameProfileGroup(callingUserId, userId)) {
                throw new SecurityException(
                        "You need MANAGE_USERS permission to: check isUserUnlockingOrUnlocked");
            }
        }
        return mLocalService.isUserUnlockingOrUnlocked(userId);
    }

    @Override
    public boolean isDemoUser(int userId) {
        int callingUserId = UserHandle.getCallingUserId();