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

Commit 07b76793 authored by Jerry Shi's avatar Jerry Shi
Browse files

Properly handle the autofill provider names, making sure place holder

name is properly filtered out.

Bug: 337040395
Test: locally built and tested
Change-Id: I081064c6103f79fe966a36d0eea854ee9893bce3
parent 4fc959d8
Loading
Loading
Loading
Loading
+26 −10
Original line number Diff line number Diff line
@@ -521,16 +521,7 @@ public class CredentialManagerPreferenceController extends BasePreferenceControl
        // Get the selected autofill provider. If it is the placeholder then replace it with an
        // empty string.
        String selectedAutofillProvider =
                DefaultCombinedPicker.getSelectedAutofillProvider(mContext, getUser());
        String credentialAutofillService = "";
        if (android.service.autofill.Flags.autofillCredmanDevIntegration()) {
            credentialAutofillService = getCredentialAutofillService(mContext, TAG);
        }
        if (TextUtils.equals(selectedAutofillProvider, credentialAutofillService)
                || TextUtils.equals(
                        selectedAutofillProvider, AUTOFILL_CREDMAN_ONLY_PROVIDER_PLACEHOLDER)) {
            selectedAutofillProvider = "";
        }
                getSelectedAutofillProvider(mContext, getUser(), TAG);

        // Get the list of combined providers.
        List<CombinedProviderInfo> providers =
@@ -695,6 +686,31 @@ public class CredentialManagerPreferenceController extends BasePreferenceControl
        return "";
    }

    /** Gets the selected autofill provider name. This will filter out place holder names. **/
    public static @Nullable String getSelectedAutofillProvider(
            Context context, int userId, String tag) {
        String providerName = Settings.Secure.getStringForUser(
                context.getContentResolver(), Settings.Secure.AUTOFILL_SERVICE, userId);

        if (TextUtils.isEmpty(providerName)) {
            return providerName;
        }

        if (providerName.equals(AUTOFILL_CREDMAN_ONLY_PROVIDER_PLACEHOLDER)) {
            return "";
        }

        String credentialAutofillService = "";
        if (android.service.autofill.Flags.autofillCredmanDevIntegration()) {
            credentialAutofillService = getCredentialAutofillService(context, tag);
        }
        if (providerName.equals(credentialAutofillService)) {
            return "";
        }

        return providerName;
    }

    private CombiPreference addProviderPreference(
            @NonNull Context prefContext,
            @NonNull CharSequence title,
+3 −5
Original line number Diff line number Diff line
@@ -275,15 +275,13 @@ public class DefaultCombinedPicker extends DefaultAppPickerFragment {
                            CredentialManager.PROVIDER_FILTER_USER_PROVIDERS_INCLUDING_HIDDEN));
        }

        final String selectedAutofillProvider = getSelectedAutofillProvider(context, userId);
        final String selectedAutofillProvider =
                CredentialManagerPreferenceController
                    .getSelectedAutofillProvider(context, userId, TAG);
        return CombinedProviderInfo.buildMergedList(
                autofillProviders, credManProviders, selectedAutofillProvider);
    }

    public static String getSelectedAutofillProvider(Context context, int userId) {
        return Settings.Secure.getStringForUser(
                context.getContentResolver(), AUTOFILL_SETTING, userId);
    }

    protected List<DefaultAppInfo> getCandidates() {
        final Context context = getContext();
+10 −5
Original line number Diff line number Diff line
@@ -183,16 +183,15 @@ public class DefaultCombinedPreferenceController extends DefaultAppPreferenceCon
        final List<AutofillServiceInfo> autofillProviders =
                AutofillServiceInfo.getAvailableServices(mContext, userId);
        final String selectedAutofillProvider =
                Settings.Secure.getStringForUser(
                        mContext.getContentResolver(),
                        DefaultCombinedPicker.AUTOFILL_SETTING,
                        userId);
                CredentialManagerPreferenceController
                .getSelectedAutofillProvider(mContext, userId, TAG);

        final List<CredentialProviderInfo> credManProviders = new ArrayList<>();
        if (mCredentialManager != null) {
            credManProviders.addAll(
                    mCredentialManager.getCredentialProviderServices(
                            userId, CredentialManager.PROVIDER_FILTER_USER_PROVIDERS_ONLY));
                            userId,
                            CredentialManager.PROVIDER_FILTER_USER_PROVIDERS_INCLUDING_HIDDEN));
        }

        return CombinedProviderInfo.buildMergedList(
@@ -226,6 +225,12 @@ public class DefaultCombinedPreferenceController extends DefaultAppPreferenceCon
            return;
        }

        // Clean the autofill provider settings
        Settings.Secure.putStringForUser(
                mContext.getContentResolver(),
                DefaultCombinedPicker.AUTOFILL_SETTING, null, getUser());

        // Clean the credman provider settings.
        mCredentialManager.setEnabledProviders(
                List.of(), // empty primary provider.
                List.of(), // empty enabled providers.