diff options
author | Mike Lockwood <lockwood@android.com> | 2010-08-03 15:30:09 -0400 |
---|---|---|
committer | Mike Lockwood <lockwood@android.com> | 2010-08-03 15:36:22 -0400 |
commit | 9a2046fb5ceeee4d5334274cbff15f1058bb3244 (patch) | |
tree | 07bc9aa79b4fad40d59382d14ba6277890d3c5f9 /media/jni/android_media_MtpDatabase.cpp | |
parent | 23ee42f904ad6ba4e3d3d569ffd49f4f7d174e1e (diff) | |
download | frameworks_base-9a2046fb5ceeee4d5334274cbff15f1058bb3244.zip frameworks_base-9a2046fb5ceeee4d5334274cbff15f1058bb3244.tar.gz frameworks_base-9a2046fb5ceeee4d5334274cbff15f1058bb3244.tar.bz2 |
MTP: Add support for syncing MTP playlists
MTP playlists now correspond to playlists in the media provider
(like those created by the Music app).
Change-Id: I085cb3cff003037ad62f0e297fb0cfd3047cb3a2
Signed-off-by: Mike Lockwood <lockwood@android.com>
Diffstat (limited to 'media/jni/android_media_MtpDatabase.cpp')
-rw-r--r-- | media/jni/android_media_MtpDatabase.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/media/jni/android_media_MtpDatabase.cpp b/media/jni/android_media_MtpDatabase.cpp index 5ab0a55..d4539fe 100644 --- a/media/jni/android_media_MtpDatabase.cpp +++ b/media/jni/android_media_MtpDatabase.cpp @@ -44,6 +44,8 @@ static jmethodID method_getObjectProperty; static jmethodID method_getObjectInfo; static jmethodID method_getObjectFilePath; static jmethodID method_deleteFile; +static jmethodID method_getObjectReferences; +static jmethodID method_setObjectReferences; static jfieldID field_context; MtpDatabase* getMtpDatabase(JNIEnv *env, jobject database) { @@ -98,6 +100,11 @@ public: virtual MtpResponseCode deleteFile(MtpObjectHandle handle); bool getPropertyInfo(MtpObjectProperty property, int& type); + + virtual MtpObjectHandleList* getObjectReferences(MtpObjectHandle handle); + + virtual MtpResponseCode setObjectReferences(MtpObjectHandle handle, + MtpObjectHandleList* references); }; MyMtpDatabase::MyMtpDatabase(JNIEnv *env, jobject client) @@ -344,6 +351,37 @@ bool MyMtpDatabase::getPropertyInfo(MtpObjectProperty property, int& type) { return false; } +MtpObjectHandleList* MyMtpDatabase::getObjectReferences(MtpObjectHandle handle) { + JNIEnv* env = AndroidRuntime::getJNIEnv(); + jintArray array = (jintArray)env->CallObjectMethod(mDatabase, method_getObjectReferences, + (jint)handle); + if (!array) + return NULL; + MtpObjectHandleList* list = new MtpObjectHandleList(); + jint* handles = env->GetIntArrayElements(array, 0); + jsize length = env->GetArrayLength(array); + for (int i = 0; i < length; i++) + list->push(handles[i]); + env->ReleaseIntArrayElements(array, handles, 0); + return list; +} + +MtpResponseCode MyMtpDatabase::setObjectReferences(MtpObjectHandle handle, MtpObjectHandleList* references) { + JNIEnv* env = AndroidRuntime::getJNIEnv(); + int count = references->size(); + jintArray array = env->NewIntArray(count); + if (!array) { + LOGE("out of memory in setObjectReferences"); + return false; + } + jint* handles = env->GetIntArrayElements(array, 0); + for (int i = 0; i < count; i++) + handles[i] = (*references)[i]; + env->ReleaseIntArrayElements(array, handles, 0); + return env->CallIntMethod(mDatabase, method_setObjectReferences, + (jint)handle, array); +} + // ---------------------------------------------------------------------------- static void checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName) { @@ -442,6 +480,16 @@ int register_android_media_MtpDatabase(JNIEnv *env) LOGE("Can't find deleteFile"); return -1; } + method_getObjectReferences = env->GetMethodID(clazz, "getObjectReferences", "(I)[I"); + if (method_getObjectReferences == NULL) { + LOGE("Can't find getObjectReferences"); + return -1; + } + method_setObjectReferences = env->GetMethodID(clazz, "setObjectReferences", "(I[I)I"); + if (method_setObjectReferences == NULL) { + LOGE("Can't find setObjectReferences"); + return -1; + } field_context = env->GetFieldID(clazz, "mNativeContext", "I"); if (field_context == NULL) { LOGE("Can't find MtpDatabase.mNativeContext"); |