For #18376: Add experiment for set default browser settings card.

upstream-sync
mcarare 3 years ago committed by Mihai Adrian Carare
parent dbae5dd3c0
commit 80d2bec150

@ -21,5 +21,6 @@ class ExperimentBranch {
const val A2 = "a2"
const val DEFAULT_BROWSER_TOOLBAR_MENU = "default_browser_toolbar_menu"
const val DEFAULT_BROWSER_NEW_TAB_BANNER = "default_browser_newtab_banner"
const val DEFAULT_BROWSER_SETTINGS_MENU = "default_browser_settings_menu"
}
}

@ -42,6 +42,8 @@ import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.FeatureFlags
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.experiments.ExperimentBranch
import org.mozilla.fenix.experiments.Experiments
import org.mozilla.fenix.ext.application
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.getPreferenceKey
@ -53,7 +55,9 @@ import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.ext.REQUEST_CODE_BROWSER_ROLE
import org.mozilla.fenix.ext.openSetDefaultBrowserOption
import org.mozilla.fenix.ext.showToolbar
import org.mozilla.fenix.ext.withExperiment
import org.mozilla.fenix.settings.account.AccountUiView
import org.mozilla.fenix.utils.BrowsersCache
import org.mozilla.fenix.utils.Settings
import kotlin.system.exitProcess
@ -137,15 +141,31 @@ class SettingsFragment : PreferenceFragmentCompat() {
}
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
val preferencesId = if (FeatureFlags.newIconSet) {
R.xml.preferences_without_icons
} else {
R.xml.preferences
}
val preferencesId = getPreferenceLayoutId()
setPreferencesFromResource(preferencesId, rootKey)
updateMakeDefaultBrowserPreference()
}
/**
* @return The preference layout to be used depending on flags and existing experiment branches.
* Note: Changing Settings screen before experiment is over requires changing all layouts.
*/
private fun getPreferenceLayoutId() =
if (isDefaultBrowserExperimentBranch() && !isFirefoxDefaultBrowser()) {
if (FeatureFlags.newIconSet) {
R.xml.preferences_without_icons_default_browser_experiment
} else {
R.xml.preferences_default_browser_experiment
}
} else {
if (FeatureFlags.newIconSet) {
R.xml.preferences_without_icons
} else {
R.xml.preferences
}
}
@SuppressLint("RestrictedApi")
override fun onResume() {
super.onResume()
@ -475,7 +495,9 @@ class SettingsFragment : PreferenceFragmentCompat() {
}
private fun updateMakeDefaultBrowserPreference() {
requirePreference<DefaultBrowserPreference>(R.string.pref_key_make_default_browser).updateSwitch()
if (!isDefaultBrowserExperimentBranch()) {
requirePreference<DefaultBrowserPreference>(R.string.pref_key_make_default_browser).updateSwitch()
}
}
private fun navigateFromSettings(directions: NavDirections) {
@ -579,6 +601,18 @@ class SettingsFragment : PreferenceFragmentCompat() {
}
}
private fun isDefaultBrowserExperimentBranch(): Boolean {
val experiments = context?.components?.analytics?.experiments
return experiments?.withExperiment(Experiments.DEFAULT_BROWSER) { experimentBranch ->
(experimentBranch == ExperimentBranch.DEFAULT_BROWSER_SETTINGS_MENU)
} == true
}
private fun isFirefoxDefaultBrowser(): Boolean {
val browsers = BrowsersCache.all(requireContext())
return browsers.isFirefoxDefaultBrowser
}
companion object {
private const val SCROLL_INDICATOR_DELAY = 10L
private const val FXA_SYNC_OVERRIDE_EXIT_DELAY = 2000L

@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
style="@style/OnboardingCardLightWithPadding"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp">
<ImageView
android:id="@+id/app_icon"
android:layout_width="32dp"
android:layout_height="32dp"
app:layout_constraintEnd_toStartOf="@id/description_text"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_firefox" />
<TextView
android:id="@+id/description_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginBottom="16dp"
android:text="@string/default_browser_experiment_card_text"
android:textAppearance="@style/Body14TextStyle"
app:layout_constraintBottom_toTopOf="@id/set_default_browser"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/app_icon"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/set_default_browser"
style="@style/PositiveButton"
android:layout_height="36dp"
android:background="@drawable/rounded_button_background"
android:clickable="false"
android:focusable="false"
android:text="@string/preferences_set_as_default_browser"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/description_text" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -0,0 +1,216 @@
<?xml version="1.0" encoding="utf-8"?><!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.preference.Preference
android:key="@string/pref_key_make_default_browser"
android:layout="@layout/default_browser_experiment_preference"
app:allowDividerBelow="false" />
<androidx.preference.SwitchPreference
android:defaultValue="true"
android:key="@string/pref_key_allow_domestic_china_fxa_server"
android:title="@string/preferences_allow_domestic_china_fxa_server" />
<androidx.preference.EditTextPreference
android:inputType="textUri"
android:key="@string/pref_key_override_fxa_server"
android:title="@string/preferences_override_fxa_server"
app:iconSpaceReserved="false"
app:isPreferenceVisible="false" />
<androidx.preference.EditTextPreference
android:inputType="textUri"
android:key="@string/pref_key_override_sync_tokenserver"
android:title="@string/preferences_override_sync_tokenserver"
app:iconSpaceReserved="false"
app:isPreferenceVisible="false" />
<androidx.preference.PreferenceCategory
android:layout="@layout/preference_cat_style"
android:title="@string/preferences_category_general"
app:iconSpaceReserved="false">
<androidx.preference.Preference
android:icon="@drawable/ic_search"
android:key="@string/pref_key_search_settings"
android:title="@string/preferences_search" />
<androidx.preference.Preference
android:icon="@drawable/ic_multiple_tabs"
android:key="@string/pref_key_tabs"
android:title="@string/preferences_tabs" />
<androidx.preference.Preference
android:icon="@drawable/ic_customize"
android:key="@string/pref_key_customize"
android:title="@string/preferences_customize" />
<androidx.preference.Preference
android:icon="@drawable/ic_login"
android:key="@string/pref_key_passwords"
android:title="@string/preferences_passwords_logins_and_passwords" />
<androidx.preference.Preference
android:icon="@drawable/ic_formfill"
android:key="@string/pref_key_credit_cards"
android:title="@string/preferences_credit_cards"
app:isPreferenceVisible="false" />
<androidx.preference.Preference
android:icon="@drawable/ic_accessibility"
android:key="@string/pref_key_accessibility"
android:title="@string/preferences_accessibility" />
<androidx.preference.Preference
android:icon="@drawable/ic_language"
android:key="@string/pref_key_language"
android:title="@string/preferences_language" />
</androidx.preference.PreferenceCategory>
<androidx.preference.PreferenceCategory
android:key="@string/pref_key_sign_in"
android:layout="@layout/preference_cat_style"
android:title="@string/preferences_category_account">
<androidx.preference.Preference
android:icon="@drawable/ic_account"
android:key="@string/pref_key_sign_in"
android:title="@string/preferences_sync"
app:allowDividerBelow="true"
app:iconSpaceReserved="false" />
</androidx.preference.PreferenceCategory>
<androidx.preference.PreferenceCategory
android:key="@string/pref_key_account_category"
android:layout="@layout/preference_cat_style"
android:title="@string/preferences_category_account"
app:isPreferenceVisible="false">
<org.mozilla.fenix.settings.account.AccountPreference
android:icon="@drawable/ic_account"
android:key="@string/pref_key_account" />
<org.mozilla.fenix.settings.account.AccountAuthErrorPreference
android:icon="@drawable/ic_account_warning"
android:key="@string/pref_key_account_auth_error" />
</androidx.preference.PreferenceCategory>
<androidx.preference.PreferenceCategory
android:layout="@layout/preference_cat_style"
android:title="@string/preferences_category_privacy_security"
app:iconSpaceReserved="false">
<androidx.preference.Preference
android:icon="@drawable/ic_private_browsing"
android:key="@string/pref_key_private_browsing"
android:title="@string/preferences_private_browsing_options" />
<androidx.preference.Preference
android:icon="@drawable/ic_tracking_protection_enabled"
android:key="@string/pref_key_tracking_protection_settings"
android:title="@string/preference_enhanced_tracking_protection" />
<androidx.preference.Preference
android:icon="@drawable/ic_permission"
android:key="@string/pref_key_site_permissions"
android:title="@string/preferences_site_permissions" />
<androidx.preference.Preference
android:icon="@drawable/ic_delete"
android:key="@string/pref_key_delete_browsing_data"
android:title="@string/preferences_delete_browsing_data" />
<androidx.preference.Preference
android:icon="@drawable/ic_exit"
android:key="@string/pref_key_delete_browsing_data_on_quit_preference"
android:title="@string/preferences_delete_browsing_data_on_quit" />
<androidx.preference.Preference
android:icon="@drawable/ic_notifications"
android:key="@string/pref_key_notifications"
android:title="@string/preferences_notifications" />
<androidx.preference.Preference
android:icon="@drawable/ic_data_collection"
android:key="@string/pref_key_data_choices"
android:title="@string/preferences_data_collection" />
</androidx.preference.PreferenceCategory>
<PreferenceCategory
android:key="@string/pref_key_advanced"
android:layout="@layout/preference_cat_style"
android:title="@string/preferences_category_advanced"
app:iconSpaceReserved="false">
<androidx.preference.Preference
android:icon="@drawable/ic_addons_extensions"
android:key="@string/pref_key_addons"
android:title="@string/preferences_addons" />
<androidx.preference.Preference
android:icon="@drawable/ic_addons_extensions"
android:key="@string/pref_key_override_amo_collection"
android:title="@string/preferences_customize_amo_collection" />
<androidx.preference.SwitchPreference
android:defaultValue="false"
android:icon="@drawable/ic_open_in_app"
android:key="@string/pref_key_open_links_in_external_app"
android:title="@string/preferences_open_links_in_apps" />
<androidx.preference.SwitchPreference
android:defaultValue="false"
android:icon="@drawable/ic_download"
android:key="@string/pref_key_external_download_manager"
android:title="@string/preferences_external_download_manager" />
<androidx.preference.SwitchPreference
android:defaultValue="true"
android:icon="@drawable/ic_info"
android:key="@string/pref_key_leakcanary"
android:title="@string/preference_leakcanary"
app:isPreferenceVisible="@bool/IS_DEBUG" />
<androidx.preference.SwitchPreference
android:defaultValue="false"
android:icon="@drawable/ic_energy"
android:key="@string/pref_key_remote_debugging"
android:title="@string/preferences_remote_debugging" />
</PreferenceCategory>
<androidx.preference.PreferenceCategory
android:layout="@layout/preference_cat_style"
android:title="@string/preferences_category_about"
app:iconSpaceReserved="false">
<androidx.preference.Preference
android:icon="@drawable/ic_bookmark_outline"
android:key="@string/pref_key_rate"
android:title="@string/preferences_rate" />
<androidx.preference.Preference
android:icon="@drawable/ic_info"
android:key="@string/pref_key_about"
android:title="@string/preferences_about" />
<androidx.preference.Preference
android:icon="@drawable/ic_info"
android:key="@string/pref_key_debug_settings"
android:title="@string/preferences_debug_settings"
app:isPreferenceVisible="false" />
<androidx.preference.Preference
android:icon="@drawable/ic_info"
android:key="@string/pref_key_secret_debug_info"
android:title="@string/preferences_debug_info"
app:isPreferenceVisible="false" />
<androidx.preference.Preference
android:icon="@drawable/ic_info"
android:key="@string/pref_key_nimbus_experiments"
android:title="@string/preferences_nimbus_experiments"
app:isPreferenceVisible="false" />
</androidx.preference.PreferenceCategory>
</androidx.preference.PreferenceScreen>

@ -0,0 +1,211 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<androidx.preference.PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.preference.Preference
android:key="@string/pref_key_make_default_browser"
android:layout="@layout/default_browser_experiment_preference"
app:allowDividerBelow="false" />
<androidx.preference.SwitchPreference
android:defaultValue="true"
android:key="@string/pref_key_allow_domestic_china_fxa_server"
android:title="@string/preferences_allow_domestic_china_fxa_server" />
<androidx.preference.EditTextPreference
android:inputType="textUri"
android:key="@string/pref_key_override_fxa_server"
android:title="@string/preferences_override_fxa_server"
app:iconSpaceReserved="false"
app:isPreferenceVisible="false" />
<androidx.preference.EditTextPreference
android:inputType="textUri"
android:key="@string/pref_key_override_sync_tokenserver"
android:title="@string/preferences_override_sync_tokenserver"
app:iconSpaceReserved="false"
app:isPreferenceVisible="false" />
<androidx.preference.PreferenceCategory
android:layout="@layout/preference_category_no_icon_style"
android:title="@string/preferences_category_general">
<androidx.preference.Preference
android:key="@string/pref_key_search_settings"
android:title="@string/preferences_search"
app:iconSpaceReserved="false" />
<androidx.preference.Preference
android:key="@string/pref_key_tabs"
android:title="@string/preferences_tabs"
app:iconSpaceReserved="false" />
<androidx.preference.Preference
android:key="@string/pref_key_customize"
android:title="@string/preferences_customize"
app:iconSpaceReserved="false" />
<androidx.preference.Preference
android:key="@string/pref_key_passwords"
android:title="@string/preferences_passwords_logins_and_passwords"
app:iconSpaceReserved="false" />
<androidx.preference.Preference
android:key="@string/pref_key_credit_cards"
android:title="@string/preferences_credit_cards"
app:iconSpaceReserved="false" />
<androidx.preference.Preference
android:key="@string/pref_key_accessibility"
android:title="@string/preferences_accessibility"
app:iconSpaceReserved="false" />
<androidx.preference.Preference
android:key="@string/pref_key_language"
android:title="@string/preferences_language"
app:iconSpaceReserved="false" />
</androidx.preference.PreferenceCategory>
<androidx.preference.PreferenceCategory
android:key="@string/pref_key_sign_in"
android:layout="@layout/preference_category_no_icon_style"
android:title="@string/preferences_category_account">
<androidx.preference.Preference
android:key="@string/pref_key_sign_in"
android:title="@string/preferences_sync"
app:allowDividerBelow="true"
app:iconSpaceReserved="false" />
</androidx.preference.PreferenceCategory>
<androidx.preference.PreferenceCategory
android:key="@string/pref_key_account_category"
android:layout="@layout/preference_category_no_icon_style"
android:title="@string/preferences_category_account"
app:isPreferenceVisible="false">
<org.mozilla.fenix.settings.account.AccountPreference
android:key="@string/pref_key_account"
app:iconSpaceReserved="false"/>
<org.mozilla.fenix.settings.account.AccountAuthErrorPreference
android:key="@string/pref_key_account_auth_error"
app:iconSpaceReserved="false"/>
</androidx.preference.PreferenceCategory>
<androidx.preference.PreferenceCategory
android:layout="@layout/preference_category_no_icon_style"
android:title="@string/preferences_category_privacy_security">
<androidx.preference.Preference
android:key="@string/pref_key_private_browsing"
android:title="@string/preferences_private_browsing_options"
app:iconSpaceReserved="false" />
<androidx.preference.Preference
android:key="@string/pref_key_tracking_protection_settings"
android:title="@string/preference_enhanced_tracking_protection"
app:iconSpaceReserved="false" />
<androidx.preference.Preference
android:key="@string/pref_key_site_permissions"
android:title="@string/preferences_site_permissions"
app:iconSpaceReserved="false" />
<androidx.preference.Preference
android:key="@string/pref_key_delete_browsing_data"
android:title="@string/preferences_delete_browsing_data"
app:iconSpaceReserved="false" />
<androidx.preference.Preference
android:key="@string/pref_key_delete_browsing_data_on_quit_preference"
android:title="@string/preferences_delete_browsing_data_on_quit"
app:iconSpaceReserved="false" />
<androidx.preference.Preference
android:key="@string/pref_key_notifications"
android:title="@string/preferences_notifications"
app:iconSpaceReserved="false" />
<androidx.preference.Preference
android:key="@string/pref_key_data_choices"
android:title="@string/preferences_data_collection"
app:iconSpaceReserved="false" />
</androidx.preference.PreferenceCategory>
<PreferenceCategory
android:key="@string/pref_key_advanced"
android:layout="@layout/preference_category_no_icon_style"
android:title="@string/preferences_category_advanced">
<androidx.preference.Preference
android:key="@string/pref_key_addons"
android:title="@string/preferences_addons"
app:iconSpaceReserved="false" />
<androidx.preference.Preference
android:key="@string/pref_key_override_amo_collection"
android:title="@string/preferences_customize_amo_collection"
app:iconSpaceReserved="false" />
<androidx.preference.SwitchPreference
android:defaultValue="false"
android:key="@string/pref_key_open_links_in_external_app"
android:title="@string/preferences_open_links_in_apps"
app:iconSpaceReserved="false" />
<androidx.preference.SwitchPreference
android:defaultValue="false"
android:key="@string/pref_key_external_download_manager"
android:title="@string/preferences_external_download_manager"
app:iconSpaceReserved="false" />
<androidx.preference.SwitchPreference
android:defaultValue="true"
android:key="@string/pref_key_leakcanary"
android:title="@string/preference_leakcanary"
app:iconSpaceReserved="false"
app:isPreferenceVisible="@bool/IS_DEBUG" />
<androidx.preference.SwitchPreference
android:defaultValue="false"
android:key="@string/pref_key_remote_debugging"
android:title="@string/preferences_remote_debugging"
app:iconSpaceReserved="false" />
</PreferenceCategory>
<androidx.preference.PreferenceCategory
android:layout="@layout/preference_category_no_icon_style"
android:title="@string/preferences_category_about"
app:iconSpaceReserved="false">
<androidx.preference.Preference
android:key="@string/pref_key_rate"
android:title="@string/preferences_rate"
app:iconSpaceReserved="false" />
<androidx.preference.Preference
android:key="@string/pref_key_about"
android:title="@string/preferences_about"
app:iconSpaceReserved="false" />
<androidx.preference.Preference
android:key="@string/pref_key_debug_settings"
android:title="@string/preferences_debug_settings"
app:iconSpaceReserved="false"
app:isPreferenceVisible="false" />
<androidx.preference.Preference
android:key="@string/pref_key_secret_debug_info"
android:title="@string/preferences_debug_info"
app:iconSpaceReserved="false"
app:isPreferenceVisible="false" />
<androidx.preference.Preference
android:key="@string/pref_key_nimbus_experiments"
android:title="@string/preferences_nimbus_experiments"
app:isPreferenceVisible="false" />
</androidx.preference.PreferenceCategory>
</androidx.preference.PreferenceScreen>
Loading…
Cancel
Save