From e73bbeb1187b47c8949d143e9679a2110b6d9cd2 Mon Sep 17 00:00:00 2001 From: YraFyra Date: Sun, 21 Oct 2012 23:26:57 +0200 Subject: Search for maps on multiple storages Many devices are mounting /mnt/sdcard to internal flash memory. This memory is then referred to as the ExternalStorage. These devices may still have the possibility to insert an SDcard and that memory is hard to access. This modification will search all mounted memory that is available for the user for map files. --- main/src/cgeo/geocaching/files/FileList.java | 64 ++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 3 deletions(-) (limited to 'main/src/cgeo/geocaching/files/FileList.java') diff --git a/main/src/cgeo/geocaching/files/FileList.java b/main/src/cgeo/geocaching/files/FileList.java index 994c8b0..f3622f9 100644 --- a/main/src/cgeo/geocaching/files/FileList.java +++ b/main/src/cgeo/geocaching/files/FileList.java @@ -17,7 +17,10 @@ import android.os.Handler; import android.os.Message; import android.widget.ArrayAdapter; +import java.io.BufferedReader; import java.io.File; +import java.io.FileReader; +import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; @@ -140,7 +143,7 @@ public abstract class FileList> extends AbstractLis * * @return The folder to start the recursive search in */ - protected abstract File[] getBaseFolders(); + protected abstract List getBaseFolders(); /** * Triggers the deriving class to set the title @@ -163,7 +166,7 @@ public abstract class FileList> extends AbstractLis { if (dir.exists() && dir.isDirectory()) { listDir(list, dir); - if (list.size() > 0) { + if (!list.isEmpty()) { loaded = true; break; } @@ -171,7 +174,7 @@ public abstract class FileList> extends AbstractLis } if (!loaded) { changeWaitDialogHandler.sendMessage(Message.obtain(changeWaitDialogHandler, MSG_SEARCH_WHOLE_SD_CARD, Environment.getExternalStorageDirectory().getName())); - listDir(list, Environment.getExternalStorageDirectory()); + listDirs(list, getStorages()); } } else { Log.w("No external media mounted."); @@ -195,6 +198,12 @@ public abstract class FileList> extends AbstractLis } } + private void listDirs(List list, List directories) { + for (final File dir : directories) { + listDir(list, dir); + } + } + private void listDir(List result, File directory) { if (directory == null || !directory.isDirectory() || !directory.canRead()) { return; @@ -228,7 +237,56 @@ public abstract class FileList> extends AbstractLis } } } + } + /* + * Get all storages available on the device. + * Will include paths like /mnt/sdcard /mnt/usbdisk /mnt/ext_card /mnt/sdcard/ext_card + */ + protected static List getStorages() { + + String extStorage = Environment.getExternalStorageDirectory().getAbsolutePath(); + List storages = new ArrayList(); + storages.add(new File(extStorage)); + File file = new File("/system/etc/vold.fstab"); + if (file.canRead()) { + FileReader fr = null; + BufferedReader br = null; + try { + fr = new FileReader(file); + br = new BufferedReader(fr); + String s = br.readLine(); + while (s != null) { + if (s.startsWith("dev_mount")) { + String[] tokens = StringUtils.split(s); + if (tokens.length >= 3) { + String path = tokens[2]; // mountpoint + if (!extStorage.equals(path)) { + File directory = new File(path); + if (directory.exists() && directory.isDirectory()) { + storages.add(directory); + } + } + } + } + s = br.readLine(); + } + } catch (IOException e) { + Log.e("Could not get additional mount points for user content. " + + "Proceeding with external storage only (" + extStorage + ")"); + } finally { + try { + if (fr != null) { + fr.close(); + } + if (br != null) { + br.close(); + } + } catch (IOException e) { + } + } + } + return storages; } /** -- cgit v1.1