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

Commit 27e3f229 authored by padarshr's avatar padarshr
Browse files

Do not mount Volume if formatting is in progress

This change will avoid mounting the volume if the
state of volume at that point is 'formatting'

CRs-Fixed: 689602

Change-Id: Iab3f8936017ea3a8a8da64f8e01b357dc045cbcf
parent 368dfaa5
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -720,6 +720,13 @@ public class Environment {
     */
    public static final String MEDIA_UNMOUNTABLE = "unmountable";

     /**
     * Storage state if the media is present and in formatting state.
     *
     * @hide
     */
    public static final String MEDIA_FORMATTING = "formatting";

    /**
     * Returns the current state of the primary "external" storage device.
     * 
+9 −0
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ public class StorageVolume implements Parcelable {
    private String mUuid;
    private String mUserLabel;
    private String mState;
    private boolean mIsFormatting;

    // StorageVolume extra for ACTION_MEDIA_REMOVED, ACTION_MEDIA_UNMOUNTED, ACTION_MEDIA_CHECKING,
    // ACTION_MEDIA_NOFS, ACTION_MEDIA_MOUNTED, ACTION_MEDIA_SHARED, ACTION_MEDIA_UNSHARED,
@@ -245,6 +246,14 @@ public class StorageVolume implements Parcelable {
        return mAllowMtp;
    }

    public void setIsFormatting(boolean isFormatting) {
        mIsFormatting = isFormatting;
    }

    public boolean getIsFormatting() {
        return mIsFormatting;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof StorageVolume && mPath != null) {
+9 −0
Original line number Diff line number Diff line
@@ -724,6 +724,9 @@ class MountService extends IMountService.Stub
        synchronized (mVolumesLock) {
            oldState = mVolumeStates.put(path, state);
            volume.setState(state);
            if (!Environment.MEDIA_FORMATTING.equals(state)) {
                volume.setIsFormatting(false);
            }
        }

        if (state.equals(oldState)) {
@@ -1069,6 +1072,9 @@ class MountService extends IMountService.Stub
        } else if (newState == VolumeState.Unmounting) {
            action = Intent.ACTION_MEDIA_EJECT;
        } else if (newState == VolumeState.Formatting) {
            synchronized (mVolumesLock) {
                volume.setIsFormatting(true);
            }
        } else if (newState == VolumeState.Shared) {
            if (DEBUG_EVENTS) Slog.i(TAG, "Updating volume state media mounted");
            /* Send the media unmounted event first */
@@ -1097,6 +1103,9 @@ class MountService extends IMountService.Stub
        final StorageVolume volume;
        synchronized (mVolumesLock) {
            volume = mVolumesByPath.get(path);
            if (volume.getIsFormatting()) {
                return StorageResultCode.OperationFailedStorageBusy;
            }
        }

        if (!volume.isEmulated() && hasUserRestriction(UserManager.DISALLOW_MOUNT_PHYSICAL_MEDIA)) {