vold2: Manually bootstrap the ums switch since switch kernel uevents are broken

Signed-off-by: San Mehat <san@google.com>
diff --git a/main.cpp b/main.cpp
index 3f25ab8..1ffbc7b 100644
--- a/main.cpp
+++ b/main.cpp
@@ -78,6 +78,35 @@
     }
 
     coldboot("/sys/block");
+    /*
+     * Switch uevents are broken.
+     * For now we manually bootstrap
+     * the ums switch
+     */
+    {
+        FILE *fp;
+        char state[255];
+
+        if (!(fp = fopen("/sys/devices/virtual/switch/usb_mass_storage/state",
+                         "r"))) {
+            LOGE("Failed to open ums switch (%s)", strerror(errno));
+            exit(1);
+        }
+        if (!fgets(state, sizeof(state), fp)) {
+            LOGE("Failed to read switch state (%s)", strerror(errno));
+            fclose(fp);
+            exit(1);
+        }
+        if (!strncmp(state, "online", 6)) {
+            LOGD("Bootstrapped ums is connected");
+            vm->notifyUmsConnected(true);
+        } else {
+            LOGD("Bootstrapped ums is disconnected");
+            vm->notifyUmsConnected(false);
+        }
+        fclose(fp);
+    }
+//    coldboot("/sys/class/switch");
 
     /*
      * Now that we're up, we can respond to commands