Bug 761706 - Bind GeckoNetworkManager to the global application context. r=mfinkle
authorKartikaya Gupta <kgupta@mozilla.com>
Fri, 14 Sep 2012 11:19:40 -0400
changeset 107203 338823aa94a63d28394001d7a36293d85365a238
parent 107202 cf2e7dc4182f98bf03834ef342c03d0dac181f76
child 107204 29466c92fe4439f3cb465c14298d229fc40c0214
push id74
push usershu@rfrn.org
push dateTue, 18 Sep 2012 19:23:47 +0000
reviewersmfinkle
bugs761706
milestone18.0a1
Bug 761706 - Bind GeckoNetworkManager to the global application context. r=mfinkle
mobile/android/base/GeckoApp.java
mobile/android/base/GeckoNetworkManager.java
--- a/mobile/android/base/GeckoApp.java
+++ b/mobile/android/base/GeckoApp.java
@@ -1611,17 +1611,17 @@ abstract public class GeckoApp
         mConnectivityReceiver.registerFor(mAppContext);
 
         mPromptService = new PromptService();
 
         mTextSelection = new TextSelection((TextSelectionHandle) findViewById(R.id.start_handle),
                                            (TextSelectionHandle) findViewById(R.id.end_handle),
                                            GeckoAppShell.getEventDispatcher());
 
-        GeckoNetworkManager.getInstance().init();
+        GeckoNetworkManager.getInstance().init(this);
         GeckoNetworkManager.getInstance().start();
 
         UpdateServiceHelper.registerForUpdates(this);
 
         GeckoScreenOrientationListener.getInstance().start();
 
         final GeckoApp self = this;
 
--- a/mobile/android/base/GeckoNetworkManager.java
+++ b/mobile/android/base/GeckoNetworkManager.java
@@ -88,16 +88,17 @@ public class GeckoNetworkManager extends
         NETWORK_2_75_G, // 2.75G
         NETWORK_3_G,    // 3G
         NETWORK_3_5_G,  // 3.5G
         NETWORK_3_75_G, // 3.75G
         NETWORK_3_9_G,  // 3.9G
         NETWORK_UNKNOWN
     }
 
+    private Context mApplicationContext;
     private NetworkType  mNetworkType = NetworkType.NETWORK_NONE;
     private IntentFilter mNetworkFilter = new IntentFilter();
     // Whether the manager should be listening to Network Information changes.
     private boolean mShouldBeListening = false;
     // Whether the manager should notify Gecko that a change in Network
     // Information happened.
     private boolean mShouldNotify      = false;
 
@@ -105,44 +106,45 @@ public class GeckoNetworkManager extends
         return sInstance;
     }
 
     @Override
     public void onReceive(Context aContext, Intent aIntent) {
         updateNetworkType();
     }
 
-    public void init() {
+    public void init(Context context) {
+        mApplicationContext = context.getApplicationContext();
         mNetworkFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
         mNetworkType = getNetworkType();
     }
 
     public void start() {
         mShouldBeListening = true;
         updateNetworkType();
 
         if (mShouldNotify) {
             startListening();
         }
     }
 
     private void startListening() {
-        GeckoApp.mAppContext.registerReceiver(sInstance, mNetworkFilter);
+        mApplicationContext.registerReceiver(sInstance, mNetworkFilter);
     }
 
     public void stop() {
         mShouldBeListening = false;
 
         if (mShouldNotify) {
         stopListening();
         }
     }
 
     private void stopListening() {
-        GeckoApp.mAppContext.unregisterReceiver(sInstance);
+        mApplicationContext.unregisterReceiver(sInstance);
     }
 
     private void updateNetworkType() {
         NetworkType previousNetworkType = mNetworkType;
         mNetworkType = getNetworkType();
 
         if (mNetworkType == previousNetworkType || !mShouldNotify) {
             return;
@@ -174,17 +176,17 @@ public class GeckoNetworkManager extends
 
         if (mShouldBeListening) {
             stopListening();
         }
     }
 
     private static NetworkType getNetworkType() {
         ConnectivityManager cm =
-            (ConnectivityManager)GeckoApp.mAppContext.getSystemService(Context.CONNECTIVITY_SERVICE);
+            (ConnectivityManager)sInstance.mApplicationContext.getSystemService(Context.CONNECTIVITY_SERVICE);
         if (cm == null) {
             Log.e(LOGTAG, "Connectivity service does not exist");
             return NetworkType.NETWORK_NONE;
         }
 
         NetworkInfo ni = cm.getActiveNetworkInfo();
         if (ni == null) {
             return NetworkType.NETWORK_NONE;
@@ -200,17 +202,17 @@ public class GeckoNetworkManager extends
         case ConnectivityManager.TYPE_MOBILE:
             break; // We will handle sub-types after the switch.
         default:
             Log.w(LOGTAG, "Ignoring the current network type.");
             return NetworkType.NETWORK_UNKNOWN;
         }
 
         TelephonyManager tm =
-            (TelephonyManager)GeckoApp.mAppContext.getSystemService(Context.TELEPHONY_SERVICE);
+            (TelephonyManager)sInstance.mApplicationContext.getSystemService(Context.TELEPHONY_SERVICE);
         if (tm == null) {
             Log.e(LOGTAG, "Telephony service does not exist");
             return NetworkType.NETWORK_UNKNOWN;
         }
 
         switch (tm.getNetworkType()) {
         case TelephonyManager.NETWORK_TYPE_IDEN:
         case TelephonyManager.NETWORK_TYPE_CDMA: