Resolve new intent that allows setting the parent challenge

Have ChooseLockGeneric resolve the new intent that allows setting the
parent challenge. If the new intent is received or seperate work
challenge is not supported, default to setting the challenge of the
parent user, otherwise use the calling user.

Change-Id: Ibd0ce8ce81b1d5c9073d4eb0096fdc74de12ee95
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 19ed0e4..186ddf7 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -1548,6 +1548,7 @@
             android:excludeFromRecents="true" >
             <intent-filter android:priority="1">
                 <action android:name="android.app.action.SET_NEW_PASSWORD" />
+                <action android:name="android.app.action.SET_NEW_PARENT_PROFILE_PASSWORD" />
                 <category android:name="android.intent.category.DEFAULT" />
             </intent-filter>
             <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
diff --git a/src/com/android/settings/ChooseLockGeneric.java b/src/com/android/settings/ChooseLockGeneric.java
index 65e6c27..bd46456 100644
--- a/src/com/android/settings/ChooseLockGeneric.java
+++ b/src/com/android/settings/ChooseLockGeneric.java
@@ -162,8 +162,20 @@
                         ENCRYPT_REQUESTED_DISABLED);
             }
 
-            // Only take this argument into account if it belongs to the current profile.
-            mUserId = Utils.getSameOwnerUserId(getContext(), getArguments());
+            int targetUser = Utils.getSecureTargetUser(
+                    getActivity().getActivityToken(),
+                    UserManager.get(getActivity()),
+                    null,
+                    getActivity().getIntent().getExtras()).getIdentifier();
+            if (DevicePolicyManager.ACTION_SET_NEW_PARENT_PROFILE_PASSWORD.equals(
+                    getActivity().getIntent().getAction()) ||
+                    !mLockPatternUtils.isSeparateProfileChallengeAllowed(targetUser)) {
+                // Always use parent if explicitely requested or if profile challenge is not
+                // supported
+                mUserId = Utils.getSameOwnerUserId(getContext(), getArguments());
+            } else {
+                mUserId = targetUser;
+            }
 
             if (mPasswordConfirmed) {
                 updatePreferencesOrFinish();