Loading core/java/android/os/IUserManager.aidl +3 −0 Original line number Original line Diff line number Diff line Loading @@ -82,4 +82,7 @@ interface IUserManager { boolean someUserHasSeedAccount(in String accountName, in String accountType); boolean someUserHasSeedAccount(in String accountName, in String accountType); boolean isManagedProfile(int userId); boolean isManagedProfile(int userId); boolean isDemoUser(int userId); boolean isDemoUser(int userId); boolean isUserUnlocked(int userId); boolean isUserUnlockingOrUnlocked(int userId); boolean isUserRunning(int userId); } } core/java/android/os/UserManager.java +3 −7 Original line number Original line Diff line number Diff line Loading @@ -960,9 +960,8 @@ public class UserManager { /** {@hide} */ /** {@hide} */ public boolean isUserRunning(int userId) { public boolean isUserRunning(int userId) { // TODO Switch to using UMS internal isUserRunning try { try { return ActivityManagerNative.getDefault().isUserRunning(userId, 0); return mService.isUserRunning(userId); } catch (RemoteException re) { } catch (RemoteException re) { throw re.rethrowFromSystemServer(); throw re.rethrowFromSystemServer(); } } Loading Loading @@ -1059,8 +1058,7 @@ public class UserManager { /** {@hide} */ /** {@hide} */ public boolean isUserUnlocked(@UserIdInt int userId) { public boolean isUserUnlocked(@UserIdInt int userId) { try { try { return ActivityManagerNative.getDefault().isUserRunning(userId, return mService.isUserUnlocked(userId); ActivityManager.FLAG_AND_UNLOCKED); } catch (RemoteException re) { } catch (RemoteException re) { throw re.rethrowFromSystemServer(); throw re.rethrowFromSystemServer(); } } Loading @@ -1073,10 +1071,8 @@ public class UserManager { /** {@hide} */ /** {@hide} */ public boolean isUserUnlockingOrUnlocked(@UserIdInt int userId) { public boolean isUserUnlockingOrUnlocked(@UserIdInt int userId) { // TODO Switch to using UMS internal isUserUnlockingOrUnlocked try { try { return ActivityManagerNative.getDefault().isUserRunning(userId, return mService.isUserUnlockingOrUnlocked(userId); ActivityManager.FLAG_AND_UNLOCKING_OR_UNLOCKED); } catch (RemoteException re) { } catch (RemoteException re) { throw re.rethrowFromSystemServer(); throw re.rethrowFromSystemServer(); } } Loading core/java/android/os/UserManagerInternal.java +6 −0 Original line number Original line Diff line number Diff line Loading @@ -134,6 +134,12 @@ public abstract class UserManagerInternal { */ */ public abstract boolean isUserUnlockingOrUnlocked(int userId); 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 * Return whether the given user is running */ */ Loading services/core/java/com/android/server/pm/UserManagerService.java +45 −10 Original line number Original line Diff line number Diff line Loading @@ -654,12 +654,10 @@ public class UserManagerService extends IUserManager.Stub { public boolean isSameProfileGroup(int userId, int otherUserId) { public boolean isSameProfileGroup(int userId, int otherUserId) { if (userId == otherUserId) return true; if (userId == otherUserId) return true; checkManageUsersPermission("check if in the same profile group"); checkManageUsersPermission("check if in the same profile group"); synchronized (mPackagesLock) { return isSameProfileGroupNoChecks(userId, otherUserId); return isSameProfileGroupLP(userId, otherUserId); } } } private boolean isSameProfileGroupLP(int userId, int otherUserId) { private boolean isSameProfileGroupNoChecks(int userId, int otherUserId) { synchronized (mUsersLock) { synchronized (mUsersLock) { UserInfo userInfo = getUserInfoLU(userId); UserInfo userInfo = getUserInfoLU(userId); if (userInfo == null || userInfo.profileGroupId == UserInfo.NO_PROFILE_GROUP_ID) { if (userInfo == null || userInfo.profileGroupId == UserInfo.NO_PROFILE_GROUP_ID) { Loading Loading @@ -861,20 +859,49 @@ public class UserManagerService extends IUserManager.Stub { public boolean isManagedProfile(int userId) { public boolean isManagedProfile(int userId) { int callingUserId = UserHandle.getCallingUserId(); int callingUserId = UserHandle.getCallingUserId(); if (callingUserId != userId && !hasManageUsersPermission()) { if (callingUserId != userId && !hasManageUsersPermission()) { synchronized (mPackagesLock) { if (!isSameProfileGroupNoChecks(callingUserId, userId)) { if (!isSameProfileGroupLP(callingUserId, userId)) { throw new SecurityException( throw new SecurityException( "You need MANAGE_USERS permission to: check if specified user a " + "You need MANAGE_USERS permission to: check if specified user a " + "managed profile outside your profile group"); "managed profile outside your profile group"); } } } } } synchronized (mUsersLock) { synchronized (mUsersLock) { UserInfo userInfo = getUserInfoLU(userId); UserInfo userInfo = getUserInfoLU(userId); return userInfo != null && userInfo.isManagedProfile(); return userInfo != null && userInfo.isManagedProfile(); } } } } @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 || 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); } } @Override @Override public boolean isDemoUser(int userId) { public boolean isDemoUser(int userId) { int callingUserId = UserHandle.getCallingUserId(); int callingUserId = UserHandle.getCallingUserId(); Loading Loading @@ -3485,6 +3512,14 @@ public class UserManagerService extends IUserManager.Stub { || (state == UserState.STATE_RUNNING_UNLOCKED); || (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. */ /* Remove all the users except of the system one. */ Loading Loading
core/java/android/os/IUserManager.aidl +3 −0 Original line number Original line Diff line number Diff line Loading @@ -82,4 +82,7 @@ interface IUserManager { boolean someUserHasSeedAccount(in String accountName, in String accountType); boolean someUserHasSeedAccount(in String accountName, in String accountType); boolean isManagedProfile(int userId); boolean isManagedProfile(int userId); boolean isDemoUser(int userId); boolean isDemoUser(int userId); boolean isUserUnlocked(int userId); boolean isUserUnlockingOrUnlocked(int userId); boolean isUserRunning(int userId); } }
core/java/android/os/UserManager.java +3 −7 Original line number Original line Diff line number Diff line Loading @@ -960,9 +960,8 @@ public class UserManager { /** {@hide} */ /** {@hide} */ public boolean isUserRunning(int userId) { public boolean isUserRunning(int userId) { // TODO Switch to using UMS internal isUserRunning try { try { return ActivityManagerNative.getDefault().isUserRunning(userId, 0); return mService.isUserRunning(userId); } catch (RemoteException re) { } catch (RemoteException re) { throw re.rethrowFromSystemServer(); throw re.rethrowFromSystemServer(); } } Loading Loading @@ -1059,8 +1058,7 @@ public class UserManager { /** {@hide} */ /** {@hide} */ public boolean isUserUnlocked(@UserIdInt int userId) { public boolean isUserUnlocked(@UserIdInt int userId) { try { try { return ActivityManagerNative.getDefault().isUserRunning(userId, return mService.isUserUnlocked(userId); ActivityManager.FLAG_AND_UNLOCKED); } catch (RemoteException re) { } catch (RemoteException re) { throw re.rethrowFromSystemServer(); throw re.rethrowFromSystemServer(); } } Loading @@ -1073,10 +1071,8 @@ public class UserManager { /** {@hide} */ /** {@hide} */ public boolean isUserUnlockingOrUnlocked(@UserIdInt int userId) { public boolean isUserUnlockingOrUnlocked(@UserIdInt int userId) { // TODO Switch to using UMS internal isUserUnlockingOrUnlocked try { try { return ActivityManagerNative.getDefault().isUserRunning(userId, return mService.isUserUnlockingOrUnlocked(userId); ActivityManager.FLAG_AND_UNLOCKING_OR_UNLOCKED); } catch (RemoteException re) { } catch (RemoteException re) { throw re.rethrowFromSystemServer(); throw re.rethrowFromSystemServer(); } } Loading
core/java/android/os/UserManagerInternal.java +6 −0 Original line number Original line Diff line number Diff line Loading @@ -134,6 +134,12 @@ public abstract class UserManagerInternal { */ */ public abstract boolean isUserUnlockingOrUnlocked(int userId); 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 * Return whether the given user is running */ */ Loading
services/core/java/com/android/server/pm/UserManagerService.java +45 −10 Original line number Original line Diff line number Diff line Loading @@ -654,12 +654,10 @@ public class UserManagerService extends IUserManager.Stub { public boolean isSameProfileGroup(int userId, int otherUserId) { public boolean isSameProfileGroup(int userId, int otherUserId) { if (userId == otherUserId) return true; if (userId == otherUserId) return true; checkManageUsersPermission("check if in the same profile group"); checkManageUsersPermission("check if in the same profile group"); synchronized (mPackagesLock) { return isSameProfileGroupNoChecks(userId, otherUserId); return isSameProfileGroupLP(userId, otherUserId); } } } private boolean isSameProfileGroupLP(int userId, int otherUserId) { private boolean isSameProfileGroupNoChecks(int userId, int otherUserId) { synchronized (mUsersLock) { synchronized (mUsersLock) { UserInfo userInfo = getUserInfoLU(userId); UserInfo userInfo = getUserInfoLU(userId); if (userInfo == null || userInfo.profileGroupId == UserInfo.NO_PROFILE_GROUP_ID) { if (userInfo == null || userInfo.profileGroupId == UserInfo.NO_PROFILE_GROUP_ID) { Loading Loading @@ -861,20 +859,49 @@ public class UserManagerService extends IUserManager.Stub { public boolean isManagedProfile(int userId) { public boolean isManagedProfile(int userId) { int callingUserId = UserHandle.getCallingUserId(); int callingUserId = UserHandle.getCallingUserId(); if (callingUserId != userId && !hasManageUsersPermission()) { if (callingUserId != userId && !hasManageUsersPermission()) { synchronized (mPackagesLock) { if (!isSameProfileGroupNoChecks(callingUserId, userId)) { if (!isSameProfileGroupLP(callingUserId, userId)) { throw new SecurityException( throw new SecurityException( "You need MANAGE_USERS permission to: check if specified user a " + "You need MANAGE_USERS permission to: check if specified user a " + "managed profile outside your profile group"); "managed profile outside your profile group"); } } } } } synchronized (mUsersLock) { synchronized (mUsersLock) { UserInfo userInfo = getUserInfoLU(userId); UserInfo userInfo = getUserInfoLU(userId); return userInfo != null && userInfo.isManagedProfile(); return userInfo != null && userInfo.isManagedProfile(); } } } } @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 || 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); } } @Override @Override public boolean isDemoUser(int userId) { public boolean isDemoUser(int userId) { int callingUserId = UserHandle.getCallingUserId(); int callingUserId = UserHandle.getCallingUserId(); Loading Loading @@ -3485,6 +3512,14 @@ public class UserManagerService extends IUserManager.Stub { || (state == UserState.STATE_RUNNING_UNLOCKED); || (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. */ /* Remove all the users except of the system one. */ Loading