Add background image for work challenge
If the challenge shown is for a work profile, add the default image and
color to the background of the fragment.
Change-Id: I148c6cd3a835a84c7bac78b020839dfdae4a6c36
diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java
index 4afa1d9..56795ae 100644
--- a/src/com/android/settings/Utils.java
+++ b/src/com/android/settings/Utils.java
@@ -16,6 +16,7 @@
package com.android.settings;
+import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.ActivityManager;
import android.app.ActivityManagerNative;
@@ -181,6 +182,19 @@
}
/**
+ * 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.
*/
public static boolean isMonkeyRunning() {
@@ -569,10 +583,24 @@
/**
* 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;
}
/**
@@ -932,17 +960,17 @@
}
/**
- * 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);
}
/**
@@ -950,27 +978,28 @@
*
* @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) {