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

Commit 279db351 authored by Axel Haslam's avatar Axel Haslam Committed by Steve Kondik
Browse files

Wait for IDLE state before mounting on insert



As soon as we recive the insert event we try to
mount the mmc sending a "volume mount" command.
But, the volume manager sometimes is still on
"pending" state, and the insertion mount will
fail.

This patch calls the doMount command on insert
only after the state has changed to idle.
This way, the mount will not fail, because the
state is pending.

Change-Id: I1f8f13c8e232a6b9159eeb78a9484838f1c600af
Signed-off-by: default avatarAxel Haslam <axelhaslam@ti.com>
parent a378f35b
Loading
Loading
Loading
Loading
+27 −12
Original line number Diff line number Diff line
@@ -137,6 +137,8 @@ class MountService extends IMountService.Stub
    private static final int RETRY_UNMOUNT_DELAY = 30; // in ms
    private static final int MAX_UNMOUNT_RETRIES = 4;

    /*used to send the mount command after state is idle.*/
    boolean insertionMountPending = false;
    class UnmountCallBack {
        String path;
        int retries;
@@ -490,6 +492,26 @@ class MountService extends IMountService.Stub
             * Format: "NNN Volume <label> <path> state changed
             * from <old_#> (<old_str>) to <new_#> (<new_str>)"
             */
            if ((Integer.parseInt(cooked[10]) == VolumeState.Idle) &&
                 insertionMountPending == true) {
                /* If the state moves to idle after a insertion
                 * try to mount the device "Insertion mount"
                 */
                final String path = cooked[3];
                insertionMountPending = false;
                new Thread() {
                    public void run() {
                        try {
                            int rc;
                            if ((rc = doMountVolume(path)) != StorageResultCode.OperationSucceeded) {
                                Slog.w(TAG, String.format("Insertion mount failed (%d)", rc));
                            }
                        } catch (Exception ex) {
                            Slog.w(TAG, "Failed to mount media on insertion", ex);
                        }
                    }
                }.start();
           }
            notifyVolumeStateChange(
                    cooked[2], cooked[3], Integer.parseInt(cooked[7]),
                            Integer.parseInt(cooked[10]));
@@ -521,18 +543,11 @@ class MountService extends IMountService.Stub
            }

            if (code == VoldResponseCode.VolumeDiskInserted) {
                new Thread() {
                    public void run() {
                        try {
                            int rc;
                            if ((rc = doMountVolume(path)) != StorageResultCode.OperationSucceeded) {
                                Slog.w(TAG, String.format("Insertion mount failed (%d)", rc));
                            }
                        } catch (Exception ex) {
                            Slog.w(TAG, "Failed to mount media on insertion", ex);
                        }
                    }
                }.start();
               /* Instead of tring to mount here, wait for
                * the state to be Idle before atempting the
                * insertion mount, else "insertion mount" may fail.
                */
               insertionMountPending = true;
            } else if (code == VoldResponseCode.VolumeDiskRemoved) {
                /*
                 * This event gets trumped if we're already in BAD_REMOVAL state