Merge "Make isAdminUser a public API" into udc-dev
This commit is contained in:
@@ -33834,6 +33834,7 @@ package android.os {
|
|||||||
method public android.os.Bundle getUserRestrictions();
|
method public android.os.Bundle getUserRestrictions();
|
||||||
method @RequiresPermission(anyOf={"android.permission.MANAGE_USERS", "android.permission.INTERACT_ACROSS_USERS"}, conditional=true) public android.os.Bundle getUserRestrictions(android.os.UserHandle);
|
method @RequiresPermission(anyOf={"android.permission.MANAGE_USERS", "android.permission.INTERACT_ACROSS_USERS"}, conditional=true) public android.os.Bundle getUserRestrictions(android.os.UserHandle);
|
||||||
method public boolean hasUserRestriction(String);
|
method public boolean hasUserRestriction(String);
|
||||||
|
method public boolean isAdminUser();
|
||||||
method public boolean isDemoUser();
|
method public boolean isDemoUser();
|
||||||
method public static boolean isHeadlessSystemUserMode();
|
method public static boolean isHeadlessSystemUserMode();
|
||||||
method public boolean isManagedProfile();
|
method public boolean isManagedProfile();
|
||||||
|
|||||||
@@ -10962,7 +10962,6 @@ package android.os {
|
|||||||
method @NonNull @RequiresPermission(anyOf={"android.permission.INTERACT_ACROSS_USERS", "android.permission.MANAGE_USERS"}) public java.util.Set<android.os.UserHandle> getVisibleUsers();
|
method @NonNull @RequiresPermission(anyOf={"android.permission.INTERACT_ACROSS_USERS", "android.permission.MANAGE_USERS"}) public java.util.Set<android.os.UserHandle> getVisibleUsers();
|
||||||
method @RequiresPermission(android.Manifest.permission.MANAGE_USERS) public boolean hasRestrictedProfiles();
|
method @RequiresPermission(android.Manifest.permission.MANAGE_USERS) public boolean hasRestrictedProfiles();
|
||||||
method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.INTERACT_ACROSS_USERS}, conditional=true) public boolean hasUserRestrictionForUser(@NonNull String, @NonNull android.os.UserHandle);
|
method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.INTERACT_ACROSS_USERS}, conditional=true) public boolean hasUserRestrictionForUser(@NonNull String, @NonNull android.os.UserHandle);
|
||||||
method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.CREATE_USERS, android.Manifest.permission.QUERY_USERS}) public boolean isAdminUser();
|
|
||||||
method public boolean isCloneProfile();
|
method public boolean isCloneProfile();
|
||||||
method @Deprecated public boolean isCredentialSharableWithParent();
|
method @Deprecated public boolean isCredentialSharableWithParent();
|
||||||
method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.CREATE_USERS, android.Manifest.permission.QUERY_USERS}) public boolean isGuestUser();
|
method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.CREATE_USERS, android.Manifest.permission.QUERY_USERS}) public boolean isGuestUser();
|
||||||
|
|||||||
@@ -117,6 +117,7 @@ interface IUserManager {
|
|||||||
boolean someUserHasAccount(in String accountName, in String accountType);
|
boolean someUserHasAccount(in String accountName, in String accountType);
|
||||||
String getProfileType(int userId);
|
String getProfileType(int userId);
|
||||||
boolean isDemoUser(int userId);
|
boolean isDemoUser(int userId);
|
||||||
|
boolean isAdminUser(int userId);
|
||||||
boolean isPreCreated(int userId);
|
boolean isPreCreated(int userId);
|
||||||
UserInfo createProfileForUserEvenWhenDisallowedWithThrow(in String name, in String userType, int flags,
|
UserInfo createProfileForUserEvenWhenDisallowedWithThrow(in String name, in String userType, int flags,
|
||||||
int userId, in String[] disallowedPackages);
|
int userId, in String[] disallowedPackages);
|
||||||
|
|||||||
@@ -2433,21 +2433,24 @@ public class UserManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to check if the context user is an admin user. An admin user is allowed to
|
* Used to check if the context user is an admin user. An admin user may be allowed to
|
||||||
* modify or configure certain settings that aren't available to non-admin users,
|
* modify or configure certain settings that aren't available to non-admin users,
|
||||||
* create and delete additional users, etc. There can be more than one admin users.
|
* create and delete additional users, etc. There can be more than one admin users.
|
||||||
*
|
*
|
||||||
* @return whether the context user is an admin user.
|
* @return whether the context user is an admin user.
|
||||||
* @hide
|
|
||||||
*/
|
*/
|
||||||
@SystemApi
|
@UserHandleAware(
|
||||||
@RequiresPermission(anyOf = {
|
enabledSinceTargetSdkVersion = Build.VERSION_CODES.TIRAMISU,
|
||||||
Manifest.permission.MANAGE_USERS,
|
requiresAnyOfPermissionsIfNotCallerProfileGroup = {
|
||||||
Manifest.permission.CREATE_USERS,
|
Manifest.permission.MANAGE_USERS,
|
||||||
Manifest.permission.QUERY_USERS})
|
Manifest.permission.CREATE_USERS,
|
||||||
@UserHandleAware(enabledSinceTargetSdkVersion = Build.VERSION_CODES.TIRAMISU)
|
Manifest.permission.QUERY_USERS})
|
||||||
public boolean isAdminUser() {
|
public boolean isAdminUser() {
|
||||||
return isUserAdmin(getContextUserIfAppropriate());
|
try {
|
||||||
|
return mService.isAdminUser(getContextUserIfAppropriate());
|
||||||
|
} catch (RemoteException re) {
|
||||||
|
throw re.rethrowFromSystemServer();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -3972,6 +3975,9 @@ public class UserManager {
|
|||||||
* time, the preferred user name and account information are used by the setup process for that
|
* time, the preferred user name and account information are used by the setup process for that
|
||||||
* user.
|
* user.
|
||||||
*
|
*
|
||||||
|
* This API should only be called if the current user is an {@link #isAdminUser() admin} user,
|
||||||
|
* as otherwise the returned intent will not be able to create a user.
|
||||||
|
*
|
||||||
* @param userName Optional name to assign to the user.
|
* @param userName Optional name to assign to the user.
|
||||||
* @param accountName Optional account name that will be used by the setup wizard to initialize
|
* @param accountName Optional account name that will be used by the setup wizard to initialize
|
||||||
* the user.
|
* the user.
|
||||||
|
|||||||
@@ -2049,6 +2049,27 @@ public class UserManagerService extends IUserManager.Stub {
|
|||||||
+ "permission to: check " + name);
|
+ "permission to: check " + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enforces that the calling user is in the same profile group as {@code userId} or that only
|
||||||
|
* the system UID or root's UID or apps that have the
|
||||||
|
* {@link android.Manifest.permission#MANAGE_USERS MANAGE_USERS} or
|
||||||
|
* {@link android.Manifest.permission#CREATE_USERS CREATE_USERS} or
|
||||||
|
* {@link android.Manifest.permission#QUERY_USERS QUERY_USERS}
|
||||||
|
* can make certain calls to the UserManager.
|
||||||
|
*
|
||||||
|
* @param userId the user's id
|
||||||
|
* @param name used as message if SecurityException is thrown
|
||||||
|
* @throws SecurityException if the caller lacks the required permissions.
|
||||||
|
*/
|
||||||
|
private void checkQueryOrCreateUsersPermissionIfCallerInOtherProfileGroup(
|
||||||
|
@UserIdInt int userId, String name) {
|
||||||
|
final int callingUserId = UserHandle.getCallingUserId();
|
||||||
|
if (callingUserId == userId || isSameProfileGroupNoChecks(callingUserId, userId)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
checkQueryOrCreateUsersPermission(name);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isDemoUser(@UserIdInt int userId) {
|
public boolean isDemoUser(@UserIdInt int userId) {
|
||||||
final int callingUserId = UserHandle.getCallingUserId();
|
final int callingUserId = UserHandle.getCallingUserId();
|
||||||
@@ -2062,6 +2083,15 @@ public class UserManagerService extends IUserManager.Stub {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAdminUser(@UserIdInt int userId) {
|
||||||
|
checkQueryOrCreateUsersPermissionIfCallerInOtherProfileGroup(userId, "isAdminUser");
|
||||||
|
synchronized (mUsersLock) {
|
||||||
|
final UserInfo userInfo = getUserInfoLU(userId);
|
||||||
|
return userInfo != null && userInfo.isAdmin();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isPreCreated(@UserIdInt int userId) {
|
public boolean isPreCreated(@UserIdInt int userId) {
|
||||||
checkManageOrInteractPermissionIfCallerInOtherProfileGroup(userId, "isPreCreated");
|
checkManageOrInteractPermissionIfCallerInOtherProfileGroup(userId, "isPreCreated");
|
||||||
|
|||||||
Reference in New Issue
Block a user