Bug 1405490 - Make Fennec honor the manual override to send telemetry from non-official builds; r?mcomella
MozReview-Commit-ID: 5lM3gEmSuJ8
--- a/mobile/android/base/java/org/mozilla/gecko/telemetry/TelemetryPreferences.java
+++ b/mobile/android/base/java/org/mozilla/gecko/telemetry/TelemetryPreferences.java
@@ -17,30 +17,37 @@ import java.lang.ref.WeakReference;
*
* This class persists any Gecko preferences beyond shutdown so that these values
* can be accessed on the next run before Gecko is started as we expect Telemetry
* to run before Gecko is available.
*/
public class TelemetryPreferences {
private TelemetryPreferences() {}
+ private static final String GECKO_PREF_SEND_OVERRIDE = "toolkit.telemetry.send.overrideOfficialCheck";
+ private static final String SHARED_PREF_SEND_OVERRIDE = "telemetry-sendOverrideOfficialCheck";
private static final String GECKO_PREF_SERVER_URL = "toolkit.telemetry.server";
private static final String SHARED_PREF_SERVER_URL = "telemetry-serverUrl";
// Defaults are a mirror of about:config defaults so we can access them before Gecko is available.
private static final String DEFAULT_SERVER_URL = "https://incoming.telemetry.mozilla.org";
private static final String[] OBSERVED_PREFS = {
+ GECKO_PREF_SEND_OVERRIDE,
GECKO_PREF_SERVER_URL,
};
public static String getServerSchemeHostPort(final Context context, final String profileName) {
return getSharedPrefs(context, profileName).getString(SHARED_PREF_SERVER_URL, DEFAULT_SERVER_URL);
}
+ public static boolean getSendOverrideOfficialCheck(final Context context, final String profileName) {
+ return getSharedPrefs(context, profileName).getBoolean(SHARED_PREF_SEND_OVERRIDE, false);
+ }
+
public static void initPreferenceObserver(final Context context, final String profileName) {
final PrefHandler prefHandler = new TelemetryPrefHandler(context, profileName);
PrefsHelper.addObserver(OBSERVED_PREFS, prefHandler); // gets preference value when gecko starts.
}
private static SharedPreferences getSharedPrefs(final Context context, final String profileName) {
return GeckoSharedPrefs.forProfileName(context, profileName);
}
@@ -64,10 +71,26 @@ public class TelemetryPreferences {
if (!pref.equals(GECKO_PREF_SERVER_URL)) {
throw new IllegalStateException("Unknown preference: " + pref);
}
getSharedPrefs(context, profileName).edit()
.putString(SHARED_PREF_SERVER_URL, value)
.apply();
}
+
+ @Override
+ public void prefValue(final String pref, final boolean value) {
+ final Context context = contextWeakReference.get();
+ if (context == null) {
+ return;
+ }
+
+ if (!pref.equals(GECKO_PREF_SEND_OVERRIDE)) {
+ throw new IllegalStateException("Unknown preference: " + pref);
+ }
+
+ getSharedPrefs(context, profileName).edit()
+ .putBoolean(SHARED_PREF_SEND_OVERRIDE, value)
+ .apply();
+ }
}
}
--- a/mobile/android/base/java/org/mozilla/gecko/telemetry/TelemetryUploadService.java
+++ b/mobile/android/base/java/org/mozilla/gecko/telemetry/TelemetryUploadService.java
@@ -178,21 +178,16 @@ public class TelemetryUploadService exte
* {@link #isUploadEnabledByProfileConfig(Context, GeckoProfile)} if the profile is available as it takes into
* account more information.
*
* You may wish to also check if the network is connected when calling this method.
*
* Note that this method logs debug statements when upload is disabled.
*/
public static boolean isUploadEnabledByAppConfig(final Context context) {
- if (!TelemetryConstants.UPLOAD_ENABLED) {
- Log.d(LOGTAG, "Telemetry upload feature is compile-time disabled");
- return false;
- }
-
if (isDisabled) {
Log.d(LOGTAG, "Telemetry upload feature is disabled by intent (in testing?)");
return false;
}
if (!GeckoPreferences.getBooleanPref(context, GeckoPreferences.PREFS_HEALTHREPORT_UPLOAD_ENABLED, true)) {
Log.d(LOGTAG, "Telemetry upload opt-out");
return false;
@@ -211,16 +206,22 @@ public class TelemetryUploadService exte
* Determines if the telemetry upload feature is enabled via profile & application level configurations. This is the
* preferred method.
*
* You may wish to also check if the network is connected when calling this method.
*
* Note that this method logs debug statements when upload is disabled.
*/
public static boolean isUploadEnabledByProfileConfig(final Context context, final GeckoProfile profile) {
+ if (!TelemetryConstants.UPLOAD_ENABLED &&
+ !TelemetryPreferences.getSendOverrideOfficialCheck(context, profile.getName())) {
+ Log.d(LOGTAG, "Telemetry upload feature is disabled in non-official builds");
+ return false;
+ }
+
if (profile.inGuestMode()) {
Log.d(LOGTAG, "Profile is in guest mode");
return false;
}
return isUploadEnabledByAppConfig(context);
}