Bug 792506 - AutoMounter should not allow UMS to be disabled while USB cable is plugged in. r=qDot
authorDave Hylands <dhylands@gmail.com>
Thu, 20 Sep 2012 00:02:19 -0700
changeset 107744 9ba0ef2df8a1f85a4030b3de2d1cd65cd90ac74b
parent 107743 b805572c0c40b45b1198299bfae5560c2b41f698
child 107745 30a90cdc3618f715e62770ba9f5fba003e76e4be
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
reviewersqDot
bugs792506
milestone18.0a1
Bug 792506 - AutoMounter should not allow UMS to be disabled while USB cable is plugged in. r=qDot
dom/system/gonk/AutoMounter.cpp
--- a/dom/system/gonk/AutoMounter.cpp
+++ b/dom/system/gonk/AutoMounter.cpp
@@ -248,16 +248,31 @@ public:
   void SetMode(int32_t aMode)
   {
     if ((aMode == AUTOMOUNTER_DISABLE_WHEN_UNPLUGGED) &&
         (mMode == AUTOMOUNTER_DISABLE)) {
       // If it's already disabled, then leave it as disabled.
       // AUTOMOUNTER_DISABLE_WHEN_UNPLUGGED implies "enabled until unplugged"
       aMode = AUTOMOUNTER_DISABLE;
     }
+
+    if ((aMode == AUTOMOUNTER_DISABLE) &&
+        (mMode == AUTOMOUNTER_ENABLE) && IsUsbCablePluggedIn()) {
+      // On many devices (esp non-Samsung), we can't force the disable, so we
+      // need to defer until the USB cable is actually unplugged.
+      // See bug 777043.
+      //
+      // Otherwise our attempt to disable it will fail, and we'll wind up in a bad
+      // state where the AutoMounter thinks that Sharing has been turned off, but
+      // the files are actually still being Shared because the attempt to unshare
+      // failed.
+      LOG("Attempting to disable UMS. Deferring until USB cable is unplugged.");
+      aMode = AUTOMOUNTER_DISABLE_WHEN_UNPLUGGED;
+    }
+
     if (aMode != mMode) {
       LOG("Changing mode from '%s' to '%s'", ModeStr(mMode), ModeStr(aMode));
       mMode = aMode;
       DBG("Calling UpdateState due to mode set to %d", mMode);
       UpdateState();
     }
   }