Closes #120 - Add Preference for Remote Debugging

Co-authored-by: Emily Kager <ekager@mozilla.com>
nightly-build-test
ekager 5 years ago committed by Colin Lee
parent c44e378385
commit 80f386c411

@ -25,7 +25,7 @@ import mozilla.components.feature.session.HistoryDelegate
import mozilla.components.feature.session.bundling.SessionBundleStorage import mozilla.components.feature.session.bundling.SessionBundleStorage
import mozilla.components.lib.crash.handler.CrashHandlerService import mozilla.components.lib.crash.handler.CrashHandlerService
import org.mozilla.fenix.AppRequestInterceptor import org.mozilla.fenix.AppRequestInterceptor
import org.mozilla.fenix.ext.components import org.mozilla.fenix.utils.Settings
import org.mozilla.geckoview.GeckoRuntime import org.mozilla.geckoview.GeckoRuntime
import org.mozilla.geckoview.GeckoRuntimeSettings import org.mozilla.geckoview.GeckoRuntimeSettings
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
@ -60,7 +60,7 @@ class Core(private val context: Context) {
val defaultSettings = DefaultSettings( val defaultSettings = DefaultSettings(
requestInterceptor = AppRequestInterceptor(context), requestInterceptor = AppRequestInterceptor(context),
remoteDebuggingEnabled = false, remoteDebuggingEnabled = Settings.getInstance(context).isRemoteDebuggingEnabled,
testingModeEnabled = false, testingModeEnabled = false,
trackingProtectionPolicy = createTrackingProtectionPolicy(prefs), trackingProtectionPolicy = createTrackingProtectionPolicy(prefs),
historyTrackingDelegate = HistoryDelegate(historyStorage) historyTrackingDelegate = HistoryDelegate(historyStorage)

@ -24,31 +24,32 @@ import kotlinx.coroutines.launch
import mozilla.components.concept.sync.AccountObserver import mozilla.components.concept.sync.AccountObserver
import mozilla.components.concept.sync.OAuthAccount import mozilla.components.concept.sync.OAuthAccount
import mozilla.components.concept.sync.Profile import mozilla.components.concept.sync.Profile
import kotlin.coroutines.CoroutineContext
import java.io.File
import mozilla.components.service.fxa.FxaUnauthorizedException import mozilla.components.service.fxa.FxaUnauthorizedException
import mozilla.components.support.ktx.android.graphics.toDataUri import mozilla.components.support.ktx.android.graphics.toDataUri
import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.BuildConfig import org.mozilla.fenix.BuildConfig
import org.mozilla.fenix.FenixApplication import org.mozilla.fenix.FenixApplication
import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.ext.getPreferenceKey import org.mozilla.fenix.R.string.pref_key_about
import org.mozilla.fenix.ext.requireComponents import org.mozilla.fenix.R.string.pref_key_accessibility
import org.mozilla.fenix.R.string.pref_key_leakcanary import org.mozilla.fenix.R.string.pref_key_account
import org.mozilla.fenix.R.string.pref_key_account_category
import org.mozilla.fenix.R.string.pref_key_data_choices
import org.mozilla.fenix.R.string.pref_key_feedback import org.mozilla.fenix.R.string.pref_key_feedback
import org.mozilla.fenix.R.string.pref_key_help import org.mozilla.fenix.R.string.pref_key_help
import org.mozilla.fenix.R.string.pref_key_language
import org.mozilla.fenix.R.string.pref_key_leakcanary
import org.mozilla.fenix.R.string.pref_key_make_default_browser import org.mozilla.fenix.R.string.pref_key_make_default_browser
import org.mozilla.fenix.R.string.pref_key_rate import org.mozilla.fenix.R.string.pref_key_rate
import org.mozilla.fenix.R.string.pref_key_site_permissions import org.mozilla.fenix.R.string.pref_key_remote_debugging
import org.mozilla.fenix.R.string.pref_key_accessibility
import org.mozilla.fenix.R.string.pref_key_language
import org.mozilla.fenix.R.string.pref_key_data_choices
import org.mozilla.fenix.R.string.pref_key_about
import org.mozilla.fenix.R.string.pref_key_sign_in
import org.mozilla.fenix.R.string.pref_key_account
import org.mozilla.fenix.R.string.pref_key_account_category
import org.mozilla.fenix.R.string.pref_key_search_engine_settings import org.mozilla.fenix.R.string.pref_key_search_engine_settings
import org.mozilla.fenix.R.string.pref_key_sign_in
import org.mozilla.fenix.R.string.pref_key_site_permissions
import org.mozilla.fenix.ext.getPreferenceKey
import org.mozilla.fenix.ext.requireComponents
import java.io.File
import kotlin.coroutines.CoroutineContext
@SuppressWarnings("TooManyFunctions") @SuppressWarnings("TooManyFunctions")
class SettingsFragment : PreferenceFragmentCompat(), CoroutineScope, AccountObserver { class SettingsFragment : PreferenceFragmentCompat(), CoroutineScope, AccountObserver {
@ -184,9 +185,11 @@ class SettingsFragment : PreferenceFragmentCompat(), CoroutineScope, AccountObse
private fun setupPreferences() { private fun setupPreferences() {
val makeDefaultBrowserKey = context!!.getPreferenceKey(pref_key_make_default_browser) val makeDefaultBrowserKey = context!!.getPreferenceKey(pref_key_make_default_browser)
val leakKey = context!!.getPreferenceKey(pref_key_leakcanary) val leakKey = context!!.getPreferenceKey(pref_key_leakcanary)
val debuggingKey = context!!.getPreferenceKey(pref_key_remote_debugging)
val preferenceMakeDefaultBrowser = findPreference<Preference>(makeDefaultBrowserKey) val preferenceMakeDefaultBrowser = findPreference<Preference>(makeDefaultBrowserKey)
val preferenceLeakCanary = findPreference<Preference>(leakKey) val preferenceLeakCanary = findPreference<Preference>(leakKey)
val preferenceRemoteDebugging = findPreference<Preference>(debuggingKey)
preferenceMakeDefaultBrowser?.onPreferenceClickListener = preferenceMakeDefaultBrowser?.onPreferenceClickListener =
getClickListenerForMakeDefaultBrowser() getClickListenerForMakeDefaultBrowser()
@ -199,6 +202,12 @@ class SettingsFragment : PreferenceFragmentCompat(), CoroutineScope, AccountObse
true true
} }
} }
preferenceRemoteDebugging?.onPreferenceChangeListener =
Preference.OnPreferenceChangeListener { _, newValue ->
requireComponents.core.engine.settings.remoteDebuggingEnabled = newValue as Boolean
true
}
} }
private val defaultClickListener = OnPreferenceClickListener { preference -> private val defaultClickListener = OnPreferenceClickListener { preference ->
@ -261,7 +270,8 @@ class SettingsFragment : PreferenceFragmentCompat(), CoroutineScope, AccountObse
override fun onError(error: Exception) { override fun onError(error: Exception) {
// TODO we could display some error states in this UI. // TODO we could display some error states in this UI.
when (error) { when (error) {
is FxaUnauthorizedException -> {} is FxaUnauthorizedException -> {
}
} }
} }

@ -41,6 +41,9 @@ class Settings private constructor(context: Context) {
val isCrashReportingEnabled: Boolean val isCrashReportingEnabled: Boolean
get() = preferences.getBoolean(appContext.getPreferenceKey(R.string.pref_key_crash_reporter), true) get() = preferences.getBoolean(appContext.getPreferenceKey(R.string.pref_key_crash_reporter), true)
val isRemoteDebuggingEnabled: Boolean
get() = preferences.getBoolean(appContext.getPreferenceKey(R.string.pref_key_remote_debugging), false)
val isTelemetryEnabled: Boolean val isTelemetryEnabled: Boolean
get() = preferences.getBoolean(appContext.getPreferenceKey(R.string.pref_key_telemetry), true) get() = preferences.getBoolean(appContext.getPreferenceKey(R.string.pref_key_telemetry), true)
@ -54,6 +57,7 @@ class Settings private constructor(context: Context) {
preferences.edit().putInt(appContext.getPreferenceKey(R.string.pref_key_bounce_quick_action), preferences.edit().putInt(appContext.getPreferenceKey(R.string.pref_key_bounce_quick_action),
autoBounceQuickActionSheetCount + 1).apply() autoBounceQuickActionSheetCount + 1).apply()
} }
fun setDefaultSearchEngineByName(name: String) { fun setDefaultSearchEngineByName(name: String) {
preferences.edit() preferences.edit()
.putString(appContext.getPreferenceKey(R.string.pref_key_search_engine), name) .putString(appContext.getPreferenceKey(R.string.pref_key_search_engine), name)

@ -20,6 +20,7 @@
<string name="pref_key_private_mode" translatable="false">pref_key_private_mode</string> <string name="pref_key_private_mode" translatable="false">pref_key_private_mode</string>
<string name="pref_key_theme" translatable="false">pref_key_theme</string> <string name="pref_key_theme" translatable="false">pref_key_theme</string>
<string name="pref_key_leakcanary" translatable="false">pref_key_leakcanary</string> <string name="pref_key_leakcanary" translatable="false">pref_key_leakcanary</string>
<string name="pref_key_remote_debugging" translatable="false">pref_key_remote_debugging</string>
<!-- Data Choices --> <!-- Data Choices -->
<string name="pref_key_telemetry" translatable="false">pref_key_telemetry</string> <string name="pref_key_telemetry" translatable="false">pref_key_telemetry</string>

@ -115,6 +115,10 @@
<string name="preferences_data_choices">Data choices</string> <string name="preferences_data_choices">Data choices</string>
<!-- Preference for developers --> <!-- Preference for developers -->
<string name="preference_leakcanary">Leak Canary</string> <string name="preference_leakcanary">Leak Canary</string>
<!-- Preference category for developer tools -->
<string name="developer_tools_category">Developer tools</string>
<!-- Preference for developers -->
<string name="preferences_remote_debugging">Remote debugging via USB</string>
<!-- Preference title for switch preference to show search suggestions --> <!-- Preference title for switch preference to show search suggestions -->
<string name="preferences_show_search_suggestions">Show search suggestions</string> <string name="preferences_show_search_suggestions">Show search suggestions</string>
<!-- Preference for account settings --> <!-- Preference for account settings -->

@ -73,6 +73,15 @@
android:defaultValue="false" /> android:defaultValue="false" />
</androidx.preference.PreferenceCategory> </androidx.preference.PreferenceCategory>
<PreferenceCategory
android:title="@string/developer_tools_category">
<androidx.preference.SwitchPreference
android:icon="@drawable/ic_energy"
android:key="@string/pref_key_remote_debugging"
android:title="@string/preferences_remote_debugging"
android:defaultValue="false" />
</PreferenceCategory>
<androidx.preference.PreferenceCategory <androidx.preference.PreferenceCategory
android:title="@string/preferences_category_about" android:title="@string/preferences_category_about"
app:iconSpaceReserved="false"> app:iconSpaceReserved="false">

Loading…
Cancel
Save