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

Commit f328e4f7 authored by kai.cao's avatar kai.cao Committed by Gerrit Code Review
Browse files

[CMFileManager] Fix can't copy after disconnect with pc.

Preconditions
1.insert a sdcard.
2.the phone connect with pc and the usb computer connection as Mount Sd card.

Procedures
1.Go to “File Manager”.
2.Copy a file in sdcard.
3.Connect to pc when the system is copying.
4.The CMFileManager will forced termination and  switch off the connecting with pc.
5.Go to CMFileManager and copy a file in Sd card.

The copy function is invalid and popup "The operation's command was not found ..."

Change-Id: I042550ce69f4c31a6fe46dfc9aeb53b34588d53f
parent df55584e
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -117,6 +117,7 @@ import com.cyanogenmod.filemanager.util.ExceptionUtil;
import com.cyanogenmod.filemanager.util.ExceptionUtil.OnRelaunchCommandResult;
import com.cyanogenmod.filemanager.util.FileHelper;
import com.cyanogenmod.filemanager.util.MimeTypeHelper.MimeTypeCategory;
import com.cyanogenmod.filemanager.util.MountPointHelper;
import com.cyanogenmod.filemanager.util.StorageHelper;

import java.io.File;
@@ -326,6 +327,8 @@ public class NavigationActivity extends Activity
                        FileManagerSettings.INTENT_MOUNT_STATUS_CHANGED) == 0 ||
                            intent.getAction().equals(Intent.ACTION_MEDIA_MOUNTED) ||
                            intent.getAction().equals(Intent.ACTION_MEDIA_UNMOUNTED)) {
                    MountPointHelper.refreshMountPoints(
                            FileManagerApplication.getBackgroundConsole());
                    onRequestBookmarksRefresh();
                    removeUnmountedHistory();
                    removeUnmountedSelection();
+48 −25
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import com.cyanogenmod.filemanager.model.DiskUsage;
import com.cyanogenmod.filemanager.model.FileSystemObject;
import com.cyanogenmod.filemanager.model.MountPoint;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
@@ -47,7 +48,7 @@ public final class MountPointHelper {

    private static final long MAX_CACHED_TIME = 60000L * 5;

    private static List<MountPoint> sMountPoints;
    private static List<MountPoint> sMountPoints = new ArrayList<>();
    private static long sLastCachedTime;

    /**
@@ -82,6 +83,27 @@ public final class MountPointHelper {
        return null;
    }

    /**
     * Method that refresh the mount point information.
     *
     * @return boolean refresh success or not.
     */
    public static boolean refreshMountPoints(Console console) {
        synchronized(sMountPoints) {
            try {
                if (FileManagerApplication.hasShellCommands()) {
                    sMountPoints.clear();
                    sMountPoints.addAll(CommandHelper.getMountPoints(null, null));
                    sLastCachedTime = System.currentTimeMillis();
                    return true;
                }
            } catch (Exception e) {
                Log.e(TAG, "Failed to update the mount point information", e); //$NON-NLS-1$
            }
        }
        return false;
    }

    /**
     * Method that retrieve the mount point information for a directory.
     *
@@ -89,20 +111,20 @@ public final class MountPointHelper {
     * @param dir The directory of which recovers his mount point information
     * @return MountPoint The mount point information
     */
    public synchronized static MountPoint getMountPointFromDirectory(Console console, String dir) {
    public static MountPoint getMountPointFromDirectory(Console console, String dir) {
        try {
            // For non-rooted devices, which console is java and runs under a chrooted
            // device, mount point info mustn't be a main objective. Caching the status
            // should be enough and operation runs smoothly.
            // Refresh mount points after some time (5 minutes should be enough)
            long now = System.currentTimeMillis();
            if (sMountPoints == null || (now - sLastCachedTime) > MAX_CACHED_TIME ||
                FileManagerApplication.hasShellCommands()) {
            synchronized(sMountPoints) {
                if (sMountPoints == null || (now - sLastCachedTime) > MAX_CACHED_TIME) {
                    //Retrieve the mount points
                List<MountPoint> mps =
                        CommandHelper.getMountPoints(null, console);
                sMountPoints = mps;
                sLastCachedTime = now;
                    refreshMountPoints(console);
                }
                if (sMountPoints == null) {
                    return null;
                }

                //Sort mount points in reverse order, needed for avoid
@@ -122,6 +144,7 @@ public final class MountPointHelper {
                        return mp;
                    }
                }
            }

        } catch (Exception e) {
            Log.e(TAG, "Failed to retrieve the mount point information", e); //$NON-NLS-1$