Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e3922e43 authored by Matt Garnes's avatar Matt Garnes
Browse files

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
parent 4bd0d070
Loading
Loading
Loading
Loading
+13 −8
Original line number Diff line number Diff line
@@ -21,6 +21,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;
@@ -319,11 +320,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();
@@ -502,9 +501,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);
@@ -1300,7 +1305,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();
@@ -1568,7 +1573,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
+1 −1
Original line number Diff line number Diff line
@@ -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;
+2 −2
Original line number Diff line number Diff line
@@ -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();
            }
+9 −5
Original line number Diff line number Diff line
@@ -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];