From 3697229cc7adfd89493e87ba8b6401c8b68bdd71 Mon Sep 17 00:00:00 2001 From: San Mehat Date: Wed, 6 Jan 2010 11:06:32 -0800 Subject: [PATCH] framework: MountService: Add initial support for Android Secure External Caches Signed-off-by: San Mehat --- core/java/android/os/IMountService.aidl | 35 +++++++ media/sdutils/sdutil.cpp | 66 +++++++++++++- .../com/android/server/MountListener.java | 91 ++++++++++++++++--- .../java/com/android/server/MountService.java | 56 +++++++++--- 4 files changed, 220 insertions(+), 28 deletions(-) diff --git a/core/java/android/os/IMountService.aidl b/core/java/android/os/IMountService.aidl index 447e764db6d24..1ea7200901231 100644 --- a/core/java/android/os/IMountService.aidl +++ b/core/java/android/os/IMountService.aidl @@ -80,4 +80,39 @@ interface IMountService * Gets the state of an volume via it's mountpoint. */ String getVolumeState(String mountPoint); + + /* + * Creates a secure cache with the specified parameters. + * On success, the filesystem cache-path is returned. + */ + String createSecureCache(String id, int sizeMb, String fstype, String key, int ownerUid); + + /* + * Finalize a cache which has just been created and populated. + * After finalization, the cache is immutable. + */ + void finalizeSecureCache(String id); + + /* + * Destroy a secure cache, and free up all resources associated with it. + * NOTE: Ensure all references are released prior to deleting. + */ + void destroySecureCache(String id); + + /* + * Mount a secure cache with the specified key and owner UID. + * On success, the filesystem cache-path is returned. + */ + String mountSecureCache(String id, String key, int ownerUid); + + /* + * Returns the filesystem path of a mounted secure cache. + */ + String getSecureCachePath(String id); + + /** + * Gets an Array of currently known secure cache IDs + */ + String[] getSecureCacheList(); + } diff --git a/media/sdutils/sdutil.cpp b/media/sdutils/sdutil.cpp index fe11878971262..7f0dda7a9b708 100644 --- a/media/sdutils/sdutil.cpp +++ b/media/sdutils/sdutil.cpp @@ -99,6 +99,42 @@ static int mount(const char* path) { return -1; } +static int asec_create(const char *id, int sizeMb, const char *fstype, + const char *key, int ownerUid) { + String16 sId(id); + String16 sFstype(fstype); + String16 sKey(key); + + String16 r = gMountService->createSecureCache(sId, sizeMb, sFstype, + sKey, ownerUid); + return 0; +} + +static int asec_finalize(const char *id) { + String16 sId(id); + gMountService->finalizeSecureCache(sId); + return 0; +} + +static int asec_destroy(const char *id) { + String16 sId(id); + gMountService->destroySecureCache(sId); + return 0; +} + +static int asec_mount(const char *id, const char *key, int ownerUid) { + String16 sId(id); + String16 sKey(key); + gMountService->mountSecureCache(sId, sKey, ownerUid); + return 0; +} + +static int asec_path(const char *id) { + String16 sId(id); + gMountService->getSecureCachePath(sId); + return 0; +} + static int unmount(const char* path) { String16 string(path); gMountService->unmountMedia(string); @@ -153,14 +189,42 @@ int main(int argc, char **argv) android::init(); return android::umsEnable(false); } + } else if (!strcmp(command, "asec")) { + const char* id = (argc > 3 ? argv[3] : NULL); + + if (!id) + goto usage; + + android::init(); + if (!strcmp(argument, "create")) { + + if (argc != 8) + goto usage; + return android::asec_create(id, atoi(argv[4]), argv[5], argv[6], + atoi(argv[7])); + } else if (!strcmp(argument, "finalize")) { + return android::asec_finalize(id); + } else if (!strcmp(argument, "destroy")) { + return android::asec_destroy(id); + } else if (!strcmp(argument, "mount")) { + return android::asec_mount(id, argv[4], atoi(argv[5])); + } else if (!strcmp(argument, "path")) { + return android::asec_path(id); + } } +usage: fprintf(stderr, "usage:\n" " sdutil mount - mounts the SD card at the given mount point\n" " sdutil unmount - unmounts the SD card at the given mount point\n" " sdutil format - formats the SD card at the given mount point\n" " sdutil ums enable - enables USB mass storage\n" - " sdutil ums disable - disnables USB mass storage\n" + " sdutil ums disable - disables USB mass storage\n" + " sdutil asec create \n" + " sdutil asec finalize \n" + " sdutil asec destroy \n" + " sdutil asec mount \n" + " sdutil asec path \n" ); return -1; } diff --git a/services/java/com/android/server/MountListener.java b/services/java/com/android/server/MountListener.java index d4943ffcc7dfd..5a1107b89559f 100644 --- a/services/java/com/android/server/MountListener.java +++ b/services/java/com/android/server/MountListener.java @@ -21,7 +21,6 @@ import android.net.LocalSocket; import android.os.Environment; import android.os.SystemClock; import android.os.SystemProperties; -import android.os.RemoteException; import android.util.Config; import android.util.Log; @@ -29,6 +28,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.Socket; +import java.lang.IllegalStateException; import java.util.List; import java.util.ArrayList; @@ -49,7 +49,13 @@ final class MountListener implements Runnable { private OutputStream mOutputStream; class ResponseCode { + public static final int ActionInitiated = 100; + public static final int VolumeListResult = 110; + public static final int AsecListResult = 111; + + public static final int CommandOkay = 200; public static final int ShareAvailabilityResult = 210; + public static final int AsecPathResult = 211; public static final int UnsolicitedInformational = 600; public static final int VolumeStateChange = 605; @@ -163,7 +169,8 @@ final class MountListener implements Runnable { SystemClock.sleep(5000); } - private void handleUnsolicitedEvent(int code, String raw, String[] cooked) throws RemoteException { + private void handleUnsolicitedEvent(int code, String raw, + String[] cooked) throws IllegalStateException { // Log.d(TAG, "unsolicited {" + raw + "}"); if (code == ResponseCode.VolumeStateChange) { // FMT: NNN Volume