OSDN Git Service

CMFileManager: Don't show unmounted volumes in PickerActivity
authorRaj Yengisetty <rajesh@cyngn.com>
Wed, 4 Feb 2015 02:32:15 +0000 (18:32 -0800)
committerSteve Kondik <shade@chemlab.org>
Thu, 5 Feb 2015 22:10:17 +0000 (22:10 +0000)
Change-Id: I628077e6132ffb4aa9f561484630e1f29b1188a5

src/com/cyanogenmod/filemanager/activities/PickerActivity.java

index f2ae5a1..e269e3a 100644 (file)
@@ -34,6 +34,7 @@ import android.os.Bundle;
 import android.os.Environment;
 import android.os.Handler;
 import android.os.storage.StorageVolume;
+import android.text.TextUtils;
 import android.util.DisplayMetrics;
 import android.util.Log;
 import android.view.View;
@@ -600,10 +601,23 @@ public class PickerActivity extends Activity
         if (volumes != null) {
             int cc = volumes.length;
             for (int i = 0; i < cc; i++) {
-                String desc = StorageHelper.getStorageVolumeDescription(this, volumes[i]);
-                CheckableItem item = new CheckableItem(desc, false, false);
-                descriptions.add(item);
+                StorageVolume volume = volumes[i];
+                if (volumes[i] != null) {
+                    String mountedState = volumes[i].getState();
+                    String path = volumes[i].getPath();
+                    if (!Environment.MEDIA_MOUNTED.equalsIgnoreCase(mountedState) &&
+                            !Environment.MEDIA_MOUNTED_READ_ONLY.equalsIgnoreCase(mountedState)) {
+                        Log.w(TAG, "Ignoring '" + path + "' with state of '"+ mountedState + "'");
+                        continue;
+                    }
+                    if (!TextUtils.isEmpty(path)) {
+                        String desc = StorageHelper.getStorageVolumeDescription(this, volumes[i]);
+                        CheckableItem item = new CheckableItem(desc, false, false);
+                        descriptions.add(item);
+                    }
+                }
             }
+
         }
         CheckableListAdapter adapter =
                 new CheckableListAdapter(getApplicationContext(), descriptions);