Bug 1062550 - b2g crashes during USB tethering. r=vchang, a=bajaj
authorHenry Chang <hchang@mozilla.com>
Fri, 05 Sep 2014 19:01:07 +0800
changeset 224925 e40762374799c809076ccaccbc066599fd282045
parent 224924 1b01b6d330fd3c5ef2998d725a341c32ffdd8d56
child 224926 e69b76df294c1a8886af2724de99fa99e1137bc8
push id3979
push userraliiev@mozilla.com
push dateMon, 13 Oct 2014 16:35:44 +0000
treeherdermozilla-beta@30f2cc610691 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvchang, bajaj
bugs1062550
milestone34.0a2
Bug 1062550 - b2g crashes during USB tethering. r=vchang, a=bajaj
dom/system/gonk/NetworkManager.js
--- a/dom/system/gonk/NetworkManager.js
+++ b/dom/system/gonk/NetworkManager.js
@@ -811,30 +811,31 @@ NetworkManager.prototype = {
   _usbTetheringSettingsToRead: [],
 
   _oldUsbTetheringEnabledState: null,
 
   // External and internal interface name.
   _tetheringInterface: null,
 
   handleLastRequest: function() {
-    let count = this._requestCount;
-    this._requestCount = 0;
-
-    if (count === 1) {
+    if (this._requestCount === 1) {
+      this._requestCount = 0;
       if (this.wantConnectionEvent) {
         if (this.tetheringSettings[SETTINGS_USB_ENABLED]) {
           this.wantConnectionEvent.call(this);
         }
         this.wantConnectionEvent = null;
       }
       return;
     }
 
-    if (count > 1) {
+    if (this._requestCount > 1) {
+      // Set this._requestCount to 1 to prevent from subsequent usb tethering toggles
+      // triggering |handleUSBTetheringToggle|.
+      this._requestCount = 1;
       this.handleUSBTetheringToggle(this.tetheringSettings[SETTINGS_USB_ENABLED]);
       this.wantConnectionEvent = null;
     }
   },
 
 #ifdef MOZ_B2G_RIL
   dunConnectTimer: Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer),
   /**
@@ -922,22 +923,24 @@ NetworkManager.prototype = {
 #endif
 
   handleUSBTetheringToggle: function(enable) {
     debug("handleUSBTetheringToggle: " + enable);
     if (enable &&
         (this._usbTetheringAction === TETHERING_STATE_ONGOING ||
          this._usbTetheringAction === TETHERING_STATE_ACTIVE)) {
       debug("Usb tethering already connecting/connected.");
+      this._requestCount = 0;
       return;
     }
 
     if (!enable &&
         this._usbTetheringAction === TETHERING_STATE_IDLE) {
       debug("Usb tethering already disconnected.");
+      this._requestCount = 0;
       return;
     }
 
     if (!enable) {
       this.tetheringSettings[SETTINGS_USB_ENABLED] = false;
       gNetworkService.enableUsbRndis(false, this.enableUsbRndisResult.bind(this));
       return;
     }
@@ -1129,40 +1132,40 @@ NetworkManager.prototype = {
     if (success) {
       // If enable is false, don't find usb interface cause it is already down,
       // just use the internal interface in settings.
       if (enable) {
         this._tetheringInterface[TETHERING_TYPE_USB].internalInterface = this.getUsbInterface();
       }
       this.setUSBTethering(enable,
                            this._tetheringInterface[TETHERING_TYPE_USB],
-                           this.usbTetheringResultReport.bind(this));
+                           this.usbTetheringResultReport.bind(this, enable));
     } else {
       this.usbTetheringResultReport("Failed to set usb function");
       throw new Error("failed to set USB Function to adb");
     }
   },
 
-  usbTetheringResultReport: function(error) {
+  usbTetheringResultReport: function(enable, error) {
     let settingsLock = gSettingsService.createLock();
 
     // Disable tethering settings when fail to enable it.
     if (error) {
       this.tetheringSettings[SETTINGS_USB_ENABLED] = false;
       settingsLock.set("tethering.usb.enabled", false, null);
       // Skip others request when we found an error.
       this._requestCount = 0;
       this._usbTetheringAction = TETHERING_STATE_IDLE;
 #ifdef MOZ_B2G_RIL
       if (this.tetheringSettings[SETTINGS_DUN_REQUIRED]) {
         this.handleDunConnection(false);
       }
 #endif
     } else {
-      if (this.tetheringSettings[SETTINGS_USB_ENABLED]) {
+      if (enable) {
         this._usbTetheringAction = TETHERING_STATE_ACTIVE;
       } else {
         this._usbTetheringAction = TETHERING_STATE_IDLE;
 #ifdef MOZ_B2G_RIL
         if (this.tetheringSettings[SETTINGS_DUN_REQUIRED]) {
           this.handleDunConnection(false);
         }
 #endif