packages/apps/CMFileManager
Revision | 6dfc729a8790c23d2efda4f21bab8123336ae383 (tree) |
---|---|
Zeit | 2016-01-26 11:40:26 |
Autor | Paulo Sergio Travaglia <pstglia@gmai...> |
Commiter | Chih-Wei Huang |
Change method for getting external storage on marshmallow
The new components/features introduced with marshmallow
(vold 3.0) required a new method for retrieving
external/removable storage devices
These changes were based and use part of the following code:
- Storage access implemented on Settings (uses VolumeInfo class
- getVolumeList method from MountService class
@@ -19,6 +19,12 @@ import android.content.Context; | ||
19 | 19 | import android.os.Environment; |
20 | 20 | import android.os.storage.StorageManager; |
21 | 21 | import android.os.storage.StorageVolume; |
22 | +import android.os.storage.VolumeInfo; | |
23 | +import android.os.UserHandle; | |
24 | + | |
25 | +import java.util.ArrayList; | |
26 | +import java.util.Collections; | |
27 | +import java.util.List; | |
22 | 28 | |
23 | 29 | import com.cyanogenmod.filemanager.FileManagerApplication; |
24 | 30 | import com.cyanogenmod.filemanager.R; |
@@ -50,9 +56,22 @@ public final class StorageHelper { | ||
50 | 56 | //IMP!! Android SDK doesn't have a "getVolumeList" but is supported by CM10. |
51 | 57 | //Use reflect to get this value (if possible) |
52 | 58 | try { |
59 | + | |
60 | + final ArrayList<StorageVolume> res = new ArrayList<>(); | |
61 | + final int userId = UserHandle.myUserId(); | |
62 | + | |
53 | 63 | StorageManager sm = (StorageManager) ctx.getSystemService(Context.STORAGE_SERVICE); |
54 | - Method method = sm.getClass().getMethod("getVolumeList"); //$NON-NLS-1$ | |
55 | - sStorageVolumes = (StorageVolume[])method.invoke(sm); | |
64 | + final List<VolumeInfo> volumes = sm.getVolumes(); | |
65 | + Collections.sort(volumes, VolumeInfo.getDescriptionComparator()); | |
66 | + | |
67 | + for (VolumeInfo vol : volumes) { | |
68 | + if (vol.getType() == VolumeInfo.TYPE_PUBLIC || vol.getType() == VolumeInfo.TYPE_EMULATED) { | |
69 | + final StorageVolume userVol = vol.buildStorageVolume(ctx, userId, false); | |
70 | + res.add(userVol); | |
71 | + } | |
72 | + } | |
73 | + | |
74 | + sStorageVolumes = res.toArray(new StorageVolume[res.size()]); | |
56 | 75 | |
57 | 76 | } catch (Exception ex) { |
58 | 77 | //Ignore. Android SDK StorageManager class doesn't have this method |