Bug 1059086 - Stop and start MTP server properly when USB cable is unplugged and replugged. r=Alphan
authorDave Hylands <dhylands@mozilla.com>
Thu, 28 Aug 2014 13:13:10 -0700
changeset 202189 4eaaa8ce26afcd114e9423cd2ce47d34c15ad0d4
parent 202188 812f62c9f703fbce4680618019db53e193218689
child 202190 dcece1b6ae346dc7af56198e0565cf800aaa2bf0
push id10143
push userdhylands@mozilla.com
push dateThu, 28 Aug 2014 20:13:22 +0000
treeherderb2g-inbound@4eaaa8ce26af [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersAlphan
bugs1059086
milestone34.0a1
Bug 1059086 - Stop and start MTP server properly when USB cable is unplugged and replugged. r=Alphan
dom/system/gonk/AutoMounter.cpp
--- a/dom/system/gonk/AutoMounter.cpp
+++ b/dom/system/gonk/AutoMounter.cpp
@@ -751,40 +751,48 @@ AutoMounter::UpdateState()
         // The USB layer has been configured. Now we can go ahead and start
         // the MTP server.
         StartMtpServer();
         SetState(STATE_MTP_STARTED);
       }
       break;
 
     case STATE_MTP_STARTED:
-      if (usbCablePluggedIn) {
-        if (mtpConfigured && mtpEnabled) {
-          // Everything is still good. Leave the MTP server running
-          break;
-        }
-        DBG("STATE_MTP_STARTED: About to StopMtpServer "
-            "mtpConfigured = %d mtpEnabled = %d usbCablePluggedIn: %d",
-            mtpConfigured, mtpEnabled, usbCablePluggedIn);
-        StopMtpServer();
-        if (umsAvail) {
-          // Switch back to UMS
-          SetUsbFunction(USB_FUNC_UMS);
-          SetState(STATE_UMS_CONFIGURING);
-          break;
-        }
+      if (usbCablePluggedIn && mtpConfigured && mtpEnabled) {
+        // Everything is still good. Leave the MTP server running
+        break;
+      }
+      DBG("STATE_MTP_STARTED: About to StopMtpServer "
+          "mtpConfigured = %d mtpEnabled = %d usbCablePluggedIn: %d",
+          mtpConfigured, mtpEnabled, usbCablePluggedIn);
+      StopMtpServer();
+      if (umsAvail) {
+        // Switch back to UMS
+        SetUsbFunction(USB_FUNC_UMS);
+        SetState(STATE_UMS_CONFIGURING);
+        break;
       }
       SetState(STATE_IDLE);
       break;
 
     case STATE_UMS_CONFIGURING:
       // While configuring, the USB configuration state will change from
       // CONFIGURED -> CONNECTED -> DISCONNECTED -> CONNECTED -> CONFIGURED
-      // so we don't check for cable unplugged here.
+      // so we don't check for cable unplugged here. However, having said
+      // that, we'll often sit in this state while the cable is unplugged,
+      // since we might not get any events until the cable gets plugged back
+      // in. This is why we need to check for mtpEnabled once we get the
+      // configured event.
       if (umsConfigured) {
+        if (mtpEnabled) {
+          // MTP was enabled. Start reconfiguring.
+          SetState(STATE_MTP_CONFIGURING);
+          SetUsbFunction(USB_FUNC_MTP);
+          break;
+        }
         SetState(STATE_UMS_CONFIGURED);
       }
       break;
 
     case STATE_UMS_CONFIGURED:
       if (usbCablePluggedIn) {
         if (mtpEnabled) {
           // MTP was enabled. Start reconfiguring.