1
0
Fork 0

Closes #120 - Add Preference for Remote Debugging

Co-authored-by: Emily Kager <ekager@mozilla.com>
master
ekager 2019-03-22 09:18:49 -07:00 committed by Colin Lee
parent c44e378385
commit 80f386c411
6 changed files with 46 additions and 18 deletions

View File

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

View File

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

View File

@ -41,6 +41,9 @@ class Settings private constructor(context: Context) {
val isCrashReportingEnabled: Boolean
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
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),
autoBounceQuickActionSheetCount + 1).apply()
}
fun setDefaultSearchEngineByName(name: String) {
preferences.edit()
.putString(appContext.getPreferenceKey(R.string.pref_key_search_engine), name)

View File

@ -20,6 +20,7 @@
<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_leakcanary" translatable="false">pref_key_leakcanary</string>
<string name="pref_key_remote_debugging" translatable="false">pref_key_remote_debugging</string>
<!-- Data Choices -->
<string name="pref_key_telemetry" translatable="false">pref_key_telemetry</string>

View File

@ -115,6 +115,10 @@
<string name="preferences_data_choices">Data choices</string>
<!-- Preference for developers -->
<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 -->
<string name="preferences_show_search_suggestions">Show search suggestions</string>
<!-- Preference for account settings -->

View File

@ -73,6 +73,15 @@
android:defaultValue="false" />
</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
android:title="@string/preferences_category_about"
app:iconSpaceReserved="false">