Merge "Add background image for work challenge"
This commit is contained in:
committed by
Android (Google) Code Review
commit
454ce75a41
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.settings;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.ActivityManagerNative;
|
||||
@@ -184,6 +185,19 @@ public final class Utils extends com.android.settingslib.Utils {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the UserManager for a given context
|
||||
*
|
||||
* @throws IllegalStateException if no UserManager could be retrieved.
|
||||
*/
|
||||
public static UserManager getUserManager(Context context) {
|
||||
UserManager um = UserManager.get(context);
|
||||
if (um == null) {
|
||||
throw new IllegalStateException("Unable to load UserManager");
|
||||
}
|
||||
return um;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if Monkey is running.
|
||||
*/
|
||||
@@ -573,10 +587,24 @@ public final class Utils extends com.android.settingslib.Utils {
|
||||
|
||||
/**
|
||||
* Returns true if the current profile is a managed one.
|
||||
*
|
||||
* @throws IllegalArgumentException if userManager is null.
|
||||
*/
|
||||
public static boolean isManagedProfile(UserManager userManager) {
|
||||
UserInfo currentUser = userManager.getUserInfo(userManager.getUserHandle());
|
||||
return currentUser.isManagedProfile();
|
||||
public static boolean isManagedProfile(@NonNull UserManager userManager) {
|
||||
return isManagedProfile(userManager, UserHandle.myUserId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the userId passed in is a managed profile.
|
||||
*
|
||||
* @throws IllegalArgumentException if userManager is null.
|
||||
*/
|
||||
public static boolean isManagedProfile(@NonNull UserManager userManager, int userId) {
|
||||
if (userManager == null) {
|
||||
throw new IllegalArgumentException("userManager must not be null");
|
||||
}
|
||||
UserInfo userInfo = userManager.getUserInfo(userId);
|
||||
return (userInfo != null) ? userInfo.isManagedProfile() : false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -936,17 +964,17 @@ public final class Utils extends com.android.settingslib.Utils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the user id present in the bundle with {@link ChooseLockGeneric#KEY_USER_ID} if it
|
||||
* Returns the user id present in the bundle with {@link Intent#EXTRA_USER_ID} if it
|
||||
* belongs to the current user.
|
||||
*
|
||||
* @throws SecurityException if the given userId does not belong to the current user group.
|
||||
*/
|
||||
public static int getSameOwnerUserId(Context context, Bundle bundle) {
|
||||
public static int getUserIdFromBundle(Context context, Bundle bundle) {
|
||||
if (bundle == null) {
|
||||
return getEffectiveUserId(context);
|
||||
return getCredentialOwnerUserId(context);
|
||||
}
|
||||
int userId = bundle.getInt(Intent.EXTRA_USER_ID, UserHandle.myUserId());
|
||||
return getSameOwnerUserId(context, userId);
|
||||
return enforceSameOwner(context, userId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -954,27 +982,28 @@ public final class Utils extends com.android.settingslib.Utils {
|
||||
*
|
||||
* @throws SecurityException if the given userId does not belong to the current user group.
|
||||
*/
|
||||
public static int getSameOwnerUserId(Context context, int userId) {
|
||||
UserManager um = UserManager.get(context);
|
||||
if (um != null) {
|
||||
if (um.getUserProfiles().contains(new UserHandle(userId))) {
|
||||
return userId;
|
||||
} else {
|
||||
throw new SecurityException("Given user id " + userId + " does not belong to user "
|
||||
+ UserHandle.myUserId());
|
||||
}
|
||||
public static int enforceSameOwner(Context context, int userId) {
|
||||
UserManager um = getUserManager(context);
|
||||
if (!um.getUserProfiles().contains(new UserHandle(userId))) {
|
||||
throw new SecurityException("Given user id " + userId + " does not belong to user "
|
||||
+ UserHandle.myUserId());
|
||||
}
|
||||
return getEffectiveUserId(context);
|
||||
return userId;
|
||||
}
|
||||
|
||||
public static int getEffectiveUserId(Context context) {
|
||||
UserManager um = UserManager.get(context);
|
||||
if (um != null) {
|
||||
return um.getCredentialOwnerProfile(UserHandle.myUserId());
|
||||
} else {
|
||||
Log.e(TAG, "Unable to acquire UserManager");
|
||||
return UserHandle.myUserId();
|
||||
}
|
||||
/**
|
||||
* Returns the effective credential owner of the calling user.
|
||||
*/
|
||||
public static int getCredentialOwnerUserId(Context context) {
|
||||
return getCredentialOwnerUserId(context, UserHandle.myUserId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the user id of the credential owner of the given user id.
|
||||
*/
|
||||
public static int getCredentialOwnerUserId(Context context, int userId) {
|
||||
UserManager um = getUserManager(context);
|
||||
return um.getCredentialOwnerProfile(userId);
|
||||
}
|
||||
|
||||
public static int resolveResource(Context context, int attr) {
|
||||
|
Reference in New Issue
Block a user