Bug 1198009 - Add a broadcast notification to SwitchBoard after network configuration fetch r=rnewman
authorMark Finkle <mfinkle@mozilla.com>
Sat, 12 Sep 2015 19:26:31 -0400
changeset 296505 27b8f7d5d686f2f0fb1e48414cf0962827478f1a
parent 296504 3a21445ed124bfcabb21de30611e765374bb31f6
child 296506 3363996dc230ec3d8b876d46f11beea9ae513560
push id962
push userjlund@mozilla.com
push dateFri, 04 Dec 2015 23:28:54 +0000
treeherdermozilla-release@23a2d286e80f [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 a broadcast notification to SwitchBoard after network configuration fetch 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
@@ -29,21 +29,22 @@ 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;
 
 import android.content.Context;
+import android.content.Intent;
 import android.content.pm.PackageManager.NameNotFoundException;
 import android.os.Build;
+import android.support.v4.content.LocalBroadcastManager;
 import android.util.Log;
 
-
 /**
  * SwitchBoard is the core class of the KeepSafe Switchboard mobile A/B testing framework.
  * This class provides a bunch of static methods that can be used in your app to run A/B tests. 
  * 
  * The SwitchBoard supports production and staging environment. 
  * 
  * For usage <code>initDefaultServerUrls</code> for first time usage. Server URLs can be updates from
  * a remote location with <code>initConfigServerUrl</code>.
@@ -64,17 +65,18 @@ public class SwitchBoard {
 	public static boolean DEBUG = true;
 	
 	/** Production server to update the remote server URLs. http://staging.domain/path_to/SwitchboardURLs.php */
 	private static String DYNAMIC_CONFIG_SERVER_URL_UPDATE;
 	
 	/** Production server for getting the actual config file. http://staging.domain/path_to/SwitchboardDriver.php */
 	private static String DYNAMIC_CONFIG_SERVER_DEFAULT_URL;
 	
-	
+	public static final String ACTION_CONFIG_FETCHED = ".SwitchBoard.CONFIG_FETCHED";
+
 	private static final String kUpdateServerUrl = "updateServerUrl";
 	private static final String kConfigServerUrl = "configServerUrl";
 	
 	private static final String IS_EXPERIMENT_ACTIVE = "isActive";
 	private static final String EXPERIMENT_VALUES = "values";
 	
 	
 	/**
@@ -227,16 +229,20 @@ public class SwitchBoard {
 				//store experiments in shared prefs (one variable)
 				if(serverConfig != null)
 					Preferences.setDynamicConfigJson(c, serverConfig);
 			}
 			
 		} catch (NullPointerException e) {
 			e.printStackTrace();
 		}
+
+		//notify listeners that the config fetch has completed
+		Intent i = new Intent(ACTION_CONFIG_FETCHED);
+		LocalBroadcastManager.getInstance(c).sendBroadcast(i);
 	}
 
 	public static boolean isInBucket(Context c, int low, int high) {
 		int userBucket = getUserBucket(c);
 		if (userBucket >= low && userBucket < high)
 			return true;
 		else
 			return false;