2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-15 18:12:54 +00:00

Close #27023: Add capability to override telemetry URL

This commit is contained in:
Roger Yang 2022-11-01 12:24:52 -04:00 committed by mergify[bot]
parent 79f0ce4cd3
commit d9d855685e
7 changed files with 99 additions and 6 deletions

View File

@ -75,6 +75,8 @@ import org.mozilla.fenix.components.metrics.MetricServiceType
import org.mozilla.fenix.components.metrics.MozillaProductDetector
import org.mozilla.fenix.components.toolbar.ToolbarPosition
import org.mozilla.fenix.ext.containsQueryParameters
import org.mozilla.fenix.ext.getCustomGleanServerUrlIfAvailable
import org.mozilla.fenix.ext.setCustomEndpointIfAvailable
import org.mozilla.fenix.ext.isCustomEngine
import org.mozilla.fenix.ext.isKnownSearchDomain
import org.mozilla.fenix.ext.settings
@ -154,14 +156,24 @@ open class FenixApplication : LocaleAwareApplication(), Provider {
logger.debug("Initializing Glean (uploadEnabled=$telemetryEnabled})")
// for performance reasons, this is only available in Nightly or Debug builds
val customEndpoint = if (Config.channel.isNightlyOrDebug) {
// for testing, if custom glean server url is set in the secret menu, use it to initialize Glean
getCustomGleanServerUrlIfAvailable(this)
} else {
null
}
val configuration = Configuration(
channel = BuildConfig.BUILD_TYPE,
httpClient = ConceptFetchHttpUploader(
lazy(LazyThreadSafetyMode.NONE) { components.core.client },
),
)
Glean.initialize(
applicationContext = this,
configuration = Configuration(
channel = BuildConfig.BUILD_TYPE,
httpClient = ConceptFetchHttpUploader(
lazy(LazyThreadSafetyMode.NONE) { components.core.client },
),
),
configuration = configuration.setCustomEndpointIfAvailable(customEndpoint),
uploadEnabled = telemetryEnabled,
buildInfo = GleanBuildInfo.buildInfo,
)

View File

@ -0,0 +1,31 @@
/* 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.ext
import android.content.Context
import androidx.preference.PreferenceManager
import mozilla.components.service.glean.config.Configuration
import org.mozilla.fenix.R
/**
* Get custom Glean server URL if available.
*/
fun getCustomGleanServerUrlIfAvailable(context: Context): String? {
return PreferenceManager.getDefaultSharedPreferences(context).getString(
context.getPreferenceKey(R.string.pref_key_custom_glean_server_url),
null,
)
}
/**
* Applies the custom Glean server URL to the Configuration if available.
*/
fun Configuration.setCustomEndpointIfAvailable(serverEndpoint: String?): Configuration {
if (!serverEndpoint.isNullOrEmpty()) {
return copy(serverEndpoint = serverEndpoint)
}
return this
}

View File

@ -5,9 +5,11 @@
package org.mozilla.fenix.settings
import android.os.Bundle
import androidx.preference.EditTextPreference
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreference
import org.mozilla.fenix.Config
import org.mozilla.fenix.FeatureFlags
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.components
@ -53,5 +55,10 @@ class SecretSettingsFragment : PreferenceFragmentCompat() {
isChecked = context.settings().showUnifiedSearchFeature
onPreferenceChangeListener = SharedPreferenceUpdater()
}
// 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
}
}
}

View File

@ -307,4 +307,5 @@
<string name="pref_key_nimbus_use_preview" translatable="false">pref_key_nimbus_use_preview</string>
<string name="pref_key_history_metadata_feature" translatable="false">pref_key_history_metadata_feature</string>
<string name="pref_key_show_unified_search" translatable="false">pref_key_show_unified_search</string>
<string name="pref_key_custom_glean_server_url" translatable="false">pref_key_custom_glean_server_url</string>
</resources>

View File

@ -44,6 +44,8 @@
<string name="preferences_debug_settings_task_continuity" translatable="false">Enable Task Continuity</string>
<!-- Label for enabling the Unified Search feature -->
<string name="preferences_debug_settings_unified_search" translatable="false">Enable Unified Search (requires restart)</string>
<!-- Label for custom Glean server URL -->
<string name="preferences_debug_settings_custom_glean_server_url" translatable="false">Custom Glean server URL (requires restart)</string>
<!-- Title of preference for sync debugging (only shown in the when the secret debug menu is enabled) -->
<string name="preferences_sync_debug">Sync Debug</string>
<!-- Preference to override the Push server -->

View File

@ -25,4 +25,10 @@
android:key="@string/pref_key_show_unified_search"
android:title="@string/preferences_debug_settings_unified_search"
app:iconSpaceReserved="false" />
<EditTextPreference
android:key="@string/pref_key_custom_glean_server_url"
android:title="@string/preferences_debug_settings_custom_glean_server_url"
android:inputType="textUri"
app:useSimpleSummaryProvider="true"
app:iconSpaceReserved="false" />
</PreferenceScreen>

View File

@ -0,0 +1,34 @@
/* 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.ext
import io.mockk.mockk
import mozilla.components.service.glean.config.Configuration
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotEquals
import org.junit.Test
class ConfigurationKtTest {
@Test
fun `GIVEN server endpoint is null THEN return the same configuration`() {
val configuration = Configuration(httpClient = mockk())
assertEquals(configuration, configuration.setCustomEndpointIfAvailable(null))
}
@Test
fun `GIVEN server endpoint is not empty THEN make a copy of configuration with server endpoint`() {
val configuration = Configuration(httpClient = mockk())
assertNotEquals(configuration, configuration.setCustomEndpointIfAvailable("test"))
}
@Test
fun `GIVEN server endpoint is empty THEN return the same configuration`() {
val configuration = Configuration(httpClient = mockk())
assertEquals(configuration, configuration.setCustomEndpointIfAvailable(""))
}
}