Bug 961571 - Part 3: Handle ims apn type in NetworkManager. r=hsinyi
authorEdgar Chen <echen@mozilla.com>
Wed, 26 Feb 2014 00:08:00 +0800
changeset 171411 cb047a99c13c6e774672a861426a4923b57feb81
parent 171410 d57fbc7bdd37f9e944244dbfb2c94288820481ce
child 171412 e7eda63c0ee77f92371b14171685e2f78e6e3c6e
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewershsinyi
bugs961571
milestone30.0a1
Bug 961571 - Part 3: Handle ims apn type in NetworkManager. r=hsinyi
dom/system/gonk/NetworkInterfaceListService.js
dom/system/gonk/NetworkManager.js
--- a/dom/system/gonk/NetworkInterfaceListService.js
+++ b/dom/system/gonk/NetworkInterfaceListService.js
@@ -30,17 +30,20 @@ NetworkInterfaceListService.prototype = 
       cpmm.sendSyncMessage(
         'NetworkInterfaceList:ListInterface',
         {
           excludeSupl: (aConditions &
                         Ci.nsINetworkInterfaceListService.
                         LIST_NOT_INCLUDE_SUPL_INTERFACES) != 0,
           excludeMms: (aConditions &
                        Ci.nsINetworkInterfaceListService.
-                       LIST_NOT_INCLUDE_MMS_INTERFACES) != 0
+                       LIST_NOT_INCLUDE_MMS_INTERFACES) != 0,
+          excludeIms: (aConditions &
+                       Ci.nsINetworkInterfaceListService.
+                       LIST_NOT_INCLUDE_IMS_INTERFACES) != 0
         }
       )[0]);
   }
 };
 
 function NetworkInterfaceList (aInterfaces) {
   this._interfaces = aInterfaces;
 }
--- a/dom/system/gonk/NetworkManager.js
+++ b/dom/system/gonk/NetworkManager.js
@@ -187,19 +187,17 @@ NetworkManager.prototype = {
     switch (topic) {
       case TOPIC_INTERFACE_STATE_CHANGED:
         let network = subject.QueryInterface(Ci.nsINetworkInterface);
         debug("Network " + network.name + " changed state to " + network.state);
         switch (network.state) {
           case Ci.nsINetworkInterface.NETWORK_STATE_CONNECTED:
 #ifdef MOZ_B2G_RIL
             // Add host route for data calls
-            if (network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE ||
-                network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_MMS ||
-                network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_SUPL) {
+            if (this.isNetworkTypeMobile(network.type)) {
               gNetworkService.removeHostRoutes(network.name);
               gNetworkService.addHostRoute(network);
             }
             // Add extra host route. For example, mms proxy or mmsc.
             this.setExtraHostRoute(network);
 #endif
             // Remove pre-created default route and let setAndConfigureActive()
             // to set default route only on preferred network
@@ -218,19 +216,17 @@ NetworkManager.prototype = {
 
             // Probing the public network accessibility after routing table is ready
             CaptivePortalDetectionHelper
               .notify(CaptivePortalDetectionHelper.EVENT_CONNECT, this.active);
             break;
           case Ci.nsINetworkInterface.NETWORK_STATE_DISCONNECTED:
 #ifdef MOZ_B2G_RIL
             // Remove host route for data calls
-            if (network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE ||
-                network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_MMS ||
-                network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_SUPL) {
+            if (this.isNetworkTypeMobile(network.type)) {
               gNetworkService.removeHostRoute(network);
             }
             // Remove extra host route. For example, mms proxy or mmsc.
             this.removeExtraHostRoute(network);
 #endif
             // Remove routing table in /proc/net/route
             if (network.type == Ci.nsINetworkInterface.NETWORK_TYPE_WIFI) {
               gNetworkService.resetRoutingTable(network);
@@ -287,25 +283,27 @@ NetworkManager.prototype = {
         break;
     }
   },
 
   receiveMessage: function(aMsg) {
     switch (aMsg.name) {
       case "NetworkInterfaceList:ListInterface": {
 #ifdef MOZ_B2G_RIL
-        let excludeMms = aMsg.json.exculdeMms;
-        let excludeSupl = aMsg.json.exculdeSupl;
+        let excludeMms = aMsg.json.excludeMms;
+        let excludeSupl = aMsg.json.excludeSupl;
+        let excludeIms = aMsg.json.excludeIms;
 #endif
         let interfaces = [];
 
         for each (let i in this.networkInterfaces) {
 #ifdef MOZ_B2G_RIL
           if ((i.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_MMS && excludeMms) ||
-              (i.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_SUPL && excludeSupl)) {
+              (i.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_SUPL && excludeSupl) ||
+              (i.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_IMS && excludeIms)) {
             continue;
           }
 #endif
           interfaces.push({
             state: i.state,
             type: i.type,
             name: i.name,
             ip: i.ip,
@@ -332,19 +330,17 @@ NetworkManager.prototype = {
     }
     if (network.name in this.networkInterfaces) {
       throw Components.Exception("Network with that name already registered!",
                                  Cr.NS_ERROR_INVALID_ARG);
     }
     this.networkInterfaces[network.name] = network;
 #ifdef MOZ_B2G_RIL
     // Add host route for data calls
-    if (network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE ||
-        network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_MMS ||
-        network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_SUPL) {
+    if (this.isNetworkTypeMobile(network.type)) {
       gNetworkService.addHostRoute(network);
     }
 #endif
     // Remove pre-created default route and let setAndConfigureActive()
     // to set default route only on preferred network
     gNetworkService.removeDefaultRoute(network.name);
     this.setAndConfigureActive();
     Services.obs.notifyObservers(network, TOPIC_INTERFACE_REGISTERED, null);
@@ -358,19 +354,17 @@ NetworkManager.prototype = {
     }
     if (!(network.name in this.networkInterfaces)) {
       throw Components.Exception("No network with that name registered.",
                                  Cr.NS_ERROR_INVALID_ARG);
     }
     delete this.networkInterfaces[network.name];
 #ifdef MOZ_B2G_RIL
     // Remove host route for data calls
-    if (network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE ||
-        network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_MMS ||
-        network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_SUPL) {
+    if (this.isNetworkTypeMobile(network.type)) {
       gNetworkService.removeHostRoute(network);
     }
 #endif
     this.setAndConfigureActive();
     Services.obs.notifyObservers(network, TOPIC_INTERFACE_UNREGISTERED, null);
     debug("Network '" + network.name + "' unregistered.");
   },
 
@@ -394,26 +388,36 @@ NetworkManager.prototype = {
     this._preferredNetworkType = val;
   },
 
   active: null,
   _overriddenActive: null,
 
   overrideActive: function(network) {
 #ifdef MOZ_B2G_RIL
-    if (network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_MMS ||
-        network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_SUPL) {
+    if (this.isNetworkTypeSecondaryMobile(network.type)) {
       throw "Invalid network type";
     }
 #endif
     this._overriddenActive = network;
     this.setAndConfigureActive();
   },
 
 #ifdef MOZ_B2G_RIL
+  isNetworkTypeSecondaryMobile: function(type) {
+    return (type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_MMS ||
+            type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_SUPL ||
+            type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_IMS);
+  },
+
+  isNetworkTypeMobile: function(type) {
+    return (type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE ||
+            this.isNetworkTypeSecondaryMobile(type));
+  },
+
   setExtraHostRoute: function(network) {
     if (network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_MMS) {
       if (!(network instanceof Ci.nsIRilNetworkInterface)) {
         debug("Network for MMS must be an instance of nsIRilNetworkInterface");
         return;
       }
 
       network = network.QueryInterface(Ci.nsIRilNetworkInterface);
@@ -503,24 +507,22 @@ NetworkManager.prototype = {
       }
     }
     if (this.active) {
 #ifdef MOZ_B2G_RIL
       // Give higher priority to default data APN than seconary APN.
       // If default data APN is not connected, we still set default route
       // and DNS on seconary APN.
       if (defaultDataNetwork &&
-          (this.active.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_MMS ||
-           this.active.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_SUPL) &&
+          this.isNetworkTypeSecondaryMobile(this.active.type) &&
           this.active.type != this.preferredNetworkType) {
         this.active = defaultDataNetwork;
       }
       // Don't set default route on secondary APN
-      if (this.active.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_MMS ||
-          this.active.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_SUPL) {
+      if (this.isNetworkTypeSecondaryMobile(this.active.type)) {
         gNetworkService.setDNS(this.active);
       } else {
 #endif // MOZ_B2G_RIL
         gNetworkService.setDefaultRouteAndDNS(this.active, oldActive);
 #ifdef MOZ_B2G_RIL
       }
 #endif
       if (this.active != oldActive) {