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

Commit 7dfb0f3d authored by Pasty Chang's avatar Pasty Chang Committed by android-build-merger
Browse files

Merge "Update the fingerprint skip dialog" into qt-dev am: d6f9ec12

am: 6c43c5a9

Change-Id: Id63a4942c83ac2d82c0b07256d1ffa9dfac6f68a
parents ec26d4e5 6c43c5a9
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -196,8 +196,14 @@ public class SetupChooseLockGeneric extends ChooseLockGeneric {
            final String key = preference.getKey();
            if (KEY_UNLOCK_SET_DO_LATER.equals(key)) {
                // show warning.
                SetupSkipDialog dialog = SetupSkipDialog.newInstance(getActivity().getIntent()
                        .getBooleanExtra(SetupSkipDialog.EXTRA_FRP_SUPPORTED, false));
                SetupSkipDialog dialog = SetupSkipDialog.newInstance(
                        getActivity().getIntent()
                                .getBooleanExtra(SetupSkipDialog.EXTRA_FRP_SUPPORTED, false),
                        /* isPatternMode= */ false,
                        /* isAlphaMode= */ false,
                        /* isFingerprintSupported= */ false,
                        /* isFaceSupported= */ false
                );
                dialog.show(getFragmentManager());
                return true;
            }
+10 −1
Original line number Diff line number Diff line
@@ -106,7 +106,16 @@ public class SetupChooseLockPassword extends ChooseLockPassword {
            if (mLeftButtonIsSkip) {
                SetupSkipDialog dialog = SetupSkipDialog.newInstance(
                        getActivity().getIntent()
                                .getBooleanExtra(SetupSkipDialog.EXTRA_FRP_SUPPORTED, false));
                                .getBooleanExtra(SetupSkipDialog.EXTRA_FRP_SUPPORTED, false),
                        /* isPatternMode= */ false,
                        mIsAlphaMode,
                        getActivity().getIntent()
                                .getBooleanExtra(ChooseLockSettingsHelper.EXTRA_KEY_FOR_FINGERPRINT,
                                        false),
                        getActivity().getIntent()
                                .getBooleanExtra(ChooseLockSettingsHelper.EXTRA_KEY_FOR_FACE, false)

                );
                dialog.show(getFragmentManager());
                return;
            }
+10 −1
Original line number Diff line number Diff line
@@ -92,7 +92,16 @@ public class SetupChooseLockPattern extends ChooseLockPattern {
            if (mLeftButtonIsSkip) {
                SetupSkipDialog dialog = SetupSkipDialog.newInstance(
                        getActivity().getIntent()
                                .getBooleanExtra(SetupSkipDialog.EXTRA_FRP_SUPPORTED, false));
                                .getBooleanExtra(SetupSkipDialog.EXTRA_FRP_SUPPORTED, false),
                        /* isPatternMode= */ true,
                        /* isAlphaMode= */ false,
                        getActivity().getIntent()
                                .getBooleanExtra(ChooseLockSettingsHelper.EXTRA_KEY_FOR_FINGERPRINT,
                                false),
                        getActivity().getIntent()
                                .getBooleanExtra(ChooseLockSettingsHelper.EXTRA_KEY_FOR_FACE, false)

                );
                dialog.show(getFragmentManager());
                return;
            }
+40 −8
Original line number Diff line number Diff line
@@ -35,13 +35,22 @@ public class SetupSkipDialog extends InstrumentedDialogFragment
    public static final String EXTRA_FRP_SUPPORTED = ":settings:frp_supported";

    private static final String ARG_FRP_SUPPORTED = "frp_supported";
    // The key indicates type of lock screen is pattern setup.
    private static final String ARG_LOCK_TYPE_PATTERN = "lock_type_pattern";
    // The key indicates type of lock screen setup is alphanumeric for password setup.
    private static final String ARG_LOCK_TYPE_ALPHANUMERIC = "lock_type_alphanumeric";
    private static final String TAG_SKIP_DIALOG = "skip_dialog";
    public static final int RESULT_SKIP = Activity.RESULT_FIRST_USER + 10;

    public static SetupSkipDialog newInstance(boolean isFrpSupported) {
    public static SetupSkipDialog newInstance(boolean isFrpSupported, boolean isPatternMode,
            boolean isAlphanumericMode, boolean isFingerprintSupported, boolean isFaceSupported) {
        SetupSkipDialog dialog = new SetupSkipDialog();
        Bundle args = new Bundle();
        args.putBoolean(ARG_FRP_SUPPORTED, isFrpSupported);
        args.putBoolean(ARG_LOCK_TYPE_PATTERN, isPatternMode);
        args.putBoolean(ARG_LOCK_TYPE_ALPHANUMERIC, isAlphanumericMode);
        args.putBoolean(ChooseLockSettingsHelper.EXTRA_KEY_FOR_FINGERPRINT, isFingerprintSupported);
        args.putBoolean(ChooseLockSettingsHelper.EXTRA_KEY_FOR_FACE, isFaceSupported);
        dialog.setArguments(args);
        return dialog;
    }
@@ -59,6 +68,28 @@ public class SetupSkipDialog extends InstrumentedDialogFragment
    @NonNull
    public AlertDialog.Builder onCreateDialogBuilder() {
        Bundle args = getArguments();
        final boolean isFaceSupported =
                args.getBoolean(ChooseLockSettingsHelper.EXTRA_KEY_FOR_FACE);
        final boolean isFingerprintSupported =
                args.getBoolean(ChooseLockSettingsHelper.EXTRA_KEY_FOR_FINGERPRINT);
        if (isFaceSupported || isFingerprintSupported) {
            final int titleId;

            if (args.getBoolean(ARG_LOCK_TYPE_PATTERN)) {
                titleId = R.string.lock_screen_pattern_skip_title;
            } else {
                titleId = args.getBoolean(ARG_LOCK_TYPE_ALPHANUMERIC) ?
                    R.string.lock_screen_password_skip_title : R.string.lock_screen_pin_skip_title;
            }

            return new AlertDialog.Builder(getContext())
                    .setPositiveButton(R.string.skip_lock_screen_dialog_button_label, this)
                    .setNegativeButton(R.string.cancel_lock_screen_dialog_button_label, this)
                    .setTitle(titleId)
                    .setMessage(isFaceSupported ?
                            R.string.face_lock_screen_setup_skip_dialog_text :
                            R.string.fingerprint_lock_screen_setup_skip_dialog_text);
        } else {
            return new AlertDialog.Builder(getContext())
                    .setPositiveButton(R.string.skip_anyway_button_label, this)
                    .setNegativeButton(R.string.go_back_button_label, this)
@@ -67,6 +98,7 @@ public class SetupSkipDialog extends InstrumentedDialogFragment
                            R.string.lock_screen_intro_skip_dialog_text_frp :
                            R.string.lock_screen_intro_skip_dialog_text);
        }
    }

    @Override
    public void onClick(DialogInterface dialog, int button) {
+101 −2
Original line number Diff line number Diff line
@@ -45,7 +45,8 @@ public class SetupSkipDialogTest {

    @Test
    public void frpMessages_areShownCorrectly_whenNotSupported() {
        SetupSkipDialog setupSkipDialog = SetupSkipDialog.newInstance(false);
        SetupSkipDialog setupSkipDialog =
                SetupSkipDialog.newInstance(false, false, false, false, false);
        setupSkipDialog.show(mActivity.getSupportFragmentManager());

        AlertDialog alertDialog = ShadowAlertDialogCompat.getLatestAlertDialog();
@@ -59,7 +60,8 @@ public class SetupSkipDialogTest {

    @Test
    public void frpMessages_areShownCorrectly_whenSupported() {
        SetupSkipDialog setupSkipDialog = SetupSkipDialog.newInstance(true);
        SetupSkipDialog setupSkipDialog =
                SetupSkipDialog.newInstance(true, false, false, false, false);
        setupSkipDialog.show(mActivity.getSupportFragmentManager());

        AlertDialog alertDialog = ShadowAlertDialogCompat.getLatestAlertDialog();
@@ -70,4 +72,101 @@ public class SetupSkipDialogTest {
        assertThat(mActivity.getString(R.string.lock_screen_intro_skip_dialog_text_frp)).isEqualTo(
                shadowAlertDialog.getMessage());
    }

    @Test
    public void dialogMessage_whenSkipPinSetupForFace_shouldShownCorrectly() {
        SetupSkipDialog setupSkipDialog =
                SetupSkipDialog.newInstance(true, false, false, false, true);
        setupSkipDialog.show(mActivity.getSupportFragmentManager());

        AlertDialog alertDialog = ShadowAlertDialogCompat.getLatestAlertDialog();
        assertThat(alertDialog).isNotNull();
        ShadowAlertDialogCompat shadowAlertDialog = ShadowAlertDialogCompat.shadowOf(alertDialog);
        assertThat(mActivity.getString(R.string.lock_screen_pin_skip_title)).isEqualTo(
                shadowAlertDialog.getTitle());

        assertThat(getSkipDialogMessage(false)).isEqualTo(shadowAlertDialog.getMessage());
    }

    @Test
    public void dialogMessage_whenSkipPasswordSetupForFace_shouldShownCorrectly() {
        SetupSkipDialog setupSkipDialog =
                SetupSkipDialog.newInstance(true, false, true, false, true);
        setupSkipDialog.show(mActivity.getSupportFragmentManager());

        AlertDialog alertDialog = ShadowAlertDialogCompat.getLatestAlertDialog();
        assertThat(alertDialog).isNotNull();
        ShadowAlertDialogCompat shadowAlertDialog = ShadowAlertDialogCompat.shadowOf(alertDialog);
        assertThat(mActivity.getString(R.string.lock_screen_password_skip_title)).isEqualTo(
                shadowAlertDialog.getTitle());

        assertThat(getSkipDialogMessage(false)).isEqualTo(shadowAlertDialog.getMessage());
    }

    @Test
    public void dialogMessage_whenSkipPatternSetupForFace_shouldShownCorrectly() {
        SetupSkipDialog setupSkipDialog =
                SetupSkipDialog.newInstance(true, true, false, false, true);
        setupSkipDialog.show(mActivity.getSupportFragmentManager());

        AlertDialog alertDialog = ShadowAlertDialogCompat.getLatestAlertDialog();
        assertThat(alertDialog).isNotNull();
        ShadowAlertDialogCompat shadowAlertDialog = ShadowAlertDialogCompat.shadowOf(alertDialog);
        assertThat(mActivity.getString(R.string.lock_screen_pattern_skip_title)).isEqualTo(
                shadowAlertDialog.getTitle());

        assertThat(getSkipDialogMessage(false)).isEqualTo(shadowAlertDialog.getMessage());
    }

    @Test
    public void dialogMessage_whenSkipPinSetupForFingerprint_shouldShownCorrectly() {
        SetupSkipDialog setupSkipDialog =
                SetupSkipDialog.newInstance(true, false, false, true, false);
        setupSkipDialog.show(mActivity.getSupportFragmentManager());

        AlertDialog alertDialog = ShadowAlertDialogCompat.getLatestAlertDialog();
        assertThat(alertDialog).isNotNull();
        ShadowAlertDialogCompat shadowAlertDialog = ShadowAlertDialogCompat.shadowOf(alertDialog);
        assertThat(mActivity.getString(R.string.lock_screen_pin_skip_title)).isEqualTo(
                shadowAlertDialog.getTitle());

        assertThat(getSkipDialogMessage(true)).isEqualTo(shadowAlertDialog.getMessage());
    }

    @Test
    public void dialogMessage_whenSkipPasswordSetupForFingerprint_shouldShownCorrectly() {
        SetupSkipDialog setupSkipDialog =
                SetupSkipDialog.newInstance(true, false, true, true, false);
        setupSkipDialog.show(mActivity.getSupportFragmentManager());

        AlertDialog alertDialog = ShadowAlertDialogCompat.getLatestAlertDialog();
        assertThat(alertDialog).isNotNull();
        ShadowAlertDialogCompat shadowAlertDialog = ShadowAlertDialogCompat.shadowOf(alertDialog);
        assertThat(mActivity.getString(R.string.lock_screen_password_skip_title)).isEqualTo(
                shadowAlertDialog.getTitle());

        assertThat(getSkipDialogMessage(true)).isEqualTo(shadowAlertDialog.getMessage());
    }

    @Test
    public void dialogMessage_whenSkipPatternSetupForFingerprint_shouldShownCorrectly() {
        SetupSkipDialog setupSkipDialog =
                SetupSkipDialog.newInstance(true, true, false, true, false);
        setupSkipDialog.show(mActivity.getSupportFragmentManager());

        AlertDialog alertDialog = ShadowAlertDialogCompat.getLatestAlertDialog();
        assertThat(alertDialog).isNotNull();
        ShadowAlertDialogCompat shadowAlertDialog = ShadowAlertDialogCompat.shadowOf(alertDialog);
        assertThat(mActivity.getString(R.string.lock_screen_pattern_skip_title)).isEqualTo(
                shadowAlertDialog.getTitle());

        assertThat(getSkipDialogMessage(true)).isEqualTo(shadowAlertDialog.getMessage());
    }

    public String getSkipDialogMessage(boolean isFingerprintSupported) {
        return String.format(
                mActivity.getString(isFingerprintSupported ?
                        R.string.fingerprint_lock_screen_setup_skip_dialog_text :
                        R.string.face_lock_screen_setup_skip_dialog_text));
    }
}