diff options
| author | Matt Garnes <matt@cyngn.com> | 2015-04-01 18:25:45 -0700 |
|---|---|---|
| committer | Rajesh Yengisetty <rajesh@cyngn.com> | 2015-04-02 18:06:34 +0000 |
| commit | 8656db649d0a88fc126e468b7ac81d8d3ea091ae (patch) | |
| tree | 20ecd96ecde38923db52e0497e203fdd55862465 | |
| parent | ad9e51955f2489a4e0d62cccc7f71aaf0d1bc1b7 (diff) | |
| download | android_packages_apps_CMFileManager-8656db649d0a88fc126e468b7ac81d8d3ea091ae.tar.gz android_packages_apps_CMFileManager-8656db649d0a88fc126e468b7ac81d8d3ea091ae.tar.bz2 android_packages_apps_CMFileManager-8656db649d0a88fc126e468b7ac81d8d3ea091ae.zip | |
Fix support for USB OTG.
Properly listen for the Broadcast with an IntentFilter that includes the
path data scheme. Reload the mounted volumes upon ACTION_MEDIA_MOUNTED AND
ACTION_MEDIA_UNMOUNTED.
Change-Id: I71d90978fef05419d912ef2398bf99c23fdefee6
(cherry picked from commit e3922e43c8988c499c85115f1f14bef8c925e1ee)
4 files changed, 25 insertions, 16 deletions
diff --git a/src/com/cyanogenmod/filemanager/activities/NavigationActivity.java b/src/com/cyanogenmod/filemanager/activities/NavigationActivity.java index b0b5043f..c179a8f9 100644 --- a/src/com/cyanogenmod/filemanager/activities/NavigationActivity.java +++ b/src/com/cyanogenmod/filemanager/activities/NavigationActivity.java @@ -22,6 +22,7 @@ import android.app.AlertDialog; import android.app.Dialog; import android.app.SearchManager; import android.content.BroadcastReceiver; +import android.content.ContentResolver; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; @@ -327,11 +328,9 @@ public class NavigationActivity extends Activity NavigationActivity.this.getCurrentNavigationView().refresh(); } } else if (intent.getAction().compareTo( - FileManagerSettings.INTENT_MOUNT_STATUS_CHANGED) == 0) { - onRequestBookmarksRefresh(); - removeUnmountedHistory(); - removeUnmountedSelection(); - } else if(intent.getAction().equals(Intent.ACTION_MEDIA_MOUNTED)) { + FileManagerSettings.INTENT_MOUNT_STATUS_CHANGED) == 0 || + intent.getAction().equals(Intent.ACTION_MEDIA_MOUNTED) || + intent.getAction().equals(Intent.ACTION_MEDIA_UNMOUNTED)) { onRequestBookmarksRefresh(); removeUnmountedHistory(); removeUnmountedSelection(); @@ -510,9 +509,15 @@ public class NavigationActivity extends Activity filter.addAction(Intent.ACTION_TIME_CHANGED); filter.addAction(Intent.ACTION_TIMEZONE_CHANGED); filter.addAction(FileManagerSettings.INTENT_MOUNT_STATUS_CHANGED); - filter.addAction(Intent.ACTION_MEDIA_MOUNTED); registerReceiver(this.mNotificationReceiver, filter); + // This filter needs the file data scheme, so it must be defined separately. + IntentFilter newFilter = new IntentFilter(); + newFilter.addAction(Intent.ACTION_MEDIA_MOUNTED); + newFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED); + newFilter.addDataScheme(ContentResolver.SCHEME_FILE); + registerReceiver(mNotificationReceiver, newFilter); + // Set the theme before setContentView Theme theme = ThemeManager.getCurrentTheme(this); theme.setBaseThemeNoActionBar(this); @@ -1308,7 +1313,7 @@ public class NavigationActivity extends Activity try { // Recovery sdcards from storage manager StorageVolume[] volumes = StorageHelper - .getStorageVolumes(getApplication()); + .getStorageVolumes(getApplication(), true); for (StorageVolume volume: volumes) { if (volume != null) { String mountedState = volume.getState(); @@ -1565,7 +1570,7 @@ public class NavigationActivity extends Activity // Initial directory is the first external sdcard (sdcard, emmc, usb, ...) if (!StorageHelper.isPathInStorageVolume(initialDir)) { StorageVolume[] volumes = - StorageHelper.getStorageVolumes(this); + StorageHelper.getStorageVolumes(this, false); if (volumes != null && volumes.length > 0) { initialDir = volumes[0].getPath(); //Ensure that initial directory is an absolute directory diff --git a/src/com/cyanogenmod/filemanager/activities/PickerActivity.java b/src/com/cyanogenmod/filemanager/activities/PickerActivity.java index faa82e96..2842e96a 100644 --- a/src/com/cyanogenmod/filemanager/activities/PickerActivity.java +++ b/src/com/cyanogenmod/filemanager/activities/PickerActivity.java @@ -596,7 +596,7 @@ public class PickerActivity extends Activity */ private void showStorageVolumesPopUp(View anchor) { // Create a list (but not checkable) - final StorageVolume[] volumes = StorageHelper.getStorageVolumes(PickerActivity.this); + final StorageVolume[] volumes = StorageHelper.getStorageVolumes(PickerActivity.this, false); List<CheckableItem> descriptions = new ArrayList<CheckableItem>(); if (volumes != null) { int cc = volumes.length; diff --git a/src/com/cyanogenmod/filemanager/ui/widgets/NavigationView.java b/src/com/cyanogenmod/filemanager/ui/widgets/NavigationView.java index 9573f682..099f0edb 100644 --- a/src/com/cyanogenmod/filemanager/ui/widgets/NavigationView.java +++ b/src/com/cyanogenmod/filemanager/ui/widgets/NavigationView.java @@ -1372,7 +1372,7 @@ BreadcrumbListener, OnSelectionChangedListener, OnSelectionListener, OnRequestRe //Change to first storage volume StorageVolume[] volumes = - StorageHelper.getStorageVolumes(getContext()); + StorageHelper.getStorageVolumes(getContext(), false); if (volumes != null && volumes.length > 0) { changeCurrentDir(volumes[0].getPath(), false, true, false, null, null); } @@ -1403,7 +1403,7 @@ BreadcrumbListener, OnSelectionChangedListener, OnSelectionListener, OnRequestRe // Check if the path is owned by one of the storage volumes if (!StorageHelper.isPathInStorageVolume(newDir)) { - StorageVolume[] volumes = StorageHelper.getStorageVolumes(getContext()); + StorageVolume[] volumes = StorageHelper.getStorageVolumes(getContext(), false); if (volumes != null && volumes.length > 0) { return volumes[0].getPath(); } diff --git a/src/com/cyanogenmod/filemanager/util/StorageHelper.java b/src/com/cyanogenmod/filemanager/util/StorageHelper.java index 9b04a6b3..ed07fd5e 100644 --- a/src/com/cyanogenmod/filemanager/util/StorageHelper.java +++ b/src/com/cyanogenmod/filemanager/util/StorageHelper.java @@ -41,11 +41,12 @@ public final class StorageHelper { * as first parameter, that AOSP hasn't. * * @param ctx The current context + * @param reload If true, re-query the volumes and do not return the already cached list. * @return StorageVolume[] The storage volumes defined in the system */ @SuppressWarnings("boxing") - public static synchronized StorageVolume[] getStorageVolumes(Context ctx) { - if (sStorageVolumes == null) { + public static synchronized StorageVolume[] getStorageVolumes(Context ctx, boolean reload) { + if (sStorageVolumes == null || reload) { //IMP!! Android SDK doesn't have a "getVolumeList" but is supported by CM10. //Use reflect to get this value (if possible) try { @@ -129,7 +130,8 @@ public final class StorageHelper { public static boolean isPathInStorageVolume(String path) { String fso = FileHelper.getAbsPath(path); StorageVolume[] volumes = - getStorageVolumes(FileManagerApplication.getInstance().getApplicationContext()); + getStorageVolumes(FileManagerApplication.getInstance().getApplicationContext(), + false); int cc = volumes.length; for (int i = 0; i < cc; i++) { StorageVolume vol = volumes[i]; @@ -148,7 +150,8 @@ public final class StorageHelper { */ public static boolean isStorageVolume(String path) { StorageVolume[] volumes = - getStorageVolumes(FileManagerApplication.getInstance().getApplicationContext()); + getStorageVolumes(FileManagerApplication.getInstance().getApplicationContext(), + false); int cc = volumes.length; for (int i = 0; i < cc; i++) { StorageVolume vol = volumes[i]; @@ -169,7 +172,8 @@ public final class StorageHelper { */ public static String getChrootedPath(String path) { StorageVolume[] volumes = - getStorageVolumes(FileManagerApplication.getInstance().getApplicationContext()); + getStorageVolumes(FileManagerApplication.getInstance().getApplicationContext(), + false); int cc = volumes.length; for (int i = 0; i < cc; i++) { StorageVolume vol = volumes[i]; |
