From 6cdd9c08565a6871ad72cd388adfdfca23532e5e Mon Sep 17 00:00:00 2001 From: San Mehat Date: Tue, 9 Feb 2010 14:45:20 -0800 Subject: [PATCH] MountService: Add isSecureContainerMounted() API call Signed-off-by: San Mehat --- .../android/os/storage/IMountService.aidl | 5 +++ .../java/com/android/server/MountService.java | 34 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/core/java/android/os/storage/IMountService.aidl b/core/java/android/os/storage/IMountService.aidl index 84e3f58da8a0b..3d1ef250a3663 100644 --- a/core/java/android/os/storage/IMountService.aidl +++ b/core/java/android/os/storage/IMountService.aidl @@ -108,6 +108,11 @@ interface IMountService */ int unmountSecureContainer(String id); + /* + * Returns true if the specified container is mounted + */ + boolean isSecureContainerMounted(String id); + /* * Rename an unmounted secure container. * Returns an int consistent with MountServiceResultCode diff --git a/services/java/com/android/server/MountService.java b/services/java/com/android/server/MountService.java index 8d450337a13a3..456244ac624e2 100644 --- a/services/java/com/android/server/MountService.java +++ b/services/java/com/android/server/MountService.java @@ -37,6 +37,7 @@ import android.os.Handler; import android.text.TextUtils; import android.util.Log; import java.util.ArrayList; +import java.util.HashSet; import java.io.File; import java.io.FileReader; @@ -116,6 +117,11 @@ class MountService extends IMountService.Stub private boolean mBooted; private boolean mReady; + /** + * Private hash of currently mounted secure containers. + */ + private HashSet mAsecMountSet = new HashSet(); + private void waitForReady() { while (mReady == false) { for (int retries = 5; retries > 0; retries--) { @@ -862,6 +868,12 @@ class MountService extends IMountService.Stub } catch (NativeDaemonConnectorException e) { rc = StorageResultCode.OperationFailedInternalError; } + + if (rc == StorageResultCode.OperationSucceeded) { + synchronized (mAsecMountSet) { + mAsecMountSet.add(id); + } + } return rc; } @@ -870,6 +882,12 @@ class MountService extends IMountService.Stub waitForReady(); warnOnNotMounted(); + synchronized (mAsecMountSet) { + if (!mAsecMountSet.contains(id)) { + return StorageResultCode.OperationFailedVolumeNotMounted; + } + } + int rc = StorageResultCode.OperationSucceeded; String cmd = String.format("asec unmount %s", id); try { @@ -877,9 +895,25 @@ class MountService extends IMountService.Stub } catch (NativeDaemonConnectorException e) { rc = StorageResultCode.OperationFailedInternalError; } + + if (rc == StorageResultCode.OperationSucceeded) { + synchronized (mAsecMountSet) { + mAsecMountSet.remove(id); + } + } return rc; } + public boolean isSecureContainerMounted(String id) { + validatePermission(android.Manifest.permission.ASEC_ACCESS); + waitForReady(); + warnOnNotMounted(); + + synchronized (mAsecMountSet) { + return mAsecMountSet.contains(id); + } + } + public int renameSecureContainer(String oldId, String newId) { validatePermission(android.Manifest.permission.ASEC_RENAME); waitForReady();