Bug 1198009 - Add SwitchBoard.getActiveExperiments r=rnewman
authorMark Finkle <mfinkle@mozilla.com>
Sat, 12 Sep 2015 19:26:14 -0400
changeset 294799 3a21445ed124bfcabb21de30611e765374bb31f6
parent 294786 68718290640b0ca195344fa5cc4c55fbc260e19e
child 294800 27b8f7d5d686f2f0fb1e48414cf0962827478f1a
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman
bugs1198009
milestone43.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1198009 - Add SwitchBoard.getActiveExperiments r=rnewman
mobile/android/thirdparty/com/keepsafe/switchboard/SwitchBoard.java
--- a/mobile/android/thirdparty/com/keepsafe/switchboard/SwitchBoard.java
+++ b/mobile/android/thirdparty/com/keepsafe/switchboard/SwitchBoard.java
@@ -17,16 +17,19 @@ package com.keepsafe.switchboard;
 
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.net.HttpURLConnection;
 import java.net.ProtocolException;
 import java.net.URL;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
 import java.util.Locale;
 import java.util.MissingResourceException;
 import java.util.UUID;
 import java.util.zip.CRC32;
 
 import org.json.JSONException;
 import org.json.JSONObject;
 
@@ -284,16 +287,47 @@ public class SwitchBoard {
 		
 			//return false when JSON fails
 			return defaultReturnVal;
 		}
 		
 	}
 	
 	/**
+	 * @returns a list of all active experiments.
+	 */
+	public static List<String> getActiveExperiments(Context c) {
+		ArrayList<String> returnList = new ArrayList<String>();
+
+		// lookup experiment in config
+		String config = Preferences.getDynamicConfigJson(c);
+
+		// if it does not exist
+		if (config == null) {
+			return returnList;
+		}
+
+		try {
+			JSONObject experiments = new JSONObject(config);
+			Iterator<?> iter = experiments.keys();
+			while (iter.hasNext()) {
+				String key = (String)iter.next();
+				JSONObject experiment = experiments.getJSONObject(key);
+				if (experiment.getBoolean(IS_EXPERIMENT_ACTIVE)) {
+					returnList.add(key);
+				}
+			}
+		} catch (JSONException e) {
+			// Something went wrong!
+		}
+
+		return returnList;
+	}
+
+	/**
 	 * Checks if a certain experiment exists. 
 	 * @param c ApplicationContext
 	 * @param experimentName Name of the experiment
 	 * @return true when experiment exists
 	 */
 	public static boolean hasExperimentValues(Context c, String experimentName) {
 		if(getExperimentValueFromJson(c, experimentName) == null)
 			return false;