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

Commit b1da9ed0 authored by Josh Stone's avatar Josh Stone
Browse files

MountService: Only notify PackageManager for true ASEC changes

MountService can be dealing with multiple mounts (emmc, sdcard), but
only the EXTERNAL_STORAGE has any ASEC mounts on it.  Since the PMS
updateExternalMediaStatus doesn't specify the path, we need to make sure
it's only called for the real ASEC mount.  Otherwise we get into nasty
race conditions when multiple mounts are coming and going, like during
UMS transitions, and sdcard-installed apps tend to break.

Change-Id: I85c6a601e84afd30b44270b0892686c2d864ce8d
parent b9df5b13
Loading
Loading
Loading
Loading
+23 −5
Original line number Diff line number Diff line
@@ -520,7 +520,9 @@ class MountService extends IMountService.Stub

        if (Environment.MEDIA_UNMOUNTED.equals(state)) {
            // Tell the package manager the media is gone.
            if (isExternalStorage(path)) {
                mPms.updateExternalMediaStatus(false, false);
            }

            /*
             * Some OBBs might have been unmounted when this volume was
@@ -531,8 +533,10 @@ class MountService extends IMountService.Stub
                    path));
        } else if (Environment.MEDIA_MOUNTED.equals(state)) {
            // Tell the package manager the media is available for use.
            if (isExternalStorage(path)) {
                mPms.updateExternalMediaStatus(true, false);
            }
        }

        String oldState = currentState;
        setVolumeState(path, state);
@@ -904,7 +908,9 @@ class MountService extends IMountService.Stub
        Runtime.getRuntime().gc();

        // Redundant probably. But no harm in updating state again.
        if (isExternalStorage(path)) {
            mPms.updateExternalMediaStatus(false, false);
        }
        try {
            mConnector.doCommand(String.format(
                    "volume unmount %s%s", path, (force ? " force" : "")));
@@ -1191,6 +1197,10 @@ class MountService extends IMountService.Stub
        return doGetShareMethodAvailable("ums");
    }

    private boolean isExternalStorage(String path) {
        return Environment.getExternalStorageDirectory().getPath().equals(path);
    }

    private ArrayList<String> getShareableVolumes() {
        // build.prop will specify additional volumes to mount in the
        // ro.additionalmounts property.
@@ -1225,7 +1235,11 @@ class MountService extends IMountService.Stub
                // Override for isUsbMassStorageEnabled()
                setUmsEnabling(enable);
                UmsEnableCallBack umscb = new UmsEnableCallBack(path, method, true);
                if (isExternalStorage(path)) {
                    mHandler.sendMessage(mHandler.obtainMessage(H_UNMOUNT_PM_UPDATE, umscb));
                } else {
                    umscb.handleFinished();
                }
                // Clear override
                setUmsEnabling(false);
            }
@@ -1291,7 +1305,11 @@ class MountService extends IMountService.Stub
            return;
        }
        UnmountCallBack ucb = new UnmountCallBack(path, force);
        if (isExternalStorage(path)) {
            mHandler.sendMessage(mHandler.obtainMessage(H_UNMOUNT_PM_UPDATE, ucb));
        } else {
            ucb.handleFinished();
        }
    }

    public int formatVolume(String path) {