services: MountService: Refactor MountService for vold2

Squash of the following:
services: MountService: Rework the way volume states are handled
MountService: Add new API for directly getting volume state via a mount point
Environment: Switch from using system property for external storage state.
MountService: Add support for UMS
MountService: Fix a few bugs
services: MountService: Add support for mount-on-insertion
services: MountService: Add some debugging around UMS
services: MountService: Fix some UMS bugs and clean-up startup mount code

Signed-off-by: San Mehat <san@google.com>
diff --git a/core/java/android/os/Environment.java b/core/java/android/os/Environment.java
index 6212b17..eed2af7 100644
--- a/core/java/android/os/Environment.java
+++ b/core/java/android/os/Environment.java
@@ -18,6 +18,8 @@
 
 import java.io.File;
 
+import android.os.IMountService;
+
 /**
  * Provides access to environment variables.
  */
@@ -28,6 +30,8 @@
 
     private static final String SYSTEM_PROPERTY_EFS_ENABLED = "persist.security.efs.enabled";
 
+    private static IMountService mMntSvc = null;
+
     /**
      * Gets the Android root directory.
      */
@@ -167,9 +171,19 @@
 
     /**
      * Gets the current state of the external storage device.
+     * Note: This call should be deprecated as it doesn't support
+     * multiple volumes.
      */
     public static String getExternalStorageState() {
-        return SystemProperties.get("EXTERNAL_STORAGE_STATE", MEDIA_REMOVED);
+        try {
+            if (mMntSvc == null) {
+                mMntSvc = IMountService.Stub.asInterface(ServiceManager
+                                                         .getService("mount"));
+            }
+            return mMntSvc.getVolumeState(getExternalStorageDirectory().toString());
+        } catch (android.os.RemoteException rex) {
+            return Environment.MEDIA_REMOVED;
+        }
     }
 
     static File getDirectory(String variableName, String defaultPath) {