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

Commit b69351b0 authored by Becca Hughes's avatar Becca Hughes
Browse files

Add dialog for enabling a provider in settings

Test: manual
Bug: 277923170
Merged-In: I404444115f178faf5545dec9686096fcdfdf73de
Change-Id: I404444115f178faf5545dec9686096fcdfdf73de
parent e85d5889
Loading
Loading
Loading
Loading
+2 −5
Original line number Diff line number Diff line
@@ -10284,13 +10284,10 @@
    <string name="credman_confirmation_message">Saved info like addresses or payment methods won\'t be filled in when you sign in. To keep your saved info filled in, set enable a password, passkey and data/or service.</string>
    <!-- Title of the warning dialog for enabling the credential provider. [CHAR_LIMIT=NONE] -->
    <string name="credman_enable_confirmation_message_title">Turn on %1$s\?</string>
    <string name="credman_enable_confirmation_message_title">Use %1$s\?</string>
    <!-- Message of the warning dialog for enabling the credential provider. [CHAR_LIMIT=NONE] -->
    <string name="credman_enable_confirmation_message">Saved info like addresses or payment methods will be shared with this provider.</string>
    <!-- Positive button to turn on credential manager provider (confirmation). [CHAR LIMIT=60] -->
    <string name="credman_enable_confirmation_message_positive_button">Turn on</string>
    <string name="credman_enable_confirmation_message">%1$s uses what\'s on your screen to determine what can be autofilled.</string>
    <!-- Title of the error dialog when too many credential providers are selected. [CHAR_LIMIT=NONE] -->
    <string name="credman_error_message_title">Passwords, passkeys and data services limit</string>
+36 −27
Original line number Diff line number Diff line
@@ -153,8 +153,7 @@ public class CredentialManagerPreferenceController extends BasePreferenceControl
        }

        final String action = launchIntent.getAction();
        final boolean isCredProviderAction =
                TextUtils.equals(action, PRIMARY_INTENT);
        final boolean isCredProviderAction = TextUtils.equals(action, PRIMARY_INTENT);
        final boolean isExistingAction = TextUtils.equals(action, ALTERNATE_INTENT);
        final boolean isValid = isCredProviderAction || isExistingAction;

@@ -226,7 +225,8 @@ public class CredentialManagerPreferenceController extends BasePreferenceControl
        }

        NewProviderConfirmationDialogFragment fragment =
                newNewProviderConfirmationDialogFragment(serviceInfo.packageName, appName);
                newNewProviderConfirmationDialogFragment(
                        serviceInfo.packageName, appName, /* setActivityResult= */ true);
        if (fragment == null || mFragmentManager == null) {
            return;
        }
@@ -482,19 +482,16 @@ public class CredentialManagerPreferenceController extends BasePreferenceControl
                    boolean isChecked = pref.isChecked();

                    if (isChecked) {
                        // Show the error if too many enabled.
                        if (!togglePackageNameEnabled(packageName)) {
                            final DialogFragment fragment = newErrorDialogFragment();

                        // Since we are enabling it we should confirm the user decision with a
                        // dialog box.
                        NewProviderConfirmationDialogFragment fragment =
                                newNewProviderConfirmationDialogFragment(
                                        packageName, title, /* setActivityResult= */ false);
                        if (fragment == null || mFragmentManager == null) {
                            return true;
                        }

                            fragment.show(mFragmentManager, ErrorDialogFragment.TAG);

                            // The user set the check to true so we need to set it back.
                            pref.setChecked(false);
                        }
                        fragment.show(mFragmentManager, NewProviderConfirmationDialogFragment.TAG);

                        return true;
                    } else {
@@ -546,12 +543,15 @@ public class CredentialManagerPreferenceController extends BasePreferenceControl
    /** Create the new provider confirmation dialog. */
    private @Nullable NewProviderConfirmationDialogFragment
            newNewProviderConfirmationDialogFragment(
                    @NonNull String packageName, @NonNull CharSequence appName) {
                    @NonNull String packageName,
                    @NonNull CharSequence appName,
                    boolean setActivityResult) {
        DialogHost host =
                new DialogHost() {
                    @Override
                    public void onDialogClick(int whichButton) {
                        completeEnableProviderDialogBox(whichButton, packageName);
                        completeEnableProviderDialogBox(
                                whichButton, packageName, setActivityResult);
                    }
                };

@@ -559,17 +559,19 @@ public class CredentialManagerPreferenceController extends BasePreferenceControl
    }

    @VisibleForTesting
    void completeEnableProviderDialogBox(int whichButton, String packageName) {
    void completeEnableProviderDialogBox(
            int whichButton, String packageName, boolean setActivityResult) {
        int activityResult = -1;
        if (whichButton == DialogInterface.BUTTON_POSITIVE) {
            if (togglePackageNameEnabled(packageName)) {
                // Enable all prefs.
                if (mPrefs.containsKey(packageName)) {
                    mPrefs.get(packageName).setChecked(true);
                }
                setActivityResult(Activity.RESULT_OK);
                activityResult = Activity.RESULT_OK;
            } else {
                // There are too many providers so set the result as cancelled.
                setActivityResult(Activity.RESULT_CANCELED);
                activityResult = Activity.RESULT_CANCELED;

                // Show the error if too many enabled.
                final DialogFragment fragment = newErrorDialogFragment();
@@ -582,7 +584,13 @@ public class CredentialManagerPreferenceController extends BasePreferenceControl
            }
        } else {
            // The user clicked the cancel button so send that result back.
            setActivityResult(Activity.RESULT_CANCELED);
            activityResult = Activity.RESULT_CANCELED;
        }

        // If the dialog is being shown because of the intent we should
        // return a result.
        if (activityResult == -1 || !setActivityResult) {
            setActivityResult(activityResult);
        }
    }

@@ -735,16 +743,17 @@ public class CredentialManagerPreferenceController extends BasePreferenceControl
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            final Bundle bundle = getArguments();
            final Context context = getContext();
            final CharSequence appName =
                    bundle.getCharSequence(CredentialManagerDialogFragment.APP_NAME_KEY);
            final String title =
                    context.getString(
                            R.string.credman_enable_confirmation_message_title,
                            bundle.getCharSequence(CredentialManagerDialogFragment.APP_NAME_KEY));
                    context.getString(R.string.credman_enable_confirmation_message_title, appName);
            final String message =
                    context.getString(R.string.credman_enable_confirmation_message, appName);

            return new AlertDialog.Builder(getActivity())
                    .setTitle(title)
                    .setMessage(context.getString(R.string.credman_enable_confirmation_message))
                    .setPositiveButton(
                            R.string.credman_enable_confirmation_message_positive_button, this)
                    .setMessage(message)
                    .setPositiveButton(android.R.string.ok, this)
                    .setNegativeButton(android.R.string.cancel, this)
                    .create();
        }
+4 −4
Original line number Diff line number Diff line
@@ -389,7 +389,7 @@ public class CredentialManagerPreferenceControllerTest {
        Intent intent = new Intent(PRIMARY_INTENT);
        intent.setData(Uri.parse("package:" + packageName));
        assertThat(controller.verifyReceivedIntent(intent)).isTrue();
        controller.completeEnableProviderDialogBox(DialogInterface.BUTTON_POSITIVE, packageName);
        controller.completeEnableProviderDialogBox(DialogInterface.BUTTON_POSITIVE, packageName, true);
        assertThat(mReceivedResultCode.get()).isEqualTo(Activity.RESULT_OK);
    }

@@ -404,7 +404,7 @@ public class CredentialManagerPreferenceControllerTest {
        Intent intent = new Intent(PRIMARY_INTENT);
        intent.setData(Uri.parse("package:" + packageName));
        assertThat(controller.verifyReceivedIntent(intent)).isTrue();
        controller.completeEnableProviderDialogBox(DialogInterface.BUTTON_NEGATIVE, packageName);
        controller.completeEnableProviderDialogBox(DialogInterface.BUTTON_NEGATIVE, packageName, true);
        assertThat(mReceivedResultCode.get()).isEqualTo(Activity.RESULT_CANCELED);
    }

@@ -430,7 +430,7 @@ public class CredentialManagerPreferenceControllerTest {
        Intent intent = new Intent(ALTERNATE_INTENT);
        intent.setData(Uri.parse("package:" + packageName));
        assertThat(controller.verifyReceivedIntent(intent)).isTrue();
        controller.completeEnableProviderDialogBox(DialogInterface.BUTTON_POSITIVE, packageName);
        controller.completeEnableProviderDialogBox(DialogInterface.BUTTON_POSITIVE, packageName, true);
        assertThat(mReceivedResultCode.get()).isEqualTo(Activity.RESULT_OK);
    }

@@ -445,7 +445,7 @@ public class CredentialManagerPreferenceControllerTest {
        Intent intent = new Intent(ALTERNATE_INTENT);
        intent.setData(Uri.parse("package:" + packageName));
        assertThat(controller.verifyReceivedIntent(intent)).isTrue();
        controller.completeEnableProviderDialogBox(DialogInterface.BUTTON_NEGATIVE, packageName);
        controller.completeEnableProviderDialogBox(DialogInterface.BUTTON_NEGATIVE, packageName, true);
        assertThat(mReceivedResultCode.get()).isEqualTo(Activity.RESULT_CANCELED);
    }