MountService: Add isSecureContainerMounted() API call
Signed-off-by: San Mehat <san@google.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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<String> mAsecMountSet = new HashSet<String>();
|
||||
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user