Bug 1270191 - Move Experiments to env var solution. r=grisha

MozReview-Commit-ID: 5Rpdyg7zpNG

--HG--
extra : rebase_source : 1642484993287d489060e95e3fbeb62232b422c6
This commit is contained in:
Michael Comella 2016-05-31 17:04:25 -07:00
Родитель b50b3795da
Коммит 8fc95417b0
2 изменённых файлов: 35 добавлений и 23 удалений

Просмотреть файл

@ -96,6 +96,7 @@ import org.mozilla.gecko.util.FloatUtils;
import org.mozilla.gecko.util.GamepadUtils;
import org.mozilla.gecko.util.GeckoEventListener;
import org.mozilla.gecko.util.HardwareUtils;
import org.mozilla.gecko.util.IntentUtils;
import org.mozilla.gecko.util.MenuUtils;
import org.mozilla.gecko.util.NativeEventListener;
import org.mozilla.gecko.util.NativeJSObject;
@ -176,6 +177,7 @@ import java.net.URLEncoder;
import java.util.Arrays;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
@ -545,6 +547,7 @@ public class BrowserApp extends GeckoApp
}
final Intent intent = getIntent();
configureForTestsBasedOnEnvironment(intent);
// This has to be prepared prior to calling GeckoApp.onCreate, because
// widget code and BrowserToolbar need it, and they're created by the
@ -760,12 +763,27 @@ public class BrowserApp extends GeckoApp
}
}
/**
* Sets up the testing configuration if the environment is configured as such.
*
* We need to read environment variables 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.
*
* This method should be called early since other initialization
* may depend on its results.
*/
private void configureForTestsBasedOnEnvironment(final Intent intent) {
final HashMap<String, String> envVars = IntentUtils.getEnvVarMap(intent);
Experiments.setDisabledFromEnvVar(envVars);
}
/**
* Initializes the default Switchboard URLs the first time.
* @param intent
*/
private void initSwitchboard(Intent intent) {
if (Experiments.isDisabled(new SafeIntent(intent)) || !AppConstants.MOZ_SWITCHBOARD) {
private void initSwitchboard(final Intent intent) {
if (Experiments.isDisabled() || !AppConstants.MOZ_SWITCHBOARD) {
return;
}

Просмотреть файл

@ -6,8 +6,8 @@ package org.mozilla.gecko.util;
import android.content.Context;
import android.support.annotation.NonNull;
import android.util.Log;
import org.mozilla.gecko.mozglue.SafeIntentUtils.SafeIntent;
import android.text.TextUtils;
import com.keepsafe.switchboard.Preferences;
@ -16,6 +16,7 @@ import org.mozilla.gecko.GeckoSharedPrefs;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
/**
* This class should reflect the experiment names found in the Switchboard experiments config here:
@ -24,6 +25,8 @@ import java.util.List;
public class Experiments {
private static final String LOGTAG = "GeckoExperiments";
private static final String ENVVAR_DISABLED = "MOZ_DISABLE_SWITCHBOARD";
// Show a system notification linking to a "What's New" page on app update.
public static final String WHATSNEW_NOTIFICATION = "whatsnew-notification";
@ -58,31 +61,22 @@ public class Experiments {
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
* As a sanity check, this method may only be called once.
*/
public static boolean isDisabled(SafeIntent intent) {
public static void setDisabledFromEnvVar(@NonNull final Map<String, String> envVarMap) {
if (disabled != null) {
return disabled;
throw new IllegalStateException("Disabled state already set");
}
disabled = envVarMap.containsKey(ENVVAR_DISABLED);
if (disabled) {
Log.d(LOGTAG, "Switchboard disabled by environment variable: " + ENVVAR_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);
public static boolean isDisabled() {
if (disabled == null) {
throw new IllegalStateException("Disabled state not yet set.");
}
disabled = false;
return disabled;
}