StorageManager:  Clean up and generalize storage configuration resources

Replace config_emulateExternalStorage, config_externalStorageRemovable,
config_externalStoragePaths, config_externalStorageDescriptions and
config_mtpReserveSpaceMegabytes resources with an XML resource file
to describe the external storages that are available.

Add android.os.storage.StorageVolume class

StorageManager.getVolumeList() now returns an array of StorageVolume

Change-Id: I06ce1451ebf08b82f0ee825d56d59ebf72eacd3d
Signed-off-by: Mike Lockwood <lockwood@android.com>
diff --git a/core/java/android/os/Environment.java b/core/java/android/os/Environment.java
index e308c2c..1f3f6d9 100644
--- a/core/java/android/os/Environment.java
+++ b/core/java/android/os/Environment.java
@@ -20,6 +20,7 @@
 
 import android.content.res.Resources;
 import android.os.storage.IMountService;
+import android.os.storage.StorageVolume;
 import android.util.Log;
 
 /**
@@ -35,7 +36,25 @@
 
     private static final Object mLock = new Object();
 
-    private volatile static Boolean mIsExternalStorageEmulated = null;
+    private volatile static StorageVolume mPrimaryVolume = null;
+
+    private static StorageVolume getPrimaryVolume() {
+        if (mPrimaryVolume == null) {
+            synchronized (mLock) {
+                if (mPrimaryVolume == null) {
+                    try {
+                        IMountService mountService = IMountService.Stub.asInterface(ServiceManager
+                                .getService("mount"));
+                        Parcelable[] volumes = mountService.getVolumeList();
+                        mPrimaryVolume = (StorageVolume)volumes[0];
+                    } catch (Exception e) {
+                        Log.e(TAG, "couldn't talk to MountService", e);
+                    }
+                }
+            }
+        }
+        return mPrimaryVolume;
+    }
 
     /**
      * Gets the Android root directory.
@@ -416,9 +435,8 @@
      * <p>See {@link #getExternalStorageDirectory()} for more information.
      */
     public static boolean isExternalStorageRemovable() {
-        if (isExternalStorageEmulated()) return false;
-        return Resources.getSystem().getBoolean(
-                com.android.internal.R.bool.config_externalStorageRemovable);
+        StorageVolume volume = getPrimaryVolume();
+        return (volume != null && volume.isRemovable());
     }
 
     /**
@@ -435,23 +453,8 @@
      * android.content.ComponentName, boolean)} for additional details.
      */
     public static boolean isExternalStorageEmulated() {
-        if (mIsExternalStorageEmulated == null) {
-            synchronized (mLock) {
-                if (mIsExternalStorageEmulated == null) {
-                    boolean externalStorageEmulated;
-                    try {
-                        IMountService mountService = IMountService.Stub.asInterface(ServiceManager
-                                .getService("mount"));
-                        externalStorageEmulated = mountService.isExternalStorageEmulated();
-                        mIsExternalStorageEmulated = Boolean.valueOf(externalStorageEmulated);
-                    } catch (Exception e) {
-                        Log.e(TAG, "couldn't talk to MountService", e);
-                        return false;
-                    }
-                }
-            }
-        }
-        return mIsExternalStorageEmulated;
+        StorageVolume volume = getPrimaryVolume();
+        return (volume != null && volume.isEmulated());
     }
 
     static File getDirectory(String variableName, String defaultPath) {