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

Commit 33c5bc47 authored by Steve Kondik's avatar Steve Kondik Committed by Gerrit Code Review
Browse files

Merge "FileUtils: add method to get UUID of a volume" into cm-10.1

parents 102cf84d 0d75ecd1
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -54,6 +54,13 @@ public class FileUtils {

    public static native int setPermissions(String file, int mode, int uid, int gid);

    /** returns the UUID for the volume mounted
     * at the given mount point, or -1 for failure
     * @param mountPoint point for volume
     * @return UUID or -1
     */
    public static native int getVolumeUUID(String mountPoint);

    /** returns the FAT file system volume ID for the volume mounted 
     * at the given mount point, or -1 for failure
     * @param mountPoint point for FAT volume
+3 −1
Original line number Diff line number Diff line
@@ -166,6 +166,7 @@ LOCAL_C_INCLUDES += \
	$(call include-path-for, libhardware)/hardware \
	$(call include-path-for, libhardware_legacy)/hardware_legacy \
	$(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 \
+44 −0
Original line number Diff line number Diff line
@@ -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},
};