[Android] rework storage detection
Sébastien Toque
git at videolan.org
Thu Mar 27 10:41:41 CET 2014
vlc-ports/android | branch: master | Sébastien Toque <xilasz at gmail.com> | Thu Mar 27 10:33:05 2014 +0100| [4ef4f728b8e9ba710043c3396574e383259b1237] | committer: Adrien Maglo
rework storage detection
Signed-off-by: Adrien Maglo <magsoft at videolan.org>
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=4ef4f728b8e9ba710043c3396574e383259b1237
---
vlc-android/src/org/videolan/vlc/Util.java | 66 +++++++++++++---------------
1 file changed, 31 insertions(+), 35 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/Util.java b/vlc-android/src/org/videolan/vlc/Util.java
index 4cdc361..471870d 100644
--- a/vlc-android/src/org/videolan/vlc/Util.java
+++ b/vlc-android/src/org/videolan/vlc/Util.java
@@ -34,6 +34,7 @@ import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
+import java.util.List;
import java.util.Locale;
import java.util.StringTokenizer;
@@ -420,47 +421,42 @@ public class Util {
}
}
- public static String[] getStorageDirectories()
- {
+ private static boolean StartsWith(String[] array, String text) {
+ for (String item : array)
+ if (text.startsWith(item))
+ return true;
+ return false;
+ }
+
+ public static String[] getStorageDirectories() {
String[] dirs = null;
BufferedReader bufReader = null;
+ ArrayList<String> list = new ArrayList<String>();
+ list.add(Environment.getExternalStorageDirectory().getPath());
+
+ List<String> typeWL = Arrays.asList("vfat", "exfat", "sdcardfs");
+ List<String> typeBL = Arrays.asList("tmpfs");
+ String[] mountWL = { "/mnt", "/Removable" };
+ String[] mountBL = { "/mnt/secure", "/mnt/shell", "/mnt/asec", "/mnt/obb", "/mnt/media_rw/extSdCard" };
+ String[] deviceWL = { "/dev/block/vold", "/mnt/media_rw/extSdCard" };
+
try {
bufReader = new BufferedReader(new FileReader("/proc/mounts"));
- ArrayList<String> list = new ArrayList<String>();
- list.add(Environment.getExternalStorageDirectory().getPath());
String line;
- boolean addedExtSdCard = false;
while((line = bufReader.readLine()) != null) {
- if(line.contains("vfat") || line.contains("exfat") ||
- line.contains("sdcardfs") || line.contains("/mnt") ||
- line.contains("/Removable")) {
- StringTokenizer tokens = new StringTokenizer(line, " ");
- String s = tokens.nextToken();
- s = tokens.nextToken(); // Take the second token, i.e. mount point
-
- if (list.contains(s))
- continue;
-
- if (line.contains("extSdCard") && line.contains("sdcardfs") && !addedExtSdCard) {
- addedExtSdCard = true;
- list.add(s);
- }
- else if (line.contains("/dev/block/vold")) {
- boolean isExtSdCardEntry = line.contains("extSdCard");
- if (!isExtSdCardEntry || !addedExtSdCard) {
- if (!line.startsWith("tmpfs") &&
- !line.startsWith("/dev/mapper") &&
- !s.startsWith("/mnt/secure") &&
- !s.startsWith("/mnt/shell") &&
- !s.startsWith("/mnt/asec") &&
- !s.startsWith("/mnt/obb")
- ) {
- addedExtSdCard = addedExtSdCard || isExtSdCardEntry;
- list.add(s);
- }
- }
- }
- }
+
+ StringTokenizer tokens = new StringTokenizer(line, " ");
+ String device = tokens.nextToken();
+ String mountpoint = tokens.nextToken();
+ String type = tokens.nextToken();
+
+ // skip if already in list or if type/mountpoint is blacklisted
+ if (list.contains(mountpoint) || typeBL.contains(type) || StartsWith(mountBL, mountpoint))
+ continue;
+
+ // check that device is in whitelist, and either type or mountpoint is in a whitelist
+ if (StartsWith(deviceWL, device) && (typeWL.contains(type) || StartsWith(mountWL, mountpoint)))
+ list.add(mountpoint);
}
dirs = new String[list.size()];
More information about the Android
mailing list