diff options
author | Daniel Hillenbrand <codeworkx@cyanogenmod.org> | 2013-06-17 17:06:57 +0200 |
---|---|---|
committer | Daniel Hillenbrand <codeworkx@cyanogenmod.org> | 2013-06-17 17:10:01 +0200 |
commit | 0d75ecd1a15d7cbd01a87ca2fec186be6f4167a5 (patch) | |
tree | bc05aa8029a037c68ae75a16465d2c24a1b1f474 /core/jni | |
parent | 44d22ba5d90b340cb99566ee99ac0b5f4fb2e826 (diff) | |
download | frameworks_base-0d75ecd1a15d7cbd01a87ca2fec186be6f4167a5.zip frameworks_base-0d75ecd1a15d7cbd01a87ca2fec186be6f4167a5.tar.gz frameworks_base-0d75ecd1a15d7cbd01a87ca2fec186be6f4167a5.tar.bz2 |
FileUtils: add method to get UUID of a volume
Change-Id: I41b76c5e01c82a2f8e67b33133a76947877a2814
Diffstat (limited to 'core/jni')
-rw-r--r-- | core/jni/Android.mk | 4 | ||||
-rw-r--r-- | core/jni/android_os_FileUtils.cpp | 44 |
2 files changed, 47 insertions, 1 deletions
diff --git a/core/jni/Android.mk b/core/jni/Android.mk index c86f949..4ec9f33 100644 --- a/core/jni/Android.mk +++ b/core/jni/Android.mk @@ -165,7 +165,8 @@ LOCAL_C_INCLUDES += \ $(call include-path-for, bluedroid) \ $(call include-path-for, libhardware)/hardware \ $(call include-path-for, libhardware_legacy)/hardware_legacy \ - $(TOP)/frameworks/av/include \ + $(TOP)/frameworks/av/include \ + external/e2fsprogs/lib \ external/skia/include/core \ external/skia/include/effects \ external/skia/include/images \ @@ -189,6 +190,7 @@ LOCAL_C_INCLUDES += \ LOCAL_SHARED_LIBRARIES := \ libandroidfw \ libexpat \ + libext2_blkid \ libnativehelper \ libcutils \ libutils \ diff --git a/core/jni/android_os_FileUtils.cpp b/core/jni/android_os_FileUtils.cpp index a07f5b7..b624a0d 100644 --- a/core/jni/android_os_FileUtils.cpp +++ b/core/jni/android_os_FileUtils.cpp @@ -23,6 +23,7 @@ #include "JNIHelp.h" +#include <string.h> #include <sys/errno.h> #include <sys/stat.h> #include <sys/types.h> @@ -30,6 +31,7 @@ #include <signal.h> #include <sys/ioctl.h> #include <linux/msdos_fs.h> +#include <blkid/blkid.h> namespace android { @@ -55,6 +57,47 @@ jint android_os_FileUtils_setPermissions(JNIEnv* env, jobject clazz, return chmod(file8.string(), mode) == 0 ? 0 : errno; } +jint android_os_FileUtils_getVolumeUUID(JNIEnv* env, jobject clazz, jstring path) +{ + char *uuid = NULL; + + if (path == NULL) { + jniThrowException(env, "java/lang/IllegalArgumentException", NULL); + return -1; + } + + const char *pathStr = env->GetStringUTFChars(path, NULL); + ALOGD("Trying to get UUID for %s \n", pathStr); + + uuid = blkid_get_tag_value(NULL, "UUID", pathStr); + if (uuid) { + ALOGD("UUID for %s is %s\n", pathStr, uuid); + + String8 s8uuid = (String8)uuid; + size_t len = s8uuid.length(); + String8 result; + + if (len > 0) { + for (int i = 0; i > len; i++) + { + if (strncmp((const char *)s8uuid[i], (const char *)"-", 1) != 0) { + result.append((const char *)s8uuid[i]); + } + } + len = 0; + } + + len = result.length(); + + if (len > 0) { + return atoi(s8uuid); + } else { + ALOGE("Couldn't get UUID for %s\n", pathStr); + } + } + return -1; +} + jint android_os_FileUtils_getFatVolumeId(JNIEnv* env, jobject clazz, jstring path) { if (path == NULL) { @@ -78,6 +121,7 @@ jint android_os_FileUtils_getFatVolumeId(JNIEnv* env, jobject clazz, jstring pat static const JNINativeMethod methods[] = { {"setPermissions", "(Ljava/lang/String;III)I", (void*)android_os_FileUtils_setPermissions}, + {"getVolumeUUID", "(Ljava/lang/String;)I", (void*)android_os_FileUtils_getVolumeUUID}, {"getFatVolumeId", "(Ljava/lang/String;)I", (void*)android_os_FileUtils_getFatVolumeId}, }; |