diff --git a/README.md b/README.md index 1729c3e1e..cae2bbc3b 100644 --- a/README.md +++ b/README.md @@ -224,6 +224,11 @@ If you wish to use a Nimbus server during local development, you can add a `http Testing experimental branches should be possible without a server. +### Using custom Glean servers during local development +If you wish to use a custom Glean server during local development, you can add a `https://` endpoint to the `local.properties` file. + +- `glean.custom.server.url` + ### GeckoView Specify a relative path to your local `mozilla-central` checkout via `dependencySubstitutions.geckoviewTopsrcdir`, and optional a path to m-c object directory via `dependencySubstitutions.geckoviewTopobjdir`. diff --git a/app/build.gradle b/app/build.gradle index 6d8e1e2b3..4d5e9064d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -365,6 +365,21 @@ android.applicationVariants.all { variant -> println("--") } +// ------------------------------------------------------------------------------------------------- +// Glean: Read custom server URL from local.properties of a local file if it exists +// ------------------------------------------------------------------------------------------------- + + print("Glean custom server URL: ") + + if (gradle.hasProperty("localProperties.glean.custom.server.url")) { + def url=gradle.getProperty("localProperties.glean.custom.server.url") + buildConfigField 'String', 'GLEAN_CUSTOM_URL', url + println "(Added from local.properties file)" + } else { + buildConfigField 'String', 'GLEAN_CUSTOM_URL', 'null' + println("--") + } + // ------------------------------------------------------------------------------------------------- // BuildConfig: Set flag for official builds; similar to MOZILLA_OFFICIAL in mozilla-central. // ------------------------------------------------------------------------------------------------- diff --git a/app/src/main/java/org/mozilla/fenix/ext/Configuration.kt b/app/src/main/java/org/mozilla/fenix/ext/Configuration.kt index 79bb3e43e..0c304ae7d 100644 --- a/app/src/main/java/org/mozilla/fenix/ext/Configuration.kt +++ b/app/src/main/java/org/mozilla/fenix/ext/Configuration.kt @@ -7,16 +7,21 @@ package org.mozilla.fenix.ext import android.content.Context import androidx.preference.PreferenceManager import mozilla.components.service.glean.config.Configuration +import org.mozilla.fenix.BuildConfig 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, - ) + return if (BuildConfig.GLEAN_CUSTOM_URL.isNullOrEmpty()) { + PreferenceManager.getDefaultSharedPreferences(context).getString( + context.getPreferenceKey(R.string.pref_key_custom_glean_server_url), + null, + ) + } else { + BuildConfig.GLEAN_CUSTOM_URL + } } /** diff --git a/app/src/main/java/org/mozilla/fenix/settings/SecretSettingsFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/SecretSettingsFragment.kt index 97f3fd4b7..be24d8d45 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/SecretSettingsFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/SecretSettingsFragment.kt @@ -9,6 +9,7 @@ import androidx.preference.EditTextPreference import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat import androidx.preference.SwitchPreference +import org.mozilla.fenix.BuildConfig import org.mozilla.fenix.Config import org.mozilla.fenix.FeatureFlags import org.mozilla.fenix.R @@ -58,7 +59,7 @@ class SecretSettingsFragment : PreferenceFragmentCompat() { // for performance reasons, this is only available in Nightly or Debug builds requirePreference(R.string.pref_key_custom_glean_server_url).apply { - isVisible = Config.channel.isNightlyOrDebug + isVisible = Config.channel.isNightlyOrDebug && BuildConfig.GLEAN_CUSTOM_URL.isNullOrEmpty() } } }