Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c5cde055 authored by Clara Bayarri's avatar Clara Bayarri
Browse files

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
parent 990c08e3
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -1468,6 +1468,17 @@
            </intent-filter>
        </activity>

        <!-- Note this must not be exported since it authenticates the given user -->
        <activity android:name="ConfirmDeviceCredentialActivity$InternalActivity"
            android:exported="false"
            android:permission="android.permission.MANAGE_USERS"
            android:theme="@android:style/Theme.NoDisplay">
            <intent-filter android:priority="1">
                <action android:name="android.app.action.CONFIRM_DEVICE_CREDENTIAL_WITH_USER" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

        <activity android:name=".SetupRedactionInterstitial"
            android:taskAffinity="com.android.wizard"
            android:theme="@style/SetupWizardDisableAppStartingTheme"/>
+32 −0
Original line number Diff line number Diff line
@@ -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 {
+20 −2
Original line number Diff line number Diff line
@@ -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;
    }
}
+13 −0
Original line number Diff line number Diff line
@@ -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 */
            }
        }
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -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(
Loading