Commit 10c9c19f authored by Sujie Zhu's avatar Sujie Zhu Committed by Commit Bot

[Autofill Auth][Clank] add FIDO auth toggle to Clank settings page

We add FIDO auth toggle on Clank Autofill Payment settings page. The
toggle is shown only when 1) autofill is enabled 2) sync is enabled 3)
feature flag is enabled. The requirement check is accomplished by
adding one more PersonalDataManager bridge function.

We reuse FIDOAuthEnabled preference to show current user's status and
record user's intention (intent to opt in/out). The preference is exposed
to Java side in order to get/set the preference via PrefServiceBridge.

Local tested video (Googlers only): https://drive.google.com/a/google.com/file/d/1nJ1pSJZu1e5oV6qle_Piog6-a-v7kmZs/view?usp=sharing
For more detailed background (Googlers only): go/autofill-auth-clank-settings

Bug: 949269
Change-Id: Iefad4c953eee4dc00ec54627810b135c1eec6206
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2029255
Commit-Queue: Sujie Zhu <sujiezhu@google.com>
Reviewed-by: default avatarsebsg <sebsg@chromium.org>
Reviewed-by: default avatarManas Verma <manasverma@google.com>
Reviewed-by: default avatarNatalie Chouinard <chouinard@chromium.org>
Reviewed-by: default avatarJared Saul <jsaul@google.com>
Cr-Commit-Position: refs/heads/master@{#738766}
parent 69926c86
......@@ -947,6 +947,15 @@ public class PersonalDataManager {
return PersonalDataManagerJni.get().hasCreditCards(mPersonalDataManagerAndroid);
}
/**
* @return Whether FIDO authentication is available.
*/
public boolean isFidoAuthenticationAvailable() {
return isAutofillCreditCardEnabled()
&& PersonalDataManagerJni.get().isFidoAuthenticationAvailable(
mPersonalDataManagerAndroid);
}
/**
* @return Whether the Autofill feature for Profiles (addresses) is enabled.
*/
......@@ -977,6 +986,25 @@ public class PersonalDataManager {
PrefServiceBridge.getInstance().setBoolean(Pref.AUTOFILL_CREDIT_CARD_ENABLED, enable);
}
/**
* @return Whether the Autofill feature for FIDO authentication is enabled.
*/
public static boolean isAutofillCreditCardFidoAuthEnabled() {
return PrefServiceBridge.getInstance().getBoolean(
Pref.AUTOFILL_CREDIT_CARD_FIDO_AUTH_ENABLED);
}
/**
* Enables or disables the Autofill feature for FIDO authentication.
* We are trying to align this pref with the server's source of truth, but any mismatches
* between this pref and the server should imply the user's intention to opt in/out.
* @param enable True to enable credit card FIDO authentication, false otherwise.
*/
public static void setAutofillCreditCardFidoAuthEnabled(boolean enable) {
PrefServiceBridge.getInstance().setBoolean(
Pref.AUTOFILL_CREDIT_CARD_FIDO_AUTH_ENABLED, enable);
}
/**
* @return Whether the Autofill feature is managed.
*/
......@@ -1110,6 +1138,7 @@ public class PersonalDataManager {
GetSubKeysRequestDelegate delegate);
boolean hasProfiles(long nativePersonalDataManagerAndroid);
boolean hasCreditCards(long nativePersonalDataManagerAndroid);
boolean isFidoAuthenticationAvailable(long nativePersonalDataManagerAndroid);
boolean isAutofillManaged();
boolean isAutofillProfileManaged();
boolean isAutofillCreditCardManaged();
......
......@@ -26,6 +26,7 @@ import org.chromium.chrome.browser.settings.ManagedPreferenceDelegate;
/**
* Autofill credit cards fragment, which allows the user to edit credit cards and control
* payment apps.
* TODO(crbug.com/949269): Add tests for AutofillProfilesFragment.
*/
public class AutofillPaymentMethodsFragment extends PreferenceFragmentCompat
implements PersonalDataManager.PersonalDataManagerObserver {
......@@ -79,6 +80,20 @@ public class AutofillPaymentMethodsFragment extends PreferenceFragmentCompat
});
getPreferenceScreen().addPreference(autofillSwitch);
if (PersonalDataManager.getInstance().isFidoAuthenticationAvailable()) {
// TODO(crbug.com/949269): Add FingerPrint availability check.
ChromeSwitchPreference fidoAuthSwitch =
new ChromeSwitchPreference(getStyledContext(), null);
fidoAuthSwitch.setTitle(R.string.enable_credit_card_fido_auth_label);
fidoAuthSwitch.setSummary(R.string.enable_credit_card_fido_auth_sublabel);
fidoAuthSwitch.setChecked(PersonalDataManager.isAutofillCreditCardFidoAuthEnabled());
fidoAuthSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
PersonalDataManager.setAutofillCreditCardFidoAuthEnabled((boolean) newValue);
return true;
});
getPreferenceScreen().addPreference(fidoAuthSwitch);
}
for (CreditCard card : PersonalDataManager.getInstance().getCreditCardsForSettings()) {
// Add a preference for the credit card.
Preference card_pref = new Preference(getStyledContext());
......
......@@ -68,6 +68,7 @@ enum Pref {
WEBKIT_PASSWORD_ECHO_ENABLED,
WEBKIT_FORCE_DARK_MODE_ENABLED,
HOME_PAGE,
AUTOFILL_CREDIT_CARD_FIDO_AUTH_ENABLED,
// PREF_NUM_PREFS must be the last entry.
PREF_NUM_PREFS
};
......@@ -121,6 +122,7 @@ const char* const kPrefsExposedToJava[] = {
prefs::kWebKitPasswordEchoEnabled,
prefs::kWebKitForceDarkModeEnabled,
prefs::kHomePage,
autofill::prefs::kAutofillCreditCardFidoAuthEnabled,
};
#endif // CHROME_BROWSER_ANDROID_PREFERENCES_PREFS_H_
......@@ -107,6 +107,8 @@ TEST_F(PrefsTest, TestIndex) {
EXPECT_EQ(prefs::kWebKitForceDarkModeEnabled,
GetPrefName(WEBKIT_FORCE_DARK_MODE_ENABLED));
EXPECT_EQ(prefs::kHomePage, GetPrefName(HOME_PAGE));
EXPECT_EQ(autofill::prefs::kAutofillCreditCardFidoAuthEnabled,
GetPrefName(AUTOFILL_CREDIT_CARD_FIDO_AUTH_ENABLED));
// If this check fails, a pref is missing a test case above.
EXPECT_EQ(Pref::PREF_NUM_PREFS, pref_count_);
......
......@@ -38,8 +38,10 @@
#include "components/autofill/core/browser/geo/country_names.h"
#include "components/autofill/core/browser/payments/full_card_request.h"
#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/autofill/core/browser/sync_utils.h"
#include "components/autofill/core/browser/validation.h"
#include "components/autofill/core/common/autofill_constants.h"
#include "components/autofill/core/common/autofill_payments_features.h"
#include "components/autofill/core/common/autofill_prefs.h"
#include "components/autofill/core/common/autofill_switches.h"
#include "components/prefs/pref_service.h"
......@@ -747,6 +749,21 @@ jboolean PersonalDataManagerAndroid::HasCreditCards(JNIEnv* env) {
return !personal_data_manager_->GetCreditCards().empty();
}
jboolean PersonalDataManagerAndroid::IsFidoAuthenticationAvailable(
JNIEnv* env) {
// Don't show toggle switch if user is unable to downstream cards.
if (personal_data_manager_->GetSyncSigninState() !=
autofill::AutofillSyncSigninState::
kSignedInAndWalletSyncTransportEnabled &&
personal_data_manager_->GetSyncSigninState() !=
autofill::AutofillSyncSigninState::kSignedInAndSyncFeatureEnabled) {
return false;
}
// Show the toggle switch only if the authentication flag is enabled.
return base::FeatureList::IsEnabled(
autofill::features::kAutofillCreditCardAuthentication);
}
void PersonalDataManagerAndroid::StartRegionSubKeysRequest(
JNIEnv* env,
const JavaParamRef<jobject>& unused_obj,
......
......@@ -330,6 +330,9 @@ class PersonalDataManagerAndroid : public PersonalDataManagerObserver {
// Checks whether the Autofill PersonalDataManager has credit cards.
jboolean HasCreditCards(JNIEnv* env);
// Checks whether FIDO authentication is available.
jboolean IsFidoAuthenticationAvailable(JNIEnv* env);
// Gets the subkeys for the region with |jregion_code| code, if the
// |jregion_code| rules have finished loading. Otherwise, sets up a task to
// get the subkeys, when the rules are loaded.
......
......@@ -242,10 +242,10 @@
</message>
</if>
<if expr="is_android">
<message name="IDS_ENABLE_CREDIT_CARD_FIDO_AUTH_LABEL" desc="The authentication mechanism on Android. Label for a toggle that allows users to control whether or not to use FIDO authentication for credit card unmasking. Title-Cased.">
<message name="IDS_ENABLE_CREDIT_CARD_FIDO_AUTH_LABEL" desc="The authentication mechanism on Android. Label for a toggle that allows users to control whether or not to use FIDO authentication for credit card unmasking. Title-Cased." formatter_data="android_java">
Screen lock
</message>
<message name="IDS_ENABLE_CREDIT_CARD_FIDO_AUTH_SUBLABEL" desc="Sublabel for a toggle that allows users to control whether or not to use FIDO authentication for credit card unmasking for Android. Sentence-Cased.">
<message name="IDS_ENABLE_CREDIT_CARD_FIDO_AUTH_SUBLABEL" desc="Sublabel for a toggle that allows users to control whether or not to use FIDO authentication for credit card unmasking for Android. Sentence-Cased." formatter_data="android_java">
Use screen lock to confirm cards faster
</message>
</if>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment