From c5cde055629a55475601b7e077c432e563258507 Mon Sep 17 00:00:00 2001 From: Clara Bayarri Date: Thu, 22 Oct 2015 17:24:43 +0100 Subject: [PATCH] Fire pending intent from Confirm Credentials flow Add support in the Confirm Credentials flow to read an Intent extra and fire it when authentication succeeds. This is part of the Separate Work Challenge feature. Change-Id: I52c203735fa9b53fd2f7df971824747eeb930f36 --- AndroidManifest.xml | 11 +++++++ .../settings/ChooseLockSettingsHelper.java | 32 +++++++++++++++++++ .../ConfirmDeviceCredentialActivity.java | 22 +++++++++++-- .../ConfirmDeviceCredentialBaseFragment.java | 13 ++++++++ .../android/settings/ConfirmLockPassword.java | 2 ++ .../android/settings/ConfirmLockPattern.java | 2 ++ 6 files changed, 80 insertions(+), 2 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 212aeaeb02d..8c9af29cb23 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1468,6 +1468,17 @@ + + + + + + + + diff --git a/src/com/android/settings/ChooseLockSettingsHelper.java b/src/com/android/settings/ChooseLockSettingsHelper.java index 4c3fb7ba37a..ab814558053 100644 --- a/src/com/android/settings/ChooseLockSettingsHelper.java +++ b/src/com/android/settings/ChooseLockSettingsHelper.java @@ -21,6 +21,7 @@ import android.app.Activity; import android.app.Fragment; import android.app.admin.DevicePolicyManager; import android.content.Intent; +import android.content.IntentSender; import com.android.internal.widget.LockPatternUtils; @@ -112,6 +113,27 @@ public final class ChooseLockSettingsHelper { returnCredentials, external, false, 0, Utils.getEffectiveUserId(mActivity)); } + /** + * If a pattern, password or PIN exists, prompt the user before allowing them to change it. + * + * @param title title of the confirmation screen; shown in the action bar + * @param header header of the confirmation screen; shown as large text + * @param description description of the confirmation screen + * @param returnCredentials if true, put credentials into intent. Note that if this is true, + * this can only be called internally. + * @param external specifies whether this activity is launched externally, meaning that it will + * get a dark theme and allow fingerprint authentication + * @param userId The userId for whom the lock should be confirmed. + * @return true if one exists and we launched an activity to confirm it + * @see Activity#onActivityResult(int, int, android.content.Intent) + */ + boolean launchConfirmationActivity(int request, @Nullable CharSequence title, + @Nullable CharSequence header, @Nullable CharSequence description, + boolean returnCredentials, boolean external, int userId) { + return launchConfirmationActivity(request, title, header, description, + returnCredentials, external, false, 0, Utils.getSameOwnerUserId(mActivity, userId)); + } + /** * If a pattern, password or PIN exists, prompt the user before allowing them to change it. * @param message optional message to display about the action about to be done @@ -175,8 +197,18 @@ public final class ChooseLockSettingsHelper { if (external) { intent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT); if (mFragment != null) { + IntentSender intentSender = mFragment.getActivity().getIntent() + .getParcelableExtra(Intent.EXTRA_INTENT); + if (intentSender != null) { + intent.putExtra(Intent.EXTRA_INTENT, intentSender); + } mFragment.startActivity(intent); } else { + IntentSender intentSender = mActivity.getIntent() + .getParcelableExtra(Intent.EXTRA_INTENT); + if (intentSender != null) { + intent.putExtra(Intent.EXTRA_INTENT, intentSender); + } mActivity.startActivity(intent); } } else { diff --git a/src/com/android/settings/ConfirmDeviceCredentialActivity.java b/src/com/android/settings/ConfirmDeviceCredentialActivity.java index 86935c3fe5b..c4587ebc2fa 100644 --- a/src/com/android/settings/ConfirmDeviceCredentialActivity.java +++ b/src/com/android/settings/ConfirmDeviceCredentialActivity.java @@ -20,7 +20,11 @@ package com.android.settings; import android.app.Activity; import android.app.KeyguardManager; import android.content.Intent; +import android.os.Binder; import android.os.Bundle; +import android.os.Process; +import android.os.UserHandle; +import android.os.UserManager; import android.util.Log; /** @@ -30,6 +34,9 @@ import android.util.Log; public class ConfirmDeviceCredentialActivity extends Activity { public static final String TAG = ConfirmDeviceCredentialActivity.class.getSimpleName(); + public static class InternalActivity extends ConfirmDeviceCredentialActivity { + } + public static Intent createIntent(CharSequence title, CharSequence details) { Intent intent = new Intent(); intent.setClassName("com.android.settings", @@ -57,13 +64,24 @@ public class ConfirmDeviceCredentialActivity extends Activity { Intent intent = getIntent(); String title = intent.getStringExtra(KeyguardManager.EXTRA_TITLE); String details = intent.getStringExtra(KeyguardManager.EXTRA_DESCRIPTION); - + int userId = Utils.getEffectiveUserId(this); + if (isInternalActivity()) { + int givenUserId = intent.getIntExtra(Intent.EXTRA_USER_ID, userId); + UserManager userManager = UserManager.get(this); + if (userManager.isSameProfileGroup(givenUserId, userId)) { + userId = givenUserId; + } + } ChooseLockSettingsHelper helper = new ChooseLockSettingsHelper(this); if (!helper.launchConfirmationActivity(0 /* request code */, null /* title */, title, - details, false /* returnCredentials */, true /* isExternal */)) { + details, false /* returnCredentials */, true /* isExternal */, userId)) { Log.d(TAG, "No pattern, password or PIN set."); setResult(Activity.RESULT_OK); } finish(); } + + private boolean isInternalActivity() { + return this instanceof ConfirmDeviceCredentialActivity.InternalActivity; + } } diff --git a/src/com/android/settings/ConfirmDeviceCredentialBaseFragment.java b/src/com/android/settings/ConfirmDeviceCredentialBaseFragment.java index 32ad317e367..e04f86fe17a 100644 --- a/src/com/android/settings/ConfirmDeviceCredentialBaseFragment.java +++ b/src/com/android/settings/ConfirmDeviceCredentialBaseFragment.java @@ -18,6 +18,7 @@ package com.android.settings; import android.annotation.Nullable; import android.content.Intent; +import android.content.IntentSender; import android.os.Bundle; import android.view.View; import android.widget.Button; @@ -124,4 +125,16 @@ public abstract class ConfirmDeviceCredentialBaseFragment extends InstrumentedFr public void startEnterAnimation() { } + + protected void checkForPendingIntent() { + IntentSender intentSender = getActivity().getIntent() + .getParcelableExtra(Intent.EXTRA_INTENT); + if (intentSender != null) { + try { + getActivity().startIntentSenderForResult(intentSender, -1, null, 0, 0, 0); + } catch (IntentSender.SendIntentException e) { + /* ignore */ + } + } + } } diff --git a/src/com/android/settings/ConfirmLockPassword.java b/src/com/android/settings/ConfirmLockPassword.java index 7ef6a577d1d..53555e0c456 100644 --- a/src/com/android/settings/ConfirmLockPassword.java +++ b/src/com/android/settings/ConfirmLockPassword.java @@ -20,6 +20,7 @@ import android.app.Fragment; import android.app.admin.DevicePolicyManager; import android.content.Context; import android.content.Intent; +import android.content.IntentSender; import android.os.AsyncTask; import android.os.Bundle; import android.os.CountDownTimer; @@ -405,6 +406,7 @@ public class ConfirmLockPassword extends ConfirmDeviceCredentialBaseActivity { mPasswordEntryInputDisabler.setInputEnabled(true); if (matched) { startDisappearAnimation(intent); + checkForPendingIntent(); } else { if (timeoutMs > 0) { long deadline = mLockPatternUtils.setLockoutAttemptDeadline( diff --git a/src/com/android/settings/ConfirmLockPattern.java b/src/com/android/settings/ConfirmLockPattern.java index 44e74c964c0..63312902588 100644 --- a/src/com/android/settings/ConfirmLockPattern.java +++ b/src/com/android/settings/ConfirmLockPattern.java @@ -18,6 +18,7 @@ package com.android.settings; import android.app.Activity; import android.content.Intent; +import android.content.IntentSender; import android.os.AsyncTask; import android.os.Bundle; import android.os.CountDownTimer; @@ -473,6 +474,7 @@ public class ConfirmLockPattern extends ConfirmDeviceCredentialBaseActivity { mLockPatternView.setEnabled(true); if (matched) { startDisappearAnimation(intent); + checkForPendingIntent(); } else { if (timeoutMs > 0) { long deadline = mLockPatternUtils.setLockoutAttemptDeadline(