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

Commit 36cf0520 authored by padarshr's avatar padarshr Committed by Gerrit - the friendly Code Review server
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 05b93e7b
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -722,6 +722,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
@@ -52,6 +52,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,
@@ -238,6 +239,14 @@ public class StorageVolume implements Parcelable {
        return mState;
    }

    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
@@ -754,6 +754,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)) {
@@ -1099,6 +1102,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 */
@@ -1127,6 +1133,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)) {