Bug 1061030 - Register wifi listener in GeckoNetworkManager constructor. r=mfinkle
authorWes Johnston <wjohnston@mozilla.com>
Wed, 03 Sep 2014 09:44:27 -0700
changeset 203254 8a5f6d1f48828680b069abbda59f5d4d0055a2df
parent 203253 a8f37943e690e3c0f2f55eb34bb67e2c946e032b
child 203255 e4d0c551410ea750bb84599ac4b6eefc6dfa9cc5
push id27424
push userryanvm@gmail.com
push dateWed, 03 Sep 2014 19:35:53 +0000
treeherdermozilla-central@bfef88becbba [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs1061030
milestone35.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 1061030 - Register wifi listener in GeckoNetworkManager constructor. r=mfinkle
mobile/android/base/GeckoApp.java
mobile/android/base/GeckoNetworkManager.java
--- a/mobile/android/base/GeckoApp.java
+++ b/mobile/android/base/GeckoApp.java
@@ -2072,16 +2072,17 @@ public abstract class GeckoApp
         if (mContactService != null)
             mContactService.destroy();
         if (mPromptService != null)
             mPromptService.destroy();
         if (mTextSelection != null)
             mTextSelection.destroy();
         NotificationHelper.destroy();
         IntentHelper.destroy();
+        GeckoNetworkManager.destroy();
 
         if (SmsManager.getInstance() != null) {
             SmsManager.getInstance().stop();
             if (isFinishing())
                 SmsManager.getInstance().shutdown();
         }
 
         final HealthRecorder rec = mHealthRecorder;
--- a/mobile/android/base/GeckoNetworkManager.java
+++ b/mobile/android/base/GeckoNetworkManager.java
@@ -34,16 +34,22 @@ import android.util.Log;
  * connection type defined in Network Information API version 3.
  */
 
 public class GeckoNetworkManager extends BroadcastReceiver implements NativeEventListener {
     private static final String LOGTAG = "GeckoNetworkManager";
 
     static private final GeckoNetworkManager sInstance = new GeckoNetworkManager();
 
+    public static void destroy() {
+        if (sInstance != null) {
+            sInstance.onDestroy();
+        }
+    }
+
     // Connection Type defined in Network Information API v3.
     private enum ConnectionType {
         CELLULAR(0),
         BLUETOOTH(1),
         ETHERNET(2),
         WIFI(3),
         OTHER(4),
         NONE(5);
@@ -55,16 +61,24 @@ public class GeckoNetworkManager extends
         }
     }
 
     private enum InfoType {
         MCC,
         MNC
     }
 
+    private GeckoNetworkManager() {
+        EventDispatcher.getInstance().registerGeckoThreadListener(this, "Wifi:Enable");
+    }
+
+    private void onDestroy() {
+        EventDispatcher.getInstance().unregisterGeckoThreadListener(this, "Wifi:Enable");
+    }
+
     private ConnectionType mConnectionType = ConnectionType.NONE;
     private final IntentFilter mNetworkFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
 
     // Whether the manager should be listening to Network Information changes.
     private boolean mShouldBeListening;
 
     // Whether the manager should notify Gecko that a change in Network
     // Information happened.
@@ -91,18 +105,16 @@ public class GeckoNetworkManager extends
         }
 
         mShouldBeListening = true;
         updateConnectionType();
 
         if (mShouldNotify) {
             startListening();
         }
-
-        EventDispatcher.getInstance().registerGeckoThreadListener((NativeEventListener)this, "Wifi:Enable");
     }
 
     private void startListening() {
         final Context appContext = mApplicationContext;
         if (appContext == null) {
             Log.w(LOGTAG, "Not registering receiver: no context!");
             return;
         }
@@ -112,18 +124,16 @@ public class GeckoNetworkManager extends
     }
 
     public void stop() {
         mShouldBeListening = false;
 
         if (mShouldNotify) {
             stopListening();
         }
-
-        EventDispatcher.getInstance().unregisterGeckoThreadListener((NativeEventListener)this, "Wifi:Enable");
     }
 
     @Override
     public void handleMessage(final String event, final NativeJSObject message,
                               final EventCallback callback) {
         if (event.equals("Wifi:Enable")) {
             final WifiManager mgr = (WifiManager) mApplicationContext.getSystemService(Context.WIFI_SERVICE);