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

Commit d970998b authored by San Mehat's avatar San Mehat
Browse files

framework: storage: Add 'force' option to unmount/destroy storage apis, and update callsites.



Also adds additional storage unit tests

Signed-off-by: default avatarSan Mehat <san@google.com>
parent 154f7a1c
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -119461,6 +119461,17 @@
 visibility="public"
>
</field>
<field name="OperationFailedStorageBusy"
 type="int"
 transient="false"
 volatile="false"
 value="-7"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="OperationFailedStorageMounted"
 type="int"
 transient="false"
+3 −3
Original line number Diff line number Diff line
@@ -63,7 +63,7 @@ interface IMountService
     * Safely unmount external storage at given mount point.
     * Returns an int consistent with MountServiceResultCode
     */
    int unmountVolume(String mountPoint);
    int unmountVolume(String mountPoint, boolean force);

    /**
     * Format external storage given a mount point.
@@ -100,7 +100,7 @@ interface IMountService
     * NOTE: Ensure all references are released prior to deleting.
     * Returns an int consistent with MountServiceResultCode
     */
    int destroySecureContainer(String id);
    int destroySecureContainer(String id, boolean force);

    /*
     * Mount a secure container with the specified key and owner UID.
@@ -112,7 +112,7 @@ interface IMountService
     * Unount a secure container.
     * Returns an int consistent with MountServiceResultCode
     */
    int unmountSecureContainer(String id);
    int unmountSecureContainer(String id, boolean force);

    /*
     * Returns true if the specified container is mounted
+6 −0
Original line number Diff line number Diff line
@@ -64,4 +64,10 @@ public class StorageResultCode
     */
    public static final int OperationFailedStorageMounted     = -6;

    /**
     * Operation failed: Storage is busy.
     * @see android.os.storage.StorageManager
     */
    public static final int OperationFailedStorageBusy        = -7;

}
+2 −2
Original line number Diff line number Diff line
@@ -93,7 +93,7 @@ public class PackageHelper {

   public static boolean unMountSdDir(String cid) {
    try {
        int rc = getMountService().unmountSecureContainer(cid);
        int rc = getMountService().unmountSecureContainer(cid, false);
        if (rc != StorageResultCode.OperationSucceeded) {
            Log.e(TAG, "Failed to unmount " + cid + " with rc " + rc);
            return false;
@@ -148,7 +148,7 @@ public class PackageHelper {

    public static boolean destroySdDir(String cid) {
        try {
            int rc = getMountService().destroySecureContainer(cid);
            int rc = getMountService().destroySecureContainer(cid, false);
            if (rc != StorageResultCode.OperationSucceeded) {
                Log.i(TAG, "Failed to destroy container " + cid);
                return false;
+26 −13
Original line number Diff line number Diff line
@@ -97,7 +97,7 @@ class MountService extends IMountService.Stub
        public static final int OpFailedMediaBlank             = 402;
        public static final int OpFailedMediaCorrupt           = 403;
        public static final int OpFailedVolNotMounted          = 404;
        public static final int OpFailedVolBusy                = 405;
        public static final int OpFailedStorageBusy            = 405;

        /*
         * 600 series - Unsolicited broadcasts.
@@ -184,7 +184,7 @@ class MountService extends IMountService.Stub
        String vs = getVolumeState(path);
        if (enable && vs.equals(Environment.MEDIA_MOUNTED)) {
            mUmsEnabling = enable; // Override for isUsbMassStorageEnabled()
            int rc = doUnmountVolume(path);
            int rc = doUnmountVolume(path, false);
            mUmsEnabling = false; // Clear override
            if (rc != StorageResultCode.OperationSucceeded) {
                Log.e(TAG, String.format("Failed to unmount before enabling UMS (%d)", rc));
@@ -527,7 +527,7 @@ class MountService extends IMountService.Stub
        return rc;
    }

    private int doUnmountVolume(String path) {
    private int doUnmountVolume(String path, boolean force) {
        if (!getVolumeState(path).equals(Environment.MEDIA_MOUNTED)) {
            return VoldResponseCode.OpFailedVolNotMounted;
        }
@@ -537,7 +537,8 @@ class MountService extends IMountService.Stub
        // notified that the applications installed on the media will be killed.
        mPms.updateExternalMediaStatus(false);
        try {
            mConnector.doCommand(String.format("volume unmount %s", path));
            mConnector.doCommand(String.format(
                    "volume unmount %s%s", path, (force ? " force" : "")));
            return StorageResultCode.OperationSucceeded;
        } catch (NativeDaemonConnectorException e) {
            // Don't worry about mismatch in PackageManager since the
@@ -545,6 +546,8 @@ class MountService extends IMountService.Stub
            int code = e.getCode();
            if (code == VoldResponseCode.OpFailedVolNotMounted) {
                return StorageResultCode.OperationFailedStorageNotMounted;
            } else if (code == VoldResponseCode.OpFailedStorageBusy) {
                return StorageResultCode.OperationFailedStorageBusy;
            } else {
                return StorageResultCode.OperationFailedInternalError;
            }
@@ -733,7 +736,7 @@ class MountService extends IMountService.Stub
            /*
             * If the media is mounted, then gracefully unmount it.
             */
            if (doUnmountVolume(path) != StorageResultCode.OperationSucceeded) {
            if (doUnmountVolume(path, true) != StorageResultCode.OperationSucceeded) {
                Log.e(TAG, "Failed to unmount media for shutdown");
            }
        }
@@ -782,11 +785,11 @@ class MountService extends IMountService.Stub
        return doMountVolume(path);
    }

    public int unmountVolume(String path) {
    public int unmountVolume(String path, boolean force) {
        validatePermission(android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS);
        waitForReady();

        return doUnmountVolume(path);
        return doUnmountVolume(path, force);
    }

    public int formatVolume(String path) {
@@ -878,17 +881,22 @@ class MountService extends IMountService.Stub
        return rc;
    }

    public int destroySecureContainer(String id) {
    public int destroySecureContainer(String id, boolean force) {
        validatePermission(android.Manifest.permission.ASEC_DESTROY);
        waitForReady();
        warnOnNotMounted();

        int rc = StorageResultCode.OperationSucceeded;
        try {
            mConnector.doCommand(String.format("asec destroy %s", id));
            mConnector.doCommand(String.format("asec destroy %s%s", id, (force ? " force" : "")));
        } catch (NativeDaemonConnectorException e) {
            int code = e.getCode();
            if (code == VoldResponseCode.OpFailedStorageBusy) {
                rc = StorageResultCode.OperationFailedStorageBusy;
            } else {
                rc = StorageResultCode.OperationFailedInternalError;
            }
        }

        if (rc == StorageResultCode.OperationSucceeded) {
            synchronized (mAsecMountSet) {
@@ -928,7 +936,7 @@ class MountService extends IMountService.Stub
        return rc;
    }

    public int unmountSecureContainer(String id) {
    public int unmountSecureContainer(String id, boolean force) {
        validatePermission(android.Manifest.permission.ASEC_MOUNT_UNMOUNT);
        waitForReady();
        warnOnNotMounted();
@@ -940,12 +948,17 @@ class MountService extends IMountService.Stub
         }

        int rc = StorageResultCode.OperationSucceeded;
        String cmd = String.format("asec unmount %s", id);
        String cmd = String.format("asec unmount %s%s", id, (force ? " force" : ""));
        try {
            mConnector.doCommand(cmd);
        } catch (NativeDaemonConnectorException e) {
            int code = e.getCode();
            if (code == VoldResponseCode.OpFailedStorageBusy) {
                rc = StorageResultCode.OperationFailedStorageBusy;
            } else {
                rc = StorageResultCode.OperationFailedInternalError;
            }
        }

        if (rc == StorageResultCode.OperationSucceeded) {
            synchronized (mAsecMountSet) {
Loading