Refactor Choose/Confirm Lock flow to take user id
This is a first step to allow this flow to be reused for setting
a work profile-specific lock, to be used with the work challenge.
Change-Id: Iaa65fdab9021cda5f0a1d3bc526a6b54f8a7dd16
diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java
index ed67ee4..468d568 100644
--- a/src/com/android/settings/Utils.java
+++ b/src/com/android/settings/Utils.java
@@ -1165,6 +1165,38 @@
return str;
}
+ /**
+ * Returns the user id present in the bundle with {@link ChooseLockGeneric#KEY_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) {
+ if (bundle == null) {
+ return getEffectiveUserId(context);
+ }
+ int userId = bundle.getInt(ChooseLockGeneric.KEY_USER_ID, UserHandle.myUserId());
+ return getSameOwnerUserId(context, userId);
+ }
+
+ /**
+ * Returns the given 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, 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());
+ }
+ }
+ return getEffectiveUserId(context);
+ }
+
public static int getEffectiveUserId(Context context) {
UserManager um = UserManager.get(context);
if (um != null) {