Commit f7714ff8 authored by Fabio Tirelo's avatar Fabio Tirelo Committed by Commit Bot

[Autofill] Add Autofill profile and payment methods settings on Android

This CL replicates on Android the following changes already done on
other platforms:
 - Replace the Autofill toggle with two new toggles, one for credit
   cards and one for addresses, and add them to the corresponding
   pages in Settings;
 - Update the strings for titles, toggles, and toggle descriptions;
 - Delete deprecated strings.

This takes up crrev.com/c/1135514, which was abandoned. Comments
initially added there have also been addressed here.

A follow-up CL will get rid of the "Autofill and payments" page
and move the "Addresses" and "Payments" page to the top Settings
page.

Screenshots and video (Googlers only): https://drive.google.com/open?id=1ZZr2lbX9q48DAxiTSVq6dZCImchqz-yA

Bug: 860526
Change-Id: I613f3badfb655532228ee1b6b6029eac06f1d42f
Reviewed-on: https://chromium-review.googlesource.com/1194474
Commit-Queue: Fabio Tirelo <ftirelo@chromium.org>
Reviewed-by: default avatarMoe Ahmadi <mahmadi@chromium.org>
Reviewed-by: default avatarMathieu Perreault <mathp@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#587770}
parent e7344594
......@@ -5,16 +5,14 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<org.chromium.chrome.browser.preferences.ChromeSwitchPreference
android:key="autofill_switch"
android:title="@string/autofill_switch" />
<org.chromium.chrome.browser.preferences.ChromeBasePreference
android:title="@string/autofill_addresses_settings_title"
android:fragment="org.chromium.chrome.browser.preferences.autofill.AutofillProfilesFragment"
android:key="autofill_addresses" />
<Preference
android:title="@string/autofill_profiles_title"
android:fragment="org.chromium.chrome.browser.preferences.autofill.AutofillProfilesFragment" />
<Preference
android:title="@string/autofill_credit_cards_title"
android:fragment="org.chromium.chrome.browser.preferences.autofill.AutofillCreditCardsFragment" />
<org.chromium.chrome.browser.preferences.ChromeBasePreference
android:title="@string/autofill_payment_methods"
android:fragment="org.chromium.chrome.browser.preferences.autofill.AutofillCreditCardsFragment"
android:key="autofill_payment_methods" />
</PreferenceScreen>
\ No newline at end of file
......@@ -12,6 +12,7 @@ import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ResourceId;
import org.chromium.chrome.browser.preferences.Pref;
import org.chromium.chrome.browser.preferences.autofill.AutofillAndPaymentsPreferences;
import org.chromium.content_public.browser.WebContents;
......@@ -908,18 +909,33 @@ public class PersonalDataManager {
}
/**
* @return Whether the Autofill feature is enabled.
* @return Whether the Autofill feature for Profiles (addresses) is enabled.
*/
public static boolean isAutofillEnabled() {
return nativeIsAutofillEnabled();
public static boolean isAutofillProfileEnabled() {
return nativeGetPref(Pref.AUTOFILL_PROFILE_ENABLED);
}
/**
* Enables or disables the Autofill feature.
* @param enable True to disable Autofill, false otherwise.
* @return Whether the Autofill feature for Credit Cards is enabled.
*/
public static void setAutofillEnabled(boolean enable) {
nativeSetAutofillEnabled(enable);
public static boolean isAutofillCreditCardEnabled() {
return nativeGetPref(Pref.AUTOFILL_CREDIT_CARD_ENABLED);
}
/**
* Enables or disables the Autofill feature for Profiles.
* @param enable True to disable profile Autofill, false otherwise.
*/
public static void setAutofillProfileEnabled(boolean enable) {
nativeSetPref(Pref.AUTOFILL_PROFILE_ENABLED, enable);
}
/**
* Enables or disables the Autofill feature for Credit Cards.
* @param enable True to disable credit card Autofill, false otherwise.
*/
public static void setAutofillCreditCardEnabled(boolean enable) {
nativeSetPref(Pref.AUTOFILL_CREDIT_CARD_ENABLED, enable);
}
/**
......@@ -929,6 +945,20 @@ public class PersonalDataManager {
return nativeIsAutofillManaged();
}
/**
* @return Whether the Autofill feature for Profiles (addresses) is managed.
*/
public static boolean isAutofillProfileManaged() {
return nativeIsAutofillProfileManaged();
}
/**
* @return Whether the Autofill feature for Credit Cards is managed.
*/
public static boolean isAutofillCreditCardManaged() {
return nativeIsAutofillCreditCardManaged();
}
/**
* @return Whether the Payments integration feature is enabled.
*/
......@@ -1030,13 +1060,15 @@ public class PersonalDataManager {
String regionCode, int timeoutSeconds, GetSubKeysRequestDelegate delegate);
private static native boolean nativeHasProfiles(long nativePersonalDataManagerAndroid);
private static native boolean nativeHasCreditCards(long nativePersonalDataManagerAndroid);
private static native boolean nativeIsAutofillEnabled();
private static native void nativeSetAutofillEnabled(boolean enable);
private static native boolean nativeIsAutofillManaged();
private static native boolean nativeIsAutofillProfileManaged();
private static native boolean nativeIsAutofillCreditCardManaged();
private static native boolean nativeIsPaymentsIntegrationEnabled();
private static native void nativeSetPaymentsIntegrationEnabled(boolean enable);
private static native String nativeToCountryCode(String countryName);
private static native void nativeCancelPendingGetSubKeys(long nativePersonalDataManagerAndroid);
private static native void nativeSetSyncServiceForTesting(
long nativePersonalDataManagerAndroid);
private static native boolean nativeGetPref(int preference);
private static native void nativeSetPref(int preference, boolean enable);
}
......@@ -274,7 +274,8 @@ public class MainPreferences extends PreferenceFragment
@Override
public boolean isPreferenceControlledByPolicy(Preference preference) {
if (PREF_AUTOFILL_SETTINGS.equals(preference.getKey())) {
return PersonalDataManager.isAutofillManaged();
return PersonalDataManager.isAutofillProfileManaged()
|| PersonalDataManager.isAutofillCreditCardManaged();
}
if (PREF_SAVED_PASSWORDS.equals(preference.getKey())) {
return PrefServiceBridge.getInstance().isRememberPasswordsManaged();
......@@ -291,8 +292,12 @@ public class MainPreferences extends PreferenceFragment
@Override
public boolean isPreferenceClickDisabledByPolicy(Preference preference) {
if (PREF_AUTOFILL_SETTINGS.equals(preference.getKey())) {
return PersonalDataManager.isAutofillManaged()
&& !PersonalDataManager.isAutofillEnabled();
// The whole "Autofill and payments" page is disabled by policy if profiles and
// credit cards are both disabled by policy.
return PersonalDataManager.isAutofillProfileManaged()
&& PersonalDataManager.isAutofillCreditCardManaged()
&& !PersonalDataManager.isAutofillProfileEnabled()
&& !PersonalDataManager.isAutofillCreditCardEnabled();
}
if (PREF_SAVED_PASSWORDS.equals(preference.getKey())) {
PrefServiceBridge prefs = PrefServiceBridge.getInstance();
......
......@@ -10,7 +10,8 @@ import android.content.Intent;
import org.chromium.base.ContextUtils;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.chrome.browser.preferences.autofill.AutofillAndPaymentsPreferences;
import org.chromium.chrome.browser.preferences.autofill.AutofillCreditCardsFragment;
import org.chromium.chrome.browser.preferences.autofill.AutofillProfilesFragment;
import org.chromium.chrome.browser.preferences.password.SavePasswordsPreferences;
import org.chromium.chrome.browser.preferences.privacy.ClearBrowsingDataTabsFragment;
import org.chromium.content_public.browser.WebContents;
......@@ -65,12 +66,13 @@ public class PreferencesLauncher {
}
@CalledByNative
private static void showAutofillSettings(WebContents webContents) {
WeakReference<Activity> currentActivity =
webContents.getTopLevelNativeWindow().getActivity();
private static void showAutofillProfileSettings(WebContents webContents) {
showSettingSubpage(webContents, AutofillProfilesFragment.class.getName());
}
launchSettingsPage(currentActivity.get(),
AutofillAndPaymentsPreferences.class.getName());
@CalledByNative
private static void showAutofillCreditCardSettings(WebContents webContents) {
showSettingSubpage(webContents, AutofillCreditCardsFragment.class.getName());
}
@CalledByNative
......@@ -78,4 +80,10 @@ public class PreferencesLauncher {
launchSettingsPage(
ContextUtils.getApplicationContext(), SavePasswordsPreferences.class.getName());
}
private static void showSettingSubpage(WebContents webContents, String className) {
WeakReference<Activity> currentActivity =
webContents.getTopLevelNativeWindow().getActivity();
launchSettingsPage(currentActivity.get(), className);
}
}
......@@ -6,7 +6,6 @@ package org.chromium.chrome.browser.preferences.autofill;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceFragment;
import org.chromium.chrome.R;
......@@ -14,7 +13,8 @@ import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.autofill.PersonalDataManager;
import org.chromium.chrome.browser.payments.AndroidPaymentAppFactory;
import org.chromium.chrome.browser.payments.ServiceWorkerPaymentAppBridge;
import org.chromium.chrome.browser.preferences.ChromeSwitchPreference;
import org.chromium.chrome.browser.preferences.ChromeBasePreference;
import org.chromium.chrome.browser.preferences.ManagedPreferenceDelegate;
import org.chromium.chrome.browser.preferences.PreferenceUtils;
/**
......@@ -27,25 +27,22 @@ public class AutofillAndPaymentsPreferences extends PreferenceFragment {
// Needs to be in sync with kSettingsOrigin[] in
// chrome/browser/ui/webui/options/autofill_options_handler.cc
public static final String SETTINGS_ORIGIN = "Chrome settings";
private static final String PREF_AUTOFILL_SWITCH = "autofill_switch";
private static final String AUTOFILL_ADDRESSES = "autofill_addresses";
private static final String AUTOFILL_PAYMENT_METHODS = "autofill_payment_methods";
private static final String PREF_PAYMENT_APPS = "payment_apps";
private final ManagedPreferenceDelegate mManagedPreferenceDelegate;
public AutofillAndPaymentsPreferences() {
mManagedPreferenceDelegate = createManagedPreferenceDelegate();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PreferenceUtils.addPreferencesFromResource(this, R.xml.autofill_and_payments_preferences);
getActivity().setTitle(R.string.prefs_autofill_and_payments);
ChromeSwitchPreference autofillSwitch =
(ChromeSwitchPreference) findPreference(PREF_AUTOFILL_SWITCH);
autofillSwitch.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
PersonalDataManager.setAutofillEnabled((boolean) newValue);
return true;
}
});
if (ChromeFeatureList.isEnabled(ChromeFeatureList.ANDROID_PAYMENT_APPS)
|| ChromeFeatureList.isEnabled(ChromeFeatureList.SERVICE_WORKER_PAYMENT_APPS)) {
Preference pref = new Preference(getActivity());
......@@ -55,14 +52,16 @@ public class AutofillAndPaymentsPreferences extends PreferenceFragment {
pref.setKey(PREF_PAYMENT_APPS);
getPreferenceScreen().addPreference(pref);
}
((ChromeBasePreference) findPreference(AUTOFILL_ADDRESSES))
.setManagedPreferenceDelegate(mManagedPreferenceDelegate);
((ChromeBasePreference) findPreference(AUTOFILL_PAYMENT_METHODS))
.setManagedPreferenceDelegate(mManagedPreferenceDelegate);
}
@Override
public void onResume() {
super.onResume();
((ChromeSwitchPreference) findPreference(PREF_AUTOFILL_SWITCH))
.setChecked(PersonalDataManager.isAutofillEnabled());
Preference pref = findPreference(PREF_PAYMENT_APPS);
if (pref != null) {
refreshPaymentAppsPrefForAndroidPaymentApps(pref);
......@@ -96,4 +95,37 @@ public class AutofillAndPaymentsPreferences extends PreferenceFragment {
pref.setEnabled(false);
}
}
ManagedPreferenceDelegate getManagedPreferenceDelegateForTest() {
return mManagedPreferenceDelegate;
}
private ManagedPreferenceDelegate createManagedPreferenceDelegate() {
return new ManagedPreferenceDelegate() {
@Override
public boolean isPreferenceControlledByPolicy(Preference preference) {
if (AUTOFILL_ADDRESSES.equals(preference.getKey())) {
return PersonalDataManager.isAutofillProfileManaged();
}
if (AUTOFILL_PAYMENT_METHODS.equals(preference.getKey())) {
return PersonalDataManager.isAutofillCreditCardManaged();
}
return false;
}
@Override
public boolean isPreferenceClickDisabledByPolicy(Preference preference) {
if (AUTOFILL_ADDRESSES.equals(preference.getKey())) {
return PersonalDataManager.isAutofillProfileManaged()
&& !PersonalDataManager.isAutofillProfileEnabled();
}
if (AUTOFILL_PAYMENT_METHODS.equals(preference.getKey())) {
return PersonalDataManager.isAutofillCreditCardManaged()
&& !PersonalDataManager.isAutofillCreditCardEnabled();
}
return isPreferenceControlledByPolicy(preference)
|| isPreferenceControlledByCustodian(preference);
}
};
}
}
......@@ -8,6 +8,7 @@ import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceFragment;
import android.support.v7.content.res.AppCompatResources;
......@@ -15,6 +16,7 @@ import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.autofill.PersonalDataManager;
import org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard;
import org.chromium.chrome.browser.preferences.ChromeSwitchPreference;
import org.chromium.chrome.browser.preferences.PreferenceUtils;
/**
......@@ -22,12 +24,15 @@ import org.chromium.chrome.browser.preferences.PreferenceUtils;
*/
public class AutofillCreditCardsFragment
extends PreferenceFragment implements PersonalDataManager.PersonalDataManagerObserver {
private static final String PREF_AUTOFILL_ENABLE_CREDIT_CARDS_TOGGLE_LABEL =
"autofill_enable_credit_cards_toggle_label";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PreferenceUtils.addPreferencesFromResource(
this, R.xml.autofill_and_payments_preference_fragment_screen);
getActivity().setTitle(R.string.autofill_credit_cards_title);
getActivity().setTitle(R.string.autofill_payment_methods);
}
@Override
......@@ -43,6 +48,21 @@ public class AutofillCreditCardsFragment
getPreferenceScreen().removeAll();
getPreferenceScreen().setOrderingAsAdded(true);
ChromeSwitchPreference autofillSwitch = new ChromeSwitchPreference(getActivity(), null);
autofillSwitch.setTitle(R.string.autofill_enable_credit_cards_toggle_label);
autofillSwitch.setSummary(
getActivity().getString(R.string.autofill_enable_credit_cards_toggle_sublabel));
autofillSwitch.setKey(PREF_AUTOFILL_ENABLE_CREDIT_CARDS_TOGGLE_LABEL); // For testing.
autofillSwitch.setChecked(PersonalDataManager.isAutofillCreditCardEnabled());
autofillSwitch.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
PersonalDataManager.setAutofillCreditCardEnabled((boolean) newValue);
return true;
}
});
getPreferenceScreen().addPreference(autofillSwitch);
for (CreditCard card : PersonalDataManager.getInstance().getCreditCardsForSettings()) {
// Add a preference for the credit card.
Preference pref = new Preference(getActivity());
......@@ -74,6 +94,7 @@ public class AutofillCreditCardsFragment
pref.setIcon(plusIcon);
pref.setTitle(R.string.autofill_create_credit_card);
pref.setFragment(AutofillLocalCardEditor.class.getName());
pref.setEnabled(PersonalDataManager.isAutofillCreditCardEnabled());
getPreferenceScreen().addPreference(pref);
}
......
......@@ -8,6 +8,7 @@ import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceFragment;
import android.support.annotation.VisibleForTesting;
......@@ -16,6 +17,7 @@ import org.chromium.base.StrictModeContext;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.autofill.PersonalDataManager;
import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile;
import org.chromium.chrome.browser.preferences.ChromeSwitchPreference;
import org.chromium.chrome.browser.preferences.PreferenceUtils;
import org.chromium.chrome.browser.widget.prefeditor.EditorObserverForTest;
......@@ -27,12 +29,15 @@ public class AutofillProfilesFragment
private static EditorObserverForTest sObserverForTest;
static final String PREF_NEW_PROFILE = "new_profile";
private static final String PREF_AUTOFILL_ENABLE_PROFILES_TOGGLE_LABEL =
"autofill_enable_profiles_toggle_label";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PreferenceUtils.addPreferencesFromResource(
this, R.xml.autofill_and_payments_preference_fragment_screen);
getActivity().setTitle(R.string.autofill_profiles_title);
getActivity().setTitle(R.string.autofill_addresses_settings_title);
}
@Override
......@@ -49,6 +54,20 @@ public class AutofillProfilesFragment
getPreferenceScreen().removeAll();
getPreferenceScreen().setOrderingAsAdded(true);
ChromeSwitchPreference autofillSwitch = new ChromeSwitchPreference(getActivity(), null);
autofillSwitch.setTitle(R.string.autofill_enable_profiles_toggle_label);
autofillSwitch.setSummary(R.string.autofill_enable_profiles_toggle_sublabel);
autofillSwitch.setKey(PREF_AUTOFILL_ENABLE_PROFILES_TOGGLE_LABEL); // For testing.
autofillSwitch.setChecked(PersonalDataManager.isAutofillProfileEnabled());
autofillSwitch.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
PersonalDataManager.setAutofillProfileEnabled((boolean) newValue);
return true;
}
});
getPreferenceScreen().addPreference(autofillSwitch);
for (AutofillProfile profile : PersonalDataManager.getInstance().getProfilesForSettings()) {
// Add a preference for the profile.
Preference pref;
......@@ -83,6 +102,7 @@ public class AutofillProfilesFragment
pref.setIcon(plusIcon);
pref.setTitle(R.string.autofill_create_profile);
pref.setKey(PREF_NEW_PROFILE); // For testing.
pref.setEnabled(PersonalDataManager.isAutofillProfileEnabled());
try (StrictModeContext unused = StrictModeContext.allowDiskWrites()) {
getPreferenceScreen().addPreference(pref);
......
......@@ -417,12 +417,6 @@ CHAR-LIMIT guidelines:
<message name="IDS_PREFS_AUTOFILL_AND_PAYMENTS" desc="Title of Autofill and payments settings prefrences. [CHAR-LIMIT=32]">
Autofill and payments
</message>
<message name="IDS_AUTOFILL_SWITCH" desc="Title for 'Autofill forms' switch preference, which controls whether personal data can be automatically filled into web page forms. [CHAR-LIMIT=32]">
Autofill forms
</message>
<message name="IDS_AUTOFILL_PROFILES_TITLE" desc="Title of the preference to list profiles (which contain the user's name, address, etc) that can be automatically filled into web page forms. [CHAR-LIMIT=32]">
Addresses
</message>
<message name="IDS_PAYMENT_APPS_TITLE" desc="Title of the preference to list the payment apps on device.">
Payment apps
</message>
......@@ -432,9 +426,6 @@ CHAR-LIMIT guidelines:
<message name="IDS_PAYMENT_APPS_USAGE_MESSAGE" desc="Message to explain the usage of the listed payment apps.">
On some websites, you can pay with above supported payment apps on your device.
</message>
<message name="IDS_AUTOFILL_CREDIT_CARDS_TITLE" desc="Title of the preference to list the user's cards that can be automatically filled into web page forms. These can be either credit, debit, or prepaid cards. [CHAR-LIMIT=32]">
Cards
</message>
<message name="IDS_AUTOFILL_CREATE_PROFILE" desc="Button that allows the user to create a new profile (which contains the user's name, address, etc) that will be automatically filled into web page forms. [CHAR-LIMIT=32]">
Add address
</message>
......
......@@ -70,7 +70,7 @@ public class AutofillProfilesFragmentTest {
(AutofillProfilesFragment) activity.getFragmentForTest();
// Check the preferences on the initial screen.
Assert.assertEquals(5 /* One add button + four profiles. */,
Assert.assertEquals(6 /* One toggle + one add button + four profiles. */,
autofillProfileFragment.getPreferenceScreen().getPreferenceCount());
PreferenceFragment fragment = (PreferenceFragment) activity.getFragmentForTest();
AutofillProfileEditorPreference addProfile =
......@@ -96,7 +96,7 @@ public class AutofillProfilesFragmentTest {
});
// Check if the preferences are updated correctly.
rule.waitForThePreferenceUpdate();
Assert.assertEquals(6 /* One add button + five profiles. */,
Assert.assertEquals(7 /* One toggle + one add button + five profiles. */,
autofillProfileFragment.getPreferenceScreen().getPreferenceCount());
AutofillProfileEditorPreference addedProfile =
(AutofillProfileEditorPreference) fragment.findPreference("Alice Doe");
......@@ -116,7 +116,7 @@ public class AutofillProfilesFragmentTest {
(AutofillProfilesFragment) activity.getFragmentForTest();
// Check the preferences on the initial screen.
Assert.assertEquals(5 /* One add button + four profiles. */,
Assert.assertEquals(6 /* One toggle + one add button + four profiles. */,
autofillProfileFragment.getPreferenceScreen().getPreferenceCount());
PreferenceFragment fragment = (PreferenceFragment) activity.getFragmentForTest();
AutofillProfileEditorPreference addProfile =
......@@ -158,7 +158,7 @@ public class AutofillProfilesFragmentTest {
(AutofillProfilesFragment) activity.getFragmentForTest();
// Check the preferences on the initial screen.
Assert.assertEquals(5 /* One add button + four profiles. */,
Assert.assertEquals(6 /* One toggle + one add button + four profiles. */,
autofillProfileFragment.getPreferenceScreen().getPreferenceCount());
PreferenceFragment fragment = (PreferenceFragment) activity.getFragmentForTest();
AutofillProfileEditorPreference sebProfile =
......@@ -182,7 +182,7 @@ public class AutofillProfilesFragmentTest {
});
// Check if the preferences are updated correctly.
rule.waitForThePreferenceUpdate();
Assert.assertEquals(4 /* One add button + three profile. */,
Assert.assertEquals(5 /* One toggle + one add button + three profile. */,
autofillProfileFragment.getPreferenceScreen().getPreferenceCount());
AutofillProfileEditorPreference remainedProfile =
(AutofillProfileEditorPreference) fragment.findPreference("John Doe");
......@@ -204,7 +204,7 @@ public class AutofillProfilesFragmentTest {
(AutofillProfilesFragment) activity.getFragmentForTest();
// Check the preferences on the initial screen.
Assert.assertEquals(5 /* One add button + four profiles. */,
Assert.assertEquals(6 /* One toggle + one add button + four profiles. */,
autofillProfileFragment.getPreferenceScreen().getPreferenceCount());
PreferenceFragment fragment = (PreferenceFragment) activity.getFragmentForTest();
AutofillProfileEditorPreference johnProfile =
......@@ -231,7 +231,7 @@ public class AutofillProfilesFragmentTest {
});
// Check if the preferences are updated correctly.
rule.waitForThePreferenceUpdate();
Assert.assertEquals(5 /* One add button + four profiles. */,
Assert.assertEquals(6 /* One toggle + one add button + four profiles. */,
autofillProfileFragment.getPreferenceScreen().getPreferenceCount());
AutofillProfileEditorPreference editedProfile =
(AutofillProfileEditorPreference) fragment.findPreference("Emily Doe");
......@@ -254,7 +254,7 @@ public class AutofillProfilesFragmentTest {
(AutofillProfilesFragment) activity.getFragmentForTest();
// Check the preferences on the initial screen.
Assert.assertEquals(5 /* One add button + four profiles. */,
Assert.assertEquals(6 /* One toggle + one add button + four profiles. */,
autofillProfileFragment.getPreferenceScreen().getPreferenceCount());
PreferenceFragment fragment = (PreferenceFragment) activity.getFragmentForTest();
AutofillProfileEditorPreference bobProfile =
......@@ -274,7 +274,7 @@ public class AutofillProfilesFragmentTest {
}
});
rule.waitForThePreferenceUpdate();
Assert.assertEquals(5 /* One add button + four profiles. */,
Assert.assertEquals(6 /* One toggle + one add button + four profiles. */,
autofillProfileFragment.getPreferenceScreen().getPreferenceCount());
activity.finish();
}
......@@ -290,7 +290,7 @@ public class AutofillProfilesFragmentTest {
(AutofillProfilesFragment) activity.getFragmentForTest();
// Check the preferences on the initial screen.
Assert.assertEquals(5 /* One add button + four profiles. */,
Assert.assertEquals(6 /* One toggle + one add button + four profiles. */,
autofillProfileFragment.getPreferenceScreen().getPreferenceCount());
PreferenceFragment fragment = (PreferenceFragment) activity.getFragmentForTest();
AutofillProfileEditorPreference billProfile =
......@@ -311,7 +311,7 @@ public class AutofillProfilesFragmentTest {
});
// Check if the preferences are updated correctly.
rule.waitForThePreferenceUpdate();
Assert.assertEquals(5 /* One add button + four profiles. */,
Assert.assertEquals(6 /* One toggle + one add button + four profiles. */,
autofillProfileFragment.getPreferenceScreen().getPreferenceCount());
}
......
......@@ -12,9 +12,15 @@
namespace chrome {
namespace android {
void PreferencesLauncher::ShowAutofillSettings(
void PreferencesLauncher::ShowAutofillProfileSettings(
content::WebContents* web_contents) {
Java_PreferencesLauncher_showAutofillSettings(
Java_PreferencesLauncher_showAutofillProfileSettings(
base::android::AttachCurrentThread(), web_contents->GetJavaWebContents());
}
void PreferencesLauncher::ShowAutofillCreditCardSettings(
content::WebContents* web_contents) {
Java_PreferencesLauncher_showAutofillCreditCardSettings(
base::android::AttachCurrentThread(), web_contents->GetJavaWebContents());
}
......
......@@ -16,8 +16,12 @@ namespace android {
class PreferencesLauncher {
public:
// Opens the autofill settings page.
static void ShowAutofillSettings(content::WebContents* web_contents);
// Opens the autofill settings page for profiles.
static void ShowAutofillProfileSettings(content::WebContents* web_contents);
// Opens the autofill settings page for credit cards.
static void ShowAutofillCreditCardSettings(
content::WebContents* web_contents);
// Opens the password settings page.
static void ShowPasswordSettings();
......
......@@ -10,6 +10,7 @@
#include "build/build_config.h"
#include "chrome/browser/android/contextual_suggestions/contextual_suggestions_prefs.h"
#include "chrome/common/pref_names.h"
#include "components/autofill/core/common/autofill_prefs.h"
#include "components/dom_distiller/core/pref_names.h"
#include "components/ntp_snippets/pref_names.h"
#include "components/payments/core/payment_prefs.h"
......@@ -28,6 +29,8 @@ enum Pref {
SHOW_MISSING_SD_CARD_ERROR_ANDROID,
CAN_MAKE_PAYMENT_ENABLED,
CONTEXTUAL_SEARCH_ENABLED,
AUTOFILL_PROFILE_ENABLED,
AUTOFILL_CREDIT_CARD_ENABLED,
// PREF_NUM_PREFS must be the last entry.
PREF_NUM_PREFS
};
......@@ -44,6 +47,8 @@ const char* const kPrefsExposedToJava[] = {
prefs::kPromptForDownloadAndroid,
prefs::kShowMissingSdCardErrorAndroid,
payments::kCanMakePaymentEnabled,
prefs::kContextualSearchEnabled};
prefs::kContextualSearchEnabled,
autofill::prefs::kAutofillProfileEnabled,
autofill::prefs::kAutofillCreditCardEnabled};
#endif // CHROME_BROWSER_ANDROID_PREFERENCES_PREFS_H_
......@@ -48,6 +48,10 @@ TEST_F(PrefsTest, TestIndex) {
GetPrefName(CAN_MAKE_PAYMENT_ENABLED));
EXPECT_EQ(prefs::kContextualSearchEnabled,
GetPrefName(CONTEXTUAL_SEARCH_ENABLED));
EXPECT_EQ(autofill::prefs::kAutofillProfileEnabled,
GetPrefName(AUTOFILL_PROFILE_ENABLED));
EXPECT_EQ(autofill::prefs::kAutofillCreditCardEnabled,
GetPrefName(AUTOFILL_CREDIT_CARD_ENABLED));
// If this check fails, a pref is missing a test case above.
EXPECT_EQ(Pref::PREF_NUM_PREFS, pref_count_);
......
......@@ -15,6 +15,7 @@
#include "base/format_macros.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "chrome/browser/android/preferences/prefs.h"
#include "chrome/browser/android/resource_mapper.h"
#include "chrome/browser/autofill/address_normalizer_factory.h"
#include "chrome/browser/autofill/personal_data_manager_factory.h"
......@@ -856,19 +857,23 @@ PersonalDataManagerAndroid::GetShippingAddressLabelForPaymentRequest(
g_browser_process->GetApplicationLocale()));
}
// Returns whether the Autofill feature is enabled.
static jboolean JNI_PersonalDataManager_IsAutofillEnabled(
// Returns whether the specified feature is enabled.
static jboolean JNI_PersonalDataManager_GetPref(
JNIEnv* env,
const JavaParamRef<jclass>& clazz) {
return prefs::IsAutofillEnabled(GetPrefs());
const JavaParamRef<jclass>& clazz,
const jint j_pref_index) {
return GetPrefs()->GetBoolean(
PersonalDataManagerAndroid::GetPrefNameExposedToJava(j_pref_index));
}
// Enables or disables the Autofill feature.
static void JNI_PersonalDataManager_SetAutofillEnabled(
JNIEnv* env,
const JavaParamRef<jclass>& clazz,
jboolean enable) {
prefs::SetAutofillEnabled(GetPrefs(), enable);
// Enables or disables the specified feature for profiles.
static void JNI_PersonalDataManager_SetPref(JNIEnv* env,
const JavaParamRef<jclass>& clazz,
const jint j_pref_index,
const jboolean j_enable) {
return GetPrefs()->SetBoolean(
PersonalDataManagerAndroid::GetPrefNameExposedToJava(j_pref_index),
j_enable);
}
// Returns whether the Autofill feature is managed.
......@@ -878,6 +883,20 @@ static jboolean JNI_PersonalDataManager_IsAutofillManaged(
return prefs::IsAutofillManaged(GetPrefs());
}
// Returns whether the Autofill feature for profiles is managed.
static jboolean JNI_PersonalDataManager_IsAutofillProfileManaged(
JNIEnv* env,
const JavaParamRef<jclass>& clazz) {
return prefs::IsProfileAutofillManaged(GetPrefs());
}
// Returns whether the Autofill feature for credit cards is managed.
static jboolean JNI_PersonalDataManager_IsAutofillCreditCardManaged(
JNIEnv* env,
const JavaParamRef<jclass>& clazz) {
return prefs::IsCreditCardAutofillManaged(GetPrefs());
}
// Returns whether the Payments integration feature is enabled.
static jboolean JNI_PersonalDataManager_IsPaymentsIntegrationEnabled(
JNIEnv* env,
......@@ -911,4 +930,11 @@ static jlong JNI_PersonalDataManager_Init(JNIEnv* env,
return reinterpret_cast<intptr_t>(personal_data_manager_android);
}
const char* PersonalDataManagerAndroid::GetPrefNameExposedToJava(
int pref_index) {
DCHECK_GE(pref_index, 0);
DCHECK_LT(pref_index, Pref::PREF_NUM_PREFS);
return kPrefsExposedToJava[pref_index];
}
} // namespace autofill
......@@ -338,6 +338,8 @@ class PersonalDataManagerAndroid : public PersonalDataManagerObserver {
JNIEnv* env,
const base::android::JavaParamRef<jobject>& unused_obj);
static const char* GetPrefNameExposedToJava(int pref_index);
private:
~PersonalDataManagerAndroid() override;
......
......@@ -171,7 +171,13 @@ ChromeAutofillClient::GetSecurityLevelForUmaHistograms() {
void ChromeAutofillClient::ShowAutofillSettings(
bool show_credit_card_settings) {
#if defined(OS_ANDROID)
chrome::android::PreferencesLauncher::ShowAutofillSettings(web_contents());
if (show_credit_card_settings) {
chrome::android::PreferencesLauncher::ShowAutofillCreditCardSettings(
web_contents());
} else {
chrome::android::PreferencesLauncher::ShowAutofillProfileSettings(
web_contents());
}
#else
Browser* browser = chrome::FindBrowserWithWebContents(web_contents());
if (browser) {
......
......@@ -153,6 +153,14 @@ bool IsAutofillManaged(const PrefService* prefs) {
return prefs->IsManagedPreference(kAutofillEnabledDeprecated);
}
bool IsProfileAutofillManaged(const PrefService* prefs) {
return prefs->IsManagedPreference(kAutofillProfileEnabled);
}
bool IsCreditCardAutofillManaged(const PrefService* prefs) {
return prefs->IsManagedPreference(kAutofillCreditCardEnabled);
}
bool IsProfileAutofillEnabled(const PrefService* prefs) {
return prefs->GetBoolean(kAutofillProfileEnabled);
}
......
......@@ -59,6 +59,10 @@ void SetAutofillEnabled(PrefService* prefs, bool enabled);
bool IsAutofillManaged(const PrefService* prefs);
bool IsProfileAutofillManaged(const PrefService* prefs);
bool IsCreditCardAutofillManaged(const PrefService* prefs);
bool IsProfileAutofillEnabled(const PrefService* prefs);
void SetProfileAutofillEnabled(PrefService* prefs, bool enabled);
......
......@@ -433,24 +433,24 @@
<message name="IDS_AUTOFILL_ADDRESSES" desc="Title for the list of addresses that chrome has saved for use in filling in forms.">
Addresses
</message>
<message name="IDS_AUTOFILL_ENABLE_PROFILES_TOGGLE_SUBLABEL" desc="Sublabel for a toggle that allows users to control whether addresses should be saved and forms should be autofilled with them.">
<message name="IDS_AUTOFILL_ENABLE_PROFILES_TOGGLE_SUBLABEL" desc="Sublabel for a toggle that allows users to control whether addresses should be saved and forms should be autofilled with them." formatter_data="android_java">
Includes information like phone numbers, email addresses, and shipping addresses
</message>
<message name="IDS_AUTOFILL_ENABLE_CREDIT_CARDS_TOGGLE_SUBLABEL" desc="Sublabel for a toggle that allows users to control whether credit cards should be saved and forms should be autofilled with it.">
<message name="IDS_AUTOFILL_ENABLE_CREDIT_CARDS_TOGGLE_SUBLABEL" desc="Sublabel for a toggle that allows users to control whether credit cards should be saved and forms should be autofilled with it." formatter_data="android_java">
Makes it faster to pay for things online
</message>
<if expr="not is_ios">
<then>
<message name="IDS_AUTOFILL_ADDRESSES_SETTINGS_TITLE" desc="Title for the Autofill settings page that allows user to manage their list of saved addresses and Autofill preferences for addresses. Sentence-Cased.">
<message name="IDS_AUTOFILL_ADDRESSES_SETTINGS_TITLE" desc="Title for the Autofill settings page that allows user to manage their list of saved addresses and Autofill preferences for addresses. Sentence-Cased." formatter_data="android_java">
Addresses and more
</message>
<message name="IDS_AUTOFILL_PAYMENT_METHODS" desc="Title for the list of saved payment methods that can be used to fill in forms. Also used as the title for the Autofill settings page that allows user to manage their list of saved payment methods and Autofill preferences for payment methods. Sentence-Cased.">
<message name="IDS_AUTOFILL_PAYMENT_METHODS" desc="Title for the list of saved payment methods that can be used to fill in forms. Also used as the title for the Autofill settings page that allows user to manage their list of saved payment methods and Autofill preferences for payment methods. Sentence-Cased." formatter_data="android_java">
Payment methods
</message>
<message name="IDS_AUTOFILL_ENABLE_PROFILES_TOGGLE_LABEL" desc="Label for a toggle that allows users to control whether addresses should be saved and forms should be autofilled with them. Sentence-Cased.">
<message name="IDS_AUTOFILL_ENABLE_PROFILES_TOGGLE_LABEL" desc="Label for a toggle that allows users to control whether addresses should be saved and forms should be autofilled with them. Sentence-Cased." formatter_data="android_java">
Remember addresses and other information
</message>
<message name="IDS_AUTOFILL_ENABLE_CREDIT_CARDS_TOGGLE_LABEL" desc="Label for a toggle that allows users to control whether credit cards should be saved and forms should be autofilled with it. Sentence-Cased.">
<message name="IDS_AUTOFILL_ENABLE_CREDIT_CARDS_TOGGLE_LABEL" desc="Label for a toggle that allows users to control whether credit cards should be saved and forms should be autofilled with it. Sentence-Cased." formatter_data="android_java">
Remember payment methods
</message>
</then>
......
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