Android-x86
Fork
Faire un don

  • R/O
  • HTTP
  • SSH
  • HTTPS

packages-apps-CMFileManager: Commit

packages/apps/CMFileManager


Commit MetaInfo

Révision6dfc729a8790c23d2efda4f21bab8123336ae383 (tree)
l'heure2016-01-26 11:40:26
AuteurPaulo Sergio Travaglia <pstglia@gmai...>
CommiterChih-Wei Huang

Message de Log

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

to list all connected disks (external and emulated)
see refresh method from class StorageSettings
=> packages/apps/Settings/src/com/android/settings/deviceinfo
=> StorageSettings.java

- getVolumeList method from MountService class

(converts VolumeInfo ArrayList item into a StorageVolume
element, which is used by CMFileManager to iterate
contents and build bookmarks):
=> frameworks/base/services/core/java/com/android/server/
=> MountService.java

Change Summary

Modification

--- a/src/com/cyanogenmod/filemanager/util/StorageHelper.java
+++ b/src/com/cyanogenmod/filemanager/util/StorageHelper.java
@@ -19,6 +19,12 @@ import android.content.Context;
1919 import android.os.Environment;
2020 import android.os.storage.StorageManager;
2121 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;
2228
2329 import com.cyanogenmod.filemanager.FileManagerApplication;
2430 import com.cyanogenmod.filemanager.R;
@@ -50,9 +56,22 @@ public final class StorageHelper {
5056 //IMP!! Android SDK doesn't have a "getVolumeList" but is supported by CM10.
5157 //Use reflect to get this value (if possible)
5258 try {
59+
60+ final ArrayList<StorageVolume> res = new ArrayList<>();
61+ final int userId = UserHandle.myUserId();
62+
5363 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()]);
5675
5776 } catch (Exception ex) {
5877 //Ignore. Android SDK StorageManager class doesn't have this method
Afficher sur ancien navigateur de dépôt.