Bug 746069: Part 1: Integration with netd daemon using IPC. r=philikon
authorAlbert Crespell <acperez@tid.es>
Thu, 04 Oct 2012 18:39:59 +0200
changeset 115565 b2e90f7448af6dc5208562337f6f27f1ca0f7abe
parent 115564 691ed91f9413d78041ddb7d532cd9d1e3e7d2228
child 115566 47f9a55ac25394cdb67d240ba224951e1f6ef1d3
push id1708
push userakeybl@mozilla.com
push dateMon, 19 Nov 2012 21:10:21 +0000
treeherdermozilla-beta@27b14fe50103 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersphilikon
bugs746069
milestone18.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 746069: Part 1: Integration with netd daemon using IPC. r=philikon
dom/system/gonk/NetworkManager.js
dom/system/gonk/net_worker.js
dom/system/gonk/nsINetworkManager.idl
--- a/dom/system/gonk/NetworkManager.js
+++ b/dom/system/gonk/NetworkManager.js
@@ -274,16 +274,43 @@ NetworkManager.prototype = {
   active: null,
   _overriddenActive: null,
 
   overrideActive: function overrideActive(network) {
     this._overriddenActive = network;
     this.setAndConfigureActive();
   },
 
+  getNetworkInterfaceStats: function getNetworkInterfaceStats(connectionType, callback) {
+    let iface = this.getNetworkInterface(connectionType);
+
+    if (!iface) {
+      debug("There is no interface registered for network type " + connectionType);
+      return false;
+    }
+
+    debug("getNetworkInterfaceStats for " + iface.name);
+
+    let params = {
+      cmd: "getNetworkInterfaceStats",
+      ifname: iface.name,
+      connType: connectionType
+    };
+
+    params.report = true;
+    params.isAsync = true;
+
+    this.controlMessage(params, function(result) {
+      let success = result.resultCode >= NETD_COMMAND_OKAY && result.resultCode < NETD_COMMAND_ERROR;
+      callback.networkStatsAvailable(success, result.connType, result.rxBytes, result.txBytes, result.date);
+    });
+
+    return true;
+  },
+
   // Helpers
 
   controlMessage: function controlMessage(params, callback) {
     if (callback) {
       let id = callback.name;
       params.id = id;
       this.controlCallbacks[id] = callback;
     }
--- a/dom/system/gonk/net_worker.js
+++ b/dom/system/gonk/net_worker.js
@@ -97,16 +97,30 @@ function usbTetheringFail(params) {
 }
 
 function usbTetheringSuccess(params) {
   // Notify the main thread.
   postMessage(params);
   return true;
 }
 
+function networkInterfaceStatsFail(params) {
+  // Notify the main thread.
+  postMessage(params);
+  return true;
+}
+
+function networkInterfaceStatsSuccess(params) {
+  // Notify the main thread.
+  params.txBytes = parseFloat(params.resultReason);
+
+  postMessage(params);
+  return true;
+}
+
 /**
  * Get network interface properties from the system property table.
  *
  * @param ifname
  *        Name of the network interface.
  */
 function getIFProperties(ifname) {
   let gateway_str = libcutils.property_get("net." + ifname + ".gw");
@@ -348,16 +362,28 @@ function startSoftAP(params, callback) {
   return doCommand(command, callback);
 }
 
 function stopSoftAP(params, callback) {
   let command = "softap stopap";
   return doCommand(command, callback);
 }
 
+function getRxBytes(params, callback) {
+  let command = "interface readrxcounter " + params.ifname;
+  return doCommand(command, callback);
+}
+
+function getTxBytes(params, callback) {
+  params.rxBytes = parseFloat(params.resultReason);
+
+  let command = "interface readtxcounter " + params.ifname;
+  return doCommand(command, callback);
+}
+
 // The command format is "softap set wlan0 wl0.1 hotspot456 open null 6 0 8".
 function setAccessPoint(params, callback) {
   let command = "softap set " + params.ifname +
                 " " + params.wifictrlinterfacename +
                 " " + params.ssid +
                 " " + params.security +
                 " " + params.key +
                 " " + "6 0 8";
@@ -530,16 +556,34 @@ function setUSBTethering(params) {
     // Disable USB tetehring.
     debug("Stopping USB Tethering on " +
            params.internalIfname + "<->" + params.externalIfname);
     chain(params, gUSBDisableChain, usbTetheringFail);
   }
   return true;
 }
 
+let gNetworkInterfaceStatsChain = [getRxBytes,
+                                   getTxBytes,
+                                   networkInterfaceStatsSuccess];
+
+/**
+ * handling main thread's get network interface stats request
+ */
+function getNetworkInterfaceStats(params) {
+  debug("getNetworkInterfaceStats: " + params.ifname);
+
+  params.rxBytes = -1;
+  params.txBytes = -1;
+  params.date = new Date();
+
+  chain(params, gNetworkInterfaceStatsChain, networkInterfaceStatsFail);
+  return true;
+}
+
 let debug;
 if (DEBUG) {
   debug = function (s) {
     dump("Network Worker: " + s + "\n");
   };
 } else {
   debug = function (s) {};
 }
--- a/dom/system/gonk/nsINetworkManager.idl
+++ b/dom/system/gonk/nsINetworkManager.idl
@@ -94,20 +94,30 @@ interface nsIWifiTetheringCallback : nsI
    *
    * @param error
    *        An error message if the operation wasn't successful,
    *        or `null` if it was.
    */
   void wifiTetheringEnabledChange(in jsval error);
 };
 
+[scriptable, function, uuid(9a887e18-b879-4bb1-8663-238bc4234ba0)]
+interface nsINetworkStatsCallback : nsISupports
+{
+  void networkStatsAvailable(in boolean success,
+                             in short connType,
+                             in unsigned long rxBytes,
+                             in unsigned long txBytes,
+                             in jsval date);
+};
+
 /**
  * Manage network interfaces.
  */
-[scriptable, uuid(a02de6b0-fb25-11e1-a21f-0800200c9a66)]
+[scriptable, uuid(4bee9633-47ed-47ae-b92b-3e0679087561)]
 interface nsINetworkManager : nsISupports
 {
   /**
    * Register the given network interface with the network manager.
    *
    * Consumers will be notified with the 'network-interface-registered'
    * observer notification.
    *
@@ -183,9 +193,24 @@ interface nsINetworkManager : nsISupport
    * @param network
    *        The Wifi network interface with at least name of network interface.
    * @param callback
    *        Callback function used to report status to WifiManager.
    */
   void setWifiTethering(in boolean enabled,
                         in nsINetworkInterface networkInterface,
                         in nsIWifiTetheringCallback callback);
+
+  /**
+   * Retrieve network interface stats.
+   *
+   * @param networkType
+   *        Select the Network interface to request estats.
+   *
+   * @param callback
+   *        Callback to notify result and provide stats, connectionType
+   *        and the date when stats are retrieved
+   *
+   * @return false if there is no interface registered for the networkType param.
+   */
+  boolean getNetworkInterfaceStats(in short networkType, in nsINetworkStatsCallback callback);
+
 };