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

Commit 8656db64 authored by Matt Garnes's avatar Matt Garnes Committed by Rajesh Yengisetty
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
(cherry picked from commit e3922e43)
parent ad9e5195
Loading
Loading
Loading
Loading
+13 −8
Original line number Original line Diff line number Diff line
@@ -22,6 +22,7 @@ import android.app.AlertDialog;
import android.app.Dialog;
import android.app.Dialog;
import android.app.SearchManager;
import android.app.SearchManager;
import android.content.BroadcastReceiver;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.Intent;
@@ -327,11 +328,9 @@ public class NavigationActivity extends Activity
                        NavigationActivity.this.getCurrentNavigationView().refresh();
                        NavigationActivity.this.getCurrentNavigationView().refresh();
                    }
                    }
                } else if (intent.getAction().compareTo(
                } else if (intent.getAction().compareTo(
                        FileManagerSettings.INTENT_MOUNT_STATUS_CHANGED) == 0) {
                        FileManagerSettings.INTENT_MOUNT_STATUS_CHANGED) == 0 ||
                    onRequestBookmarksRefresh();
                            intent.getAction().equals(Intent.ACTION_MEDIA_MOUNTED) ||
                    removeUnmountedHistory();
                            intent.getAction().equals(Intent.ACTION_MEDIA_UNMOUNTED)) {
                    removeUnmountedSelection();
                } else if(intent.getAction().equals(Intent.ACTION_MEDIA_MOUNTED)) {
                    onRequestBookmarksRefresh();
                    onRequestBookmarksRefresh();
                    removeUnmountedHistory();
                    removeUnmountedHistory();
                    removeUnmountedSelection();
                    removeUnmountedSelection();
@@ -510,9 +509,15 @@ public class NavigationActivity extends Activity
        filter.addAction(Intent.ACTION_TIME_CHANGED);
        filter.addAction(Intent.ACTION_TIME_CHANGED);
        filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
        filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
        filter.addAction(FileManagerSettings.INTENT_MOUNT_STATUS_CHANGED);
        filter.addAction(FileManagerSettings.INTENT_MOUNT_STATUS_CHANGED);
        filter.addAction(Intent.ACTION_MEDIA_MOUNTED);
        registerReceiver(this.mNotificationReceiver, filter);
        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
        // Set the theme before setContentView
        Theme theme = ThemeManager.getCurrentTheme(this);
        Theme theme = ThemeManager.getCurrentTheme(this);
        theme.setBaseThemeNoActionBar(this);
        theme.setBaseThemeNoActionBar(this);
@@ -1308,7 +1313,7 @@ public class NavigationActivity extends Activity
        try {
        try {
            // Recovery sdcards from storage manager
            // Recovery sdcards from storage manager
            StorageVolume[] volumes = StorageHelper
            StorageVolume[] volumes = StorageHelper
                    .getStorageVolumes(getApplication());
                    .getStorageVolumes(getApplication(), true);
            for (StorageVolume volume: volumes) {
            for (StorageVolume volume: volumes) {
                if (volume != null) {
                if (volume != null) {
                    String mountedState = volume.getState();
                    String mountedState = volume.getState();
@@ -1565,7 +1570,7 @@ public class NavigationActivity extends Activity
            // Initial directory is the first external sdcard (sdcard, emmc, usb, ...)
            // Initial directory is the first external sdcard (sdcard, emmc, usb, ...)
            if (!StorageHelper.isPathInStorageVolume(initialDir)) {
            if (!StorageHelper.isPathInStorageVolume(initialDir)) {
                StorageVolume[] volumes =
                StorageVolume[] volumes =
                        StorageHelper.getStorageVolumes(this);
                        StorageHelper.getStorageVolumes(this, false);
                if (volumes != null && volumes.length > 0) {
                if (volumes != null && volumes.length > 0) {
                    initialDir = volumes[0].getPath();
                    initialDir = volumes[0].getPath();
                    //Ensure that initial directory is an absolute directory
                    //Ensure that initial directory is an absolute directory
+1 −1
Original line number Original line Diff line number Diff line
@@ -596,7 +596,7 @@ public class PickerActivity extends Activity
     */
     */
    private void showStorageVolumesPopUp(View anchor) {
    private void showStorageVolumesPopUp(View anchor) {
        // Create a list (but not checkable)
        // 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>();
        List<CheckableItem> descriptions = new ArrayList<CheckableItem>();
        if (volumes != null) {
        if (volumes != null) {
            int cc = volumes.length;
            int cc = volumes.length;
+2 −2
Original line number Original line Diff line number Diff line
@@ -1372,7 +1372,7 @@ BreadcrumbListener, OnSelectionChangedListener, OnSelectionListener, OnRequestRe


        //Change to first storage volume
        //Change to first storage volume
        StorageVolume[] volumes =
        StorageVolume[] volumes =
                StorageHelper.getStorageVolumes(getContext());
                StorageHelper.getStorageVolumes(getContext(), false);
        if (volumes != null && volumes.length > 0) {
        if (volumes != null && volumes.length > 0) {
            changeCurrentDir(volumes[0].getPath(), false, true, false, null, null);
            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
        // Check if the path is owned by one of the storage volumes
        if (!StorageHelper.isPathInStorageVolume(newDir)) {
        if (!StorageHelper.isPathInStorageVolume(newDir)) {
            StorageVolume[] volumes = StorageHelper.getStorageVolumes(getContext());
            StorageVolume[] volumes = StorageHelper.getStorageVolumes(getContext(), false);
            if (volumes != null && volumes.length > 0) {
            if (volumes != null && volumes.length > 0) {
                return volumes[0].getPath();
                return volumes[0].getPath();
            }
            }
+9 −5
Original line number Original line Diff line number Diff line
@@ -41,11 +41,12 @@ public final class StorageHelper {
     * as first parameter, that AOSP hasn't.
     * as first parameter, that AOSP hasn't.
     *
     *
     * @param ctx The current context
     * @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
     * @return StorageVolume[] The storage volumes defined in the system
     */
     */
    @SuppressWarnings("boxing")
    @SuppressWarnings("boxing")
    public static synchronized StorageVolume[] getStorageVolumes(Context ctx) {
    public static synchronized StorageVolume[] getStorageVolumes(Context ctx, boolean reload) {
        if (sStorageVolumes == null) {
        if (sStorageVolumes == null || reload) {
            //IMP!! Android SDK doesn't have a "getVolumeList" but is supported by CM10.
            //IMP!! Android SDK doesn't have a "getVolumeList" but is supported by CM10.
            //Use reflect to get this value (if possible)
            //Use reflect to get this value (if possible)
            try {
            try {
@@ -129,7 +130,8 @@ public final class StorageHelper {
    public static boolean isPathInStorageVolume(String path) {
    public static boolean isPathInStorageVolume(String path) {
        String fso = FileHelper.getAbsPath(path);
        String fso = FileHelper.getAbsPath(path);
        StorageVolume[] volumes =
        StorageVolume[] volumes =
                getStorageVolumes(FileManagerApplication.getInstance().getApplicationContext());
                getStorageVolumes(FileManagerApplication.getInstance().getApplicationContext(),
                                  false);
        int cc = volumes.length;
        int cc = volumes.length;
        for (int i = 0; i < cc; i++) {
        for (int i = 0; i < cc; i++) {
            StorageVolume vol = volumes[i];
            StorageVolume vol = volumes[i];
@@ -148,7 +150,8 @@ public final class StorageHelper {
     */
     */
    public static boolean isStorageVolume(String path) {
    public static boolean isStorageVolume(String path) {
        StorageVolume[] volumes =
        StorageVolume[] volumes =
                getStorageVolumes(FileManagerApplication.getInstance().getApplicationContext());
                getStorageVolumes(FileManagerApplication.getInstance().getApplicationContext(),
                                  false);
        int cc = volumes.length;
        int cc = volumes.length;
        for (int i = 0; i < cc; i++) {
        for (int i = 0; i < cc; i++) {
            StorageVolume vol = volumes[i];
            StorageVolume vol = volumes[i];
@@ -169,7 +172,8 @@ public final class StorageHelper {
     */
     */
    public static String getChrootedPath(String path) {
    public static String getChrootedPath(String path) {
        StorageVolume[] volumes =
        StorageVolume[] volumes =
                getStorageVolumes(FileManagerApplication.getInstance().getApplicationContext());
                getStorageVolumes(FileManagerApplication.getInstance().getApplicationContext(),
                                  false);
        int cc = volumes.length;
        int cc = volumes.length;
        for (int i = 0; i < cc; i++) {
        for (int i = 0; i < cc; i++) {
            StorageVolume vol = volumes[i];
            StorageVolume vol = volumes[i];