Bug 1864070 - Add secret setting to enable the debug drawer

fenix/122.0
Noah Bond 7 months ago committed by mergify[bot]
parent 1e2b8d5920
commit 670f80d7b8

@ -0,0 +1,40 @@
/* 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/. */
package org.mozilla.fenix.debugsettings.data
import android.content.Context
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.booleanPreferencesKey
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.preferencesDataStore
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
/**
* [DataStore] for accessing debugging settings.
*/
val Context.debugSettings: DataStore<Preferences> by preferencesDataStore(name = "debug_settings")
private val DEBUG_DRAWER_ENABLED = booleanPreferencesKey("debug_drawer_enabled")
/**
* Updates whether the debug drawer is enabled.
*
* @param enabled Whether the debug drawer is enabled.
*/
suspend fun DataStore<Preferences>.updateDebugDrawerEnabled(enabled: Boolean) {
edit { preferences ->
preferences[DEBUG_DRAWER_ENABLED] = enabled
}
}
/**
* [Flow] for checking whether the Debug Drawer is enabled.
*/
val DataStore<Preferences>.debugDrawerEnabled: Flow<Boolean>
get() = data.map { preferences ->
preferences[DEBUG_DRAWER_ENABLED] ?: false
}

@ -6,15 +6,21 @@ package org.mozilla.fenix.settings
import android.os.Bundle
import androidx.core.content.edit
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
import androidx.preference.EditTextPreference
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreference
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
import org.mozilla.fenix.BuildConfig
import org.mozilla.fenix.Config
import org.mozilla.fenix.FeatureFlags
import org.mozilla.fenix.R
import org.mozilla.fenix.debugsettings.data.debugDrawerEnabled
import org.mozilla.fenix.debugsettings.data.debugSettings
import org.mozilla.fenix.debugsettings.data.updateDebugDrawerEnabled
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.nav
import org.mozilla.fenix.ext.settings
@ -98,6 +104,23 @@ class SecretSettingsFragment : PreferenceFragmentCompat() {
onPreferenceChangeListener = SharedPreferenceUpdater()
}
lifecycleScope.launch {
val debugDataStore = requireContext().debugSettings
// During initial development, this will only be available in Nightly or Debug builds.
requirePreference<SwitchPreference>(R.string.pref_key_enable_debug_drawer).apply {
isVisible = Config.channel.isNightlyOrDebug
isChecked = debugDataStore.debugDrawerEnabled.first()
onPreferenceChangeListener =
Preference.OnPreferenceChangeListener { _, newValue ->
lifecycleScope.launch {
debugDataStore.updateDebugDrawerEnabled(enabled = newValue as Boolean)
}
true
}
}
}
// for performance reasons, this is only available in Nightly or Debug builds
requirePreference<EditTextPreference>(R.string.pref_key_custom_glean_server_url).apply {
isVisible = Config.channel.isNightlyOrDebug && BuildConfig.GLEAN_CUSTOM_URL.isNullOrEmpty()

@ -78,6 +78,7 @@
<string name="pref_key_home_blocklist">pref_key_home_blocklist</string>
<string name="pref_key_hidden_engines_restored" translatable="false">pref_key_hidden_engines_restored</string>
<string name="pref_key_enable_fxsuggest" translatable="false">pref_key_fxsuggest_enabled</string>
<string name="pref_key_enable_debug_drawer" translatable="false">pref_key_enable_debug_drawer</string>
<!-- Data Choices -->
<string name="pref_key_telemetry" translatable="false">pref_key_telemetry</string>

@ -74,6 +74,8 @@
<string name="preferences_debug_settings_toolbar_redesign" translatable="false">Enable Toolbar Redesign incomplete portions</string>
<!-- Label for enabling Felt Privacy -->
<string name="preferences_debug_felt_privacy" translatable="false">Enable Felt Privacy</string>
<!-- Label for enabling the Debug Drawer -->
<string name="preferences_debug_settings_debug_drawer" translatable="false">Enable Debug Drawer</string>
<!-- A secret menu option in the tabs tray for making a tab inactive for testing. -->
<string name="inactive_tabs_menu_item">Make inactive</string>

@ -45,6 +45,11 @@
app:iconSpaceReserved="false"
android:title="@string/preferences_debug_felt_privacy"
/>
<SwitchPreference
android:defaultValue="false"
android:key="@string/pref_key_enable_debug_drawer"
android:title="@string/preferences_debug_settings_debug_drawer"
app:iconSpaceReserved="false" />
<EditTextPreference
android:key="@string/pref_key_custom_glean_server_url"
android:title="@string/preferences_debug_settings_custom_glean_server_url"

Loading…
Cancel
Save