From 14eea7579589a4ee3cff7ccece6cb8ff0a33abe4 Mon Sep 17 00:00:00 2001 From: Margaret Leibovic Date: Thu, 18 Feb 2016 12:03:51 -0500 Subject: [PATCH] Bug 1247324 - Disable Switchboard in automation. r=gbrown,mfinkle MozReview-Commit-ID: ItqHBIEdD0Q --- build/mobile/remoteautomation.py | 4 +++ .../java/org/mozilla/gecko/BrowserApp.java | 2 +- .../org/mozilla/gecko/util/Experiments.java | 35 +++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/build/mobile/remoteautomation.py b/build/mobile/remoteautomation.py index 3475b24feba..87ff64707f5 100644 --- a/build/mobile/remoteautomation.py +++ b/build/mobile/remoteautomation.py @@ -86,6 +86,10 @@ class RemoteAutomation(Automation): # Don't override the user's choice here. See bug 1049688. env.setdefault('MOZ_DISABLE_NONLOCAL_CONNECTIONS', '1') + # Disable Switchboard by default. This will prevent nonlocal + # network connections to the Switchboard server. + env.setdefault('MOZ_DISABLE_SWITCHBOARD', '1') + # Set WebRTC logging in case it is not set yet. # On Android, environment variables cannot contain ',' so the # standard WebRTC setting for NSPR_LOG_MODULES is not available. diff --git a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java index 4a90ba00c2c..7e8cc28ca2c 100644 --- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java +++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java @@ -587,7 +587,7 @@ public class BrowserApp extends GeckoApp final Context appContext = getApplicationContext(); - if (AppConstants.MOZ_SWITCHBOARD) { + if (!Experiments.isDisabled(new SafeIntent(intent)) && AppConstants.MOZ_SWITCHBOARD) { // Initializes the default URLs the first time. SwitchBoard.initDefaultServerUrls("https://switchboard.services.mozilla.com/urls", "https://switchboard.services.mozilla.com/v1", true); diff --git a/mobile/android/base/java/org/mozilla/gecko/util/Experiments.java b/mobile/android/base/java/org/mozilla/gecko/util/Experiments.java index 2a86e6171e1..c3a3b9f993d 100644 --- a/mobile/android/base/java/org/mozilla/gecko/util/Experiments.java +++ b/mobile/android/base/java/org/mozilla/gecko/util/Experiments.java @@ -4,11 +4,16 @@ package org.mozilla.gecko.util; +import android.util.Log; +import org.mozilla.gecko.mozglue.ContextUtils.SafeIntent; + /** * This class should reflect the experiment names found in the Switchboard experiments config here: * https://github.com/mozilla-services/switchboard-experiments */ public class Experiments { + private static final String LOGTAG = "GeckoExperiments"; + // Display History and Bookmarks in 3-dot menu. public static final String BOOKMARKS_HISTORY_MENU = "bookmark-history-menu"; @@ -20,4 +25,34 @@ public class Experiments { // Show search mode (instead of home panels) when tapping on urlbar if there is a search term in the urlbar. public static final String SEARCH_TERM = "search-term"; + private static volatile Boolean disabled = null; + + /** + * Determines whether Switchboard is disabled by the MOZ_DISABLE_SWITCHBOARD + * environment variable. We need to read this value from the intent string + * extra because environment variables from our test harness aren't set + * until Gecko is loaded, and we need to know this before then. + * + * @param intent Main intent that launched the app + * @return Whether Switchboard is disabled + */ + public static boolean isDisabled(SafeIntent intent) { + if (disabled != null) { + return disabled; + } + + String env = intent.getStringExtra("env0"); + for (int i = 1; env != null; i++) { + if (env.startsWith("MOZ_DISABLE_SWITCHBOARD=")) { + if (!env.endsWith("=")) { + Log.d(LOGTAG, "Switchboard disabled by MOZ_DISABLE_SWITCHBOARD environment variable"); + disabled = true; + return disabled; + } + } + env = intent.getStringExtra("env" + i); + } + disabled = false; + return disabled; + } }