From 6e4060fa5a3cbeb35ec6a0bc72f927a73b0d5571 Mon Sep 17 00:00:00 2001 From: Sebastian Kaspari Date: Fri, 16 Jul 2021 16:10:36 +0200 Subject: [PATCH] [fenix] Add preference for enabling/disabling Android Autofill from within the app. --- .../SettingsSubMenuLoginsAndPasswordRobot.kt | 2 +- .../java/org/mozilla/fenix/FeatureFlags.kt | 8 ++++++++ .../fragment/SavedLoginsAuthFragment.kt | 19 ++++++++++++++++++- app/src/main/res/values/preference_keys.xml | 1 + app/src/main/res/values/strings.xml | 9 +++++++++ app/src/main/res/xml/logins_preferences.xml | 7 ++++++- 6 files changed, 43 insertions(+), 3 deletions(-) diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuLoginsAndPasswordRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuLoginsAndPasswordRobot.kt index 5db63ad9b4..06934b2825 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuLoginsAndPasswordRobot.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuLoginsAndPasswordRobot.kt @@ -97,7 +97,7 @@ private fun goBackButton() = private fun assertDefaultView() = onView(ViewMatchers.withText("Sync logins across devices")) .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))) -private fun assertDefaultValueAutofillLogins() = onView(ViewMatchers.withText("Autofill")) +private fun assertDefaultValueAutofillLogins() = onView(ViewMatchers.withText("Autofill websites")) .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))) private fun assertDefaultValueExceptions() = onView(ViewMatchers.withText("Exceptions")) diff --git a/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt b/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt index 94522769e4..09575a41ef 100644 --- a/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt +++ b/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt @@ -58,4 +58,12 @@ object FeatureFlags { * Identifies and separates the tabs list with a secondary section containing least used tabs. */ val inactiveTabs = Config.channel.isNightlyOrDebug + + /** + * Enables support for Android Autofill. + * + * In addition to toggling this flag, matching entries in the Android Manifest of the build + * type need to present. + */ + val androidAutofill = Config.channel.isNightlyOrDebug } diff --git a/app/src/main/java/org/mozilla/fenix/settings/logins/fragment/SavedLoginsAuthFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/logins/fragment/SavedLoginsAuthFragment.kt index 10016dccd3..b139a53ece 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/logins/fragment/SavedLoginsAuthFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/logins/fragment/SavedLoginsAuthFragment.kt @@ -22,8 +22,10 @@ import androidx.preference.SwitchPreference import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.delay import kotlinx.coroutines.launch +import mozilla.components.feature.autofill.preference.AutofillPreference import mozilla.components.service.fxa.SyncEngine import mozilla.components.support.base.feature.ViewBoundFeatureWrapper +import org.mozilla.fenix.FeatureFlags import org.mozilla.fenix.R import org.mozilla.fenix.components.metrics.Event import org.mozilla.fenix.ext.components @@ -39,7 +41,6 @@ import org.mozilla.fenix.settings.requirePreference @Suppress("TooManyFunctions") class SavedLoginsAuthFragment : PreferenceFragmentCompat() { - private val biometricPromptFeature = ViewBoundFeatureWrapper() override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { @@ -99,6 +100,14 @@ class SavedLoginsAuthFragment : PreferenceFragmentCompat() { } } + requirePreference(R.string.pref_key_android_autofill).apply { + update() + + if (!FeatureFlags.androidAutofill) { + isVisible = false + } + } + requirePreference(R.string.pref_key_login_exceptions).apply { setOnPreferenceClickListener { navigateToLoginExceptionFragment() @@ -107,6 +116,14 @@ class SavedLoginsAuthFragment : PreferenceFragmentCompat() { } requirePreference(R.string.pref_key_autofill_logins).apply { + title = context.getString( + R.string.preferences_passwords_autofill2, + getString(R.string.app_name) + ) + summary = context.getString( + R.string.preferences_passwords_autofill_description, + getString(R.string.app_name) + ) isChecked = context.settings().shouldAutofillLogins onPreferenceChangeListener = object : SharedPreferenceUpdater() { override fun onPreferenceChange(preference: Preference, newValue: Any?): Boolean { diff --git a/app/src/main/res/values/preference_keys.xml b/app/src/main/res/values/preference_keys.xml index b3fe9a513c..88eb4fafeb 100644 --- a/app/src/main/res/values/preference_keys.xml +++ b/app/src/main/res/values/preference_keys.xml @@ -169,6 +169,7 @@ pref_key_save_logins_settings pref_key_save_logins pref_key_autofill_logins + pref_key_android_autofill pref_key_never_save_logins pref_key_saved_logins pref_key_password_sync_logins diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f5ba7dea17..4e09e2dcc3 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1457,6 +1457,15 @@ Never save Autofill + + Autofill in %1$s + + Fill and save usernames and passwords in websites while using %1$s. + + Autofill in other apps + + Fill usernames and passwords in other apps on your device. + Sync logins diff --git a/app/src/main/res/xml/logins_preferences.xml b/app/src/main/res/xml/logins_preferences.xml index 608a233038..8545bc9160 100644 --- a/app/src/main/res/xml/logins_preferences.xml +++ b/app/src/main/res/xml/logins_preferences.xml @@ -11,7 +11,12 @@ + android:title="@string/preferences_passwords_autofill2" + android:summary="@string/preferences_passwords_autofill_description" /> +