package com.studio4plus.homerplayer.util;

import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class FilesystemUtil {

    public static List<File> listRootDirs(Context context) {
        File[] filesDirs;
        if (Build.VERSION.SDK_INT < 19)
            filesDirs = new File[]{ context.getExternalFilesDir(null) };
        else
            filesDirs = API19.getExternalFilesDirs(context);

        List<File> rootDirs = new ArrayList<>(filesDirs.length);
        for (File path : filesDirs) {
            File root = getFSRootForPath(path);
            if (root != null)
                rootDirs.add(root);
        }
        return rootDirs;
    }

    private static File getFSRootForPath(File path) {
        while (path != null && path.isDirectory()) {
            long fsSize = path.getTotalSpace();
            File parent = path.getParentFile();
            if (parent == null || parent.getTotalSpace() != fsSize)
                return path;
            path = parent;
        }
        return path;
    }

    @TargetApi(19)
    private static class API19 {
        public static File[] getExternalFilesDirs(Context context) {
            return context.getExternalFilesDirs(null);
        }
    }
}

@@ -146,20 +146,106 @@
 java.io.
-File
+BufferedReader;%0Aimport java.io.File;%0Aimport java.io.FileReader;%0Aimport java.io.IOException
 ;%0Aimport
@@ -374,32 +374,2265 @@
 text context) %7B%0A
+        List%3CFile%3E rootDirs = listStorageMounts();%0A        for (File rootDir : listSemiPermanentRootDirs(context)) %7B%0A            if (!rootDirs.contains(rootDir))%0A                rootDirs.add(rootDir);%0A        %7D%0A%0A        return rootDirs;%0A    %7D%0A%0A    private static File getFSRootForPath(File path) %7B%0A        while (path != null && path.isDirectory()) %7B%0A            long fsSize = path.getTotalSpace();%0A            File parent = path.getParentFile();%0A            if (parent == null %7C%7C parent.getTotalSpace() != fsSize)%0A                return path;%0A            path = parent;%0A        %7D%0A        return path;%0A    %7D%0A%0A    // Returns all system mount points that start with /storage.%0A    // This is likely to list attached SD cards, including those that are hidden from%0A    // Context.getExternalFilesDir()..%0A    // Some of the returned files may not be accessible due to permissions.%0A    private static List%3CFile%3E listStorageMounts() %7B%0A        List%3CFile%3E mounts = new ArrayList%3C%3E();%0A        File mountsFile = new File(%22/proc/mounts%22);%0A        try %7B%0A            BufferedReader reader = new BufferedReader(new FileReader(mountsFile));%0A            String line;%0A            while ((line = reader.readLine()) != null) %7B%0A                String%5B%5D fields = line.split(%22 +%22);%0A                if (fields.length %3E= 2 && fields%5B1%5D.startsWith(%22/storage%22)) %7B%0A                    mounts.add(new File(fields%5B1%5D));%0A                %7D%0A            %7D%0A        %7D catch (IOException e) %7B%0A            // Ignore, just return as much as is accumulated in mounts.%0A        %7D%0A        return mounts;%0A    %7D%0A%0A    // Returns a list of file system roots on all semi-permanent storage mounts.%0A    // Semi-permanent storage is removable medium that is part of the device (e.g. an SD slot%0A    // inside the battery compartment) and therefore unlikely to be removed often.%0A    // Storage medium that is easily accessible by the user (e.g. an external SD card slot) is%0A    // treated as portable storage.%0A    // The Context.getExternalFilesDir() method only lists semi-permanent storage devices.%0A    //%0A    // See http://source.android.com/devices/storage/traditional.html#multiple-external-storage-devices%0A    private static List%3CFile%3E listSemiPermanentRootDirs(Context context) %7B%0A
         File%5B%5D f
@@ -3048,32 +3048,32 @@
 oot);%0A        %7D%0A
+
         return r
@@ -3092,373 +3092,8 @@
  %7D%0A%0A
-    private static File getFSRootForPath(File path) %7B%0A        while (path != null && path.isDirectory()) %7B%0A            long fsSize = path.getTotalSpace();%0A            File parent = path.getParentFile();%0A            if (parent == null %7C%7C parent.getTotalSpace() != fsSize)%0A                return path;%0A            path = parent;%0A        %7D%0A        return path;%0A    %7D%0A%0A
     

Read /proc/mounts to find more removable media.