Bug 1258428: If activity is active, always listen for network status updates r=sebastian
authorGrigory Kruglov <gkruglov@mozilla.com>
Fri, 06 May 2016 17:31:52 -0700
changeset 322690 911e01d2cbe0f75e5645aa5070e179885a1dbef7
parent 322689 e155723908e3c2aa129f12e7000ae416d91f5c70
child 322691 d620b3d2247d897de801062c15e314f085eef786
push id9671
push userraliiev@mozilla.com
push dateMon, 06 Jun 2016 20:27:52 +0000
treeherdermozilla-aurora@cea65ca3d0bd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebastian
bugs1258428
milestone49.0a1
Bug 1258428: If activity is active, always listen for network status updates r=sebastian MozReview-Commit-ID: HwTmnOReUBb
mobile/android/base/java/org/mozilla/gecko/GeckoNetworkManager.java
mobile/android/tests/background/junit4/src/org/mozilla/gecko/GeckoNetworkManagerTest.java
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoNetworkManager.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoNetworkManager.java
@@ -174,16 +174,18 @@ public class GeckoNetworkManager extends
                         return null;
                 }
             case OnNoListeners:
                 switch (event) {
                     case stop:
                         return ManagerState.OffNoListeners;
                     case enableNotifications:
                         return ManagerState.OnWithListeners;
+                    case receivedUpdate:
+                        return ManagerState.OnNoListeners;
                     default:
                         return null;
                 }
             case OnWithListeners:
                 switch (event) {
                     case stop:
                         return ManagerState.OffWithListeners;
                     case disableNotifications:
@@ -219,43 +221,50 @@ public class GeckoNetworkManager extends
         // NB: network state might be queried via getCurrentInformation at any time; pre-rewrite behaviour was
         // that network state was updated whenever enableNotifications was called. To avoid deviating
         // from previous behaviour and causing weird side-effects, we call updateNetworkStateAndConnectionType
         // whenever notifications are enabled.
         switch (currentState) {
             case OffNoListeners:
                 if (event == ManagerEvent.start) {
                     updateNetworkStateAndConnectionType();
+                    registerBroadcastReceiver();
                 }
                 if (event == ManagerEvent.enableNotifications) {
                     updateNetworkStateAndConnectionType();
                 }
                 break;
             case OnNoListeners:
+                if (event == ManagerEvent.receivedUpdate) {
+                    updateNetworkStateAndConnectionType();
+                    sendNetworkStateToListeners();
+                }
                 if (event == ManagerEvent.enableNotifications) {
                     updateNetworkStateAndConnectionType();
                     registerBroadcastReceiver();
                 }
+                if (event == ManagerEvent.stop) {
+                    unregisterBroadcastReceiver();
+                }
                 break;
             case OnWithListeners:
                 if (event == ManagerEvent.receivedUpdate) {
                     updateNetworkStateAndConnectionType();
                     sendNetworkStateToListeners();
                 }
                 if (event == ManagerEvent.stop) {
                     unregisterBroadcastReceiver();
                 }
-                if (event == ManagerEvent.disableNotifications) {
-                    unregisterBroadcastReceiver();
-                }
+                /* no-op event: ManagerEvent.disableNotifications */
                 break;
             case OffWithListeners:
                 if (event == ManagerEvent.start) {
                     registerBroadcastReceiver();
                 }
+                /* no-op event: ManagerEvent.disableNotifications */
                 break;
             default:
                 throw new IllegalStateException("Unknown current state: " + currentState.name());
         }
     }
 
     /**
      * Update current network state and connection types.
--- a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/GeckoNetworkManagerTest.java
+++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/GeckoNetworkManagerTest.java
@@ -25,19 +25,19 @@ public class GeckoNetworkManagerTest {
         assertNull(GeckoNetworkManager.getNextState(testingState, ManagerEvent.stop));
         assertNull(GeckoNetworkManager.getNextState(testingState, ManagerEvent.receivedUpdate));
         assertEquals(ManagerState.OnNoListeners, GeckoNetworkManager.getNextState(testingState, ManagerEvent.start));
         assertEquals(ManagerState.OffWithListeners, GeckoNetworkManager.getNextState(testingState, ManagerEvent.enableNotifications));
 
         testingState = ManagerState.OnNoListeners;
         assertNull(GeckoNetworkManager.getNextState(testingState, ManagerEvent.start));
         assertNull(GeckoNetworkManager.getNextState(testingState, ManagerEvent.disableNotifications));
-        assertNull(GeckoNetworkManager.getNextState(testingState, ManagerEvent.receivedUpdate));
         assertEquals(ManagerState.OnWithListeners, GeckoNetworkManager.getNextState(testingState, ManagerEvent.enableNotifications));
         assertEquals(ManagerState.OffNoListeners, GeckoNetworkManager.getNextState(testingState, ManagerEvent.stop));
+        assertEquals(ManagerState.OnNoListeners, GeckoNetworkManager.getNextState(testingState, ManagerEvent.receivedUpdate));
 
         testingState = ManagerState.OnWithListeners;
         assertNull(GeckoNetworkManager.getNextState(testingState, ManagerEvent.start));
         assertNull(GeckoNetworkManager.getNextState(testingState, ManagerEvent.enableNotifications));
         assertEquals(ManagerState.OffWithListeners, GeckoNetworkManager.getNextState(testingState, ManagerEvent.stop));
         assertEquals(ManagerState.OnNoListeners, GeckoNetworkManager.getNextState(testingState, ManagerEvent.disableNotifications));
         assertEquals(ManagerState.OnWithListeners, GeckoNetworkManager.getNextState(testingState, ManagerEvent.receivedUpdate));