Loading media/jni/Android.mk +2 −0 Original line number Diff line number Diff line Loading @@ -40,7 +40,9 @@ else LOCAL_CFLAGS += -DNO_OPENCORE endif ifneq ($(TARGET_SIMULATOR),true) LOCAL_STATIC_LIBRARIES := libmtp libusbhost endif LOCAL_C_INCLUDES += \ external/tremor/Tremor \ Loading media/jni/android_media_MtpClient.cpp +20 −0 Original line number Diff line number Diff line Loading @@ -38,6 +38,8 @@ static jmethodID method_deviceAdded; static jmethodID method_deviceRemoved; static jfieldID field_context; #ifdef HAVE_ANDROID_OS static void checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName) { if (env->ExceptionCheck()) { LOGE("An exception was thrown by callback '%s'.", methodName); Loading Loading @@ -94,52 +96,66 @@ void MyClient::deviceRemoved(MtpDevice *device) { checkAndClearExceptionFromCallback(env, __FUNCTION__); } #endif // HAVE_ANDROID_OS // ---------------------------------------------------------------------------- static void android_media_MtpClient_setup(JNIEnv *env, jobject thiz) { #ifdef HAVE_ANDROID_OS LOGD("setup\n"); MyClient* client = new MyClient(env, thiz); client->start(); env->SetIntField(thiz, field_context, (int)client); #endif } static void android_media_MtpClient_finalize(JNIEnv *env, jobject thiz) { #ifdef HAVE_ANDROID_OS LOGD("finalize\n"); MyClient *client = (MyClient *)env->GetIntField(thiz, field_context); client->cleanup(env); delete client; env->SetIntField(thiz, field_context, 0); #endif } static jboolean android_media_MtpClient_start(JNIEnv *env, jobject thiz) { #ifdef HAVE_ANDROID_OS LOGD("start\n"); MyClient *client = (MyClient *)env->GetIntField(thiz, field_context); return client->start(); #else return false; #endif } static void android_media_MtpClient_stop(JNIEnv *env, jobject thiz) { #ifdef HAVE_ANDROID_OS LOGD("stop\n"); MyClient *client = (MyClient *)env->GetIntField(thiz, field_context); client->stop(); #endif } static jboolean android_media_MtpClient_delete_object(JNIEnv *env, jobject thiz, jint device_id, jint object_id) { #ifdef HAVE_ANDROID_OS MyClient *client = (MyClient *)env->GetIntField(thiz, field_context); MtpDevice* device = client->getDevice(device_id); if (device) return device->deleteObject(object_id); else #endif return NULL; } Loading @@ -147,11 +163,13 @@ static jint android_media_MtpClient_get_parent(JNIEnv *env, jobject thiz, jint device_id, jint object_id) { #ifdef HAVE_ANDROID_OS MyClient *client = (MyClient *)env->GetIntField(thiz, field_context); MtpDevice* device = client->getDevice(device_id); if (device) return device->getParent(object_id); else #endif return -1; } Loading @@ -159,11 +177,13 @@ static jint android_media_MtpClient_get_storage_id(JNIEnv *env, jobject thiz, jint device_id, jint object_id) { #ifdef HAVE_ANDROID_OS MyClient *client = (MyClient *)env->GetIntField(thiz, field_context); MtpDevice* device = client->getDevice(device_id); if (device) return device->getStorageID(object_id); else #endif return -1; } Loading media/jni/android_media_MtpCursor.cpp +8 −0 Original line number Diff line number Diff line Loading @@ -51,6 +51,7 @@ static void android_media_MtpCursor_setup(JNIEnv *env, jobject thiz, jobject javaClient, jint queryType, jint deviceID, jint storageID, jint objectID, jintArray javaColumns) { #ifdef HAVE_ANDROID_OS LOGD("android_media_MtpCursor_setup queryType: %d deviceID: %d storageID: %d objectID: %d\n", queryType, deviceID, storageID, objectID); Loading @@ -68,19 +69,23 @@ android_media_MtpCursor_setup(JNIEnv *env, jobject thiz, jobject javaClient, if (columns) env->ReleaseIntArrayElements(javaColumns, columns, 0); env->SetIntField(thiz, field_context, (int)cursor); #endif } static void android_media_MtpCursor_finalize(JNIEnv *env, jobject thiz) { #ifdef HAVE_ANDROID_OS LOGD("finalize\n"); MtpCursor *cursor = (MtpCursor *)env->GetIntField(thiz, field_context); delete cursor; #endif } static jint android_media_MtpCursor_fill_window(JNIEnv *env, jobject thiz, jobject javaWindow, jint startPos) { #ifdef HAVE_ANDROID_OS CursorWindow* window = get_window_from_object(env, javaWindow); if (!window) { LOGE("Invalid CursorWindow"); Loading @@ -91,6 +96,9 @@ android_media_MtpCursor_fill_window(JNIEnv *env, jobject thiz, jobject javaWindo MtpCursor *cursor = (MtpCursor *)env->GetIntField(thiz, field_context); return cursor->fillWindow(window, startPos); #else return 0; #endif } // ---------------------------------------------------------------------------- Loading media/jni/android_media_MtpDatabase.cpp +7 −0 Original line number Diff line number Diff line Loading @@ -49,6 +49,7 @@ MtpDatabase* getMtpDatabase(JNIEnv *env, jobject database) { return (MtpDatabase *)env->GetIntField(database, field_context); } #ifdef HAVE_ANDROID_OS // ---------------------------------------------------------------------------- class MyMtpDatabase : public MtpDatabase { Loading Loading @@ -368,26 +369,32 @@ static void checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodNa } } #endif // HAVE_ANDROID_OS // ---------------------------------------------------------------------------- static void android_media_MtpDatabase_setup(JNIEnv *env, jobject thiz) { #ifdef HAVE_ANDROID_OS LOGD("setup\n"); MyMtpDatabase* database = new MyMtpDatabase(env, thiz); env->SetIntField(thiz, field_context, (int)database); checkAndClearExceptionFromCallback(env, __FUNCTION__); #endif } static void android_media_MtpDatabase_finalize(JNIEnv *env, jobject thiz) { #ifdef HAVE_ANDROID_OS LOGD("finalize\n"); MyMtpDatabase* database = (MyMtpDatabase *)env->GetIntField(thiz, field_context); database->cleanup(env); delete database; env->SetIntField(thiz, field_context, 0); checkAndClearExceptionFromCallback(env, __FUNCTION__); #endif } // ---------------------------------------------------------------------------- Loading media/jni/android_media_MtpServer.cpp +14 −0 Original line number Diff line number Diff line Loading @@ -42,6 +42,8 @@ extern MtpDatabase* getMtpDatabase(JNIEnv *env, jobject database); // ---------------------------------------------------------------------------- #ifdef HAVE_ANDROID_OS static bool ExceptionCheck(void* env) { return ((JNIEnv *)env)->ExceptionCheck(); Loading Loading @@ -111,9 +113,12 @@ public: } }; #endif // HAVE_ANDROID_OS static void android_media_MtpServer_setup(JNIEnv *env, jobject thiz, jobject javaDatabase, jstring storagePath) { #ifdef HAVE_ANDROID_OS LOGD("setup\n"); MtpDatabase* database = getMtpDatabase(env, javaDatabase); Loading @@ -123,6 +128,7 @@ android_media_MtpServer_setup(JNIEnv *env, jobject thiz, jobject javaDatabase, j env->SetIntField(thiz, field_context, (int)thread); env->ReleaseStringUTFChars(storagePath, storagePathStr); #endif } static void Loading @@ -135,42 +141,50 @@ android_media_MtpServer_finalize(JNIEnv *env, jobject thiz) static void android_media_MtpServer_start(JNIEnv *env, jobject thiz) { #ifdef HAVE_ANDROID_OS LOGD("start\n"); MtpThread *thread = (MtpThread *)env->GetIntField(thiz, field_context); thread->run("MtpThread"); #endif // HAVE_ANDROID_OS } static void android_media_MtpServer_stop(JNIEnv *env, jobject thiz) { #ifdef HAVE_ANDROID_OS LOGD("stop\n"); MtpThread *thread = (MtpThread *)env->GetIntField(thiz, field_context); if (thread) { thread->setDone(); env->SetIntField(thiz, field_context, 0); } #endif } static void android_media_MtpServer_send_object_added(JNIEnv *env, jobject thiz, jint handle) { #ifdef HAVE_ANDROID_OS LOGD("send_object_added %d\n", handle); MtpThread *thread = (MtpThread *)env->GetIntField(thiz, field_context); if (thread) thread->sendObjectAdded(handle); else LOGE("sendObjectAdded called while disconnected\n"); #endif } static void android_media_MtpServer_send_object_removed(JNIEnv *env, jobject thiz, jint handle) { #ifdef HAVE_ANDROID_OS LOGD("send_object_removed %d\n", handle); MtpThread *thread = (MtpThread *)env->GetIntField(thiz, field_context); if (thread) thread->sendObjectRemoved(handle); else LOGE("sendObjectRemoved called while disconnected\n"); #endif } // ---------------------------------------------------------------------------- Loading Loading
media/jni/Android.mk +2 −0 Original line number Diff line number Diff line Loading @@ -40,7 +40,9 @@ else LOCAL_CFLAGS += -DNO_OPENCORE endif ifneq ($(TARGET_SIMULATOR),true) LOCAL_STATIC_LIBRARIES := libmtp libusbhost endif LOCAL_C_INCLUDES += \ external/tremor/Tremor \ Loading
media/jni/android_media_MtpClient.cpp +20 −0 Original line number Diff line number Diff line Loading @@ -38,6 +38,8 @@ static jmethodID method_deviceAdded; static jmethodID method_deviceRemoved; static jfieldID field_context; #ifdef HAVE_ANDROID_OS static void checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName) { if (env->ExceptionCheck()) { LOGE("An exception was thrown by callback '%s'.", methodName); Loading Loading @@ -94,52 +96,66 @@ void MyClient::deviceRemoved(MtpDevice *device) { checkAndClearExceptionFromCallback(env, __FUNCTION__); } #endif // HAVE_ANDROID_OS // ---------------------------------------------------------------------------- static void android_media_MtpClient_setup(JNIEnv *env, jobject thiz) { #ifdef HAVE_ANDROID_OS LOGD("setup\n"); MyClient* client = new MyClient(env, thiz); client->start(); env->SetIntField(thiz, field_context, (int)client); #endif } static void android_media_MtpClient_finalize(JNIEnv *env, jobject thiz) { #ifdef HAVE_ANDROID_OS LOGD("finalize\n"); MyClient *client = (MyClient *)env->GetIntField(thiz, field_context); client->cleanup(env); delete client; env->SetIntField(thiz, field_context, 0); #endif } static jboolean android_media_MtpClient_start(JNIEnv *env, jobject thiz) { #ifdef HAVE_ANDROID_OS LOGD("start\n"); MyClient *client = (MyClient *)env->GetIntField(thiz, field_context); return client->start(); #else return false; #endif } static void android_media_MtpClient_stop(JNIEnv *env, jobject thiz) { #ifdef HAVE_ANDROID_OS LOGD("stop\n"); MyClient *client = (MyClient *)env->GetIntField(thiz, field_context); client->stop(); #endif } static jboolean android_media_MtpClient_delete_object(JNIEnv *env, jobject thiz, jint device_id, jint object_id) { #ifdef HAVE_ANDROID_OS MyClient *client = (MyClient *)env->GetIntField(thiz, field_context); MtpDevice* device = client->getDevice(device_id); if (device) return device->deleteObject(object_id); else #endif return NULL; } Loading @@ -147,11 +163,13 @@ static jint android_media_MtpClient_get_parent(JNIEnv *env, jobject thiz, jint device_id, jint object_id) { #ifdef HAVE_ANDROID_OS MyClient *client = (MyClient *)env->GetIntField(thiz, field_context); MtpDevice* device = client->getDevice(device_id); if (device) return device->getParent(object_id); else #endif return -1; } Loading @@ -159,11 +177,13 @@ static jint android_media_MtpClient_get_storage_id(JNIEnv *env, jobject thiz, jint device_id, jint object_id) { #ifdef HAVE_ANDROID_OS MyClient *client = (MyClient *)env->GetIntField(thiz, field_context); MtpDevice* device = client->getDevice(device_id); if (device) return device->getStorageID(object_id); else #endif return -1; } Loading
media/jni/android_media_MtpCursor.cpp +8 −0 Original line number Diff line number Diff line Loading @@ -51,6 +51,7 @@ static void android_media_MtpCursor_setup(JNIEnv *env, jobject thiz, jobject javaClient, jint queryType, jint deviceID, jint storageID, jint objectID, jintArray javaColumns) { #ifdef HAVE_ANDROID_OS LOGD("android_media_MtpCursor_setup queryType: %d deviceID: %d storageID: %d objectID: %d\n", queryType, deviceID, storageID, objectID); Loading @@ -68,19 +69,23 @@ android_media_MtpCursor_setup(JNIEnv *env, jobject thiz, jobject javaClient, if (columns) env->ReleaseIntArrayElements(javaColumns, columns, 0); env->SetIntField(thiz, field_context, (int)cursor); #endif } static void android_media_MtpCursor_finalize(JNIEnv *env, jobject thiz) { #ifdef HAVE_ANDROID_OS LOGD("finalize\n"); MtpCursor *cursor = (MtpCursor *)env->GetIntField(thiz, field_context); delete cursor; #endif } static jint android_media_MtpCursor_fill_window(JNIEnv *env, jobject thiz, jobject javaWindow, jint startPos) { #ifdef HAVE_ANDROID_OS CursorWindow* window = get_window_from_object(env, javaWindow); if (!window) { LOGE("Invalid CursorWindow"); Loading @@ -91,6 +96,9 @@ android_media_MtpCursor_fill_window(JNIEnv *env, jobject thiz, jobject javaWindo MtpCursor *cursor = (MtpCursor *)env->GetIntField(thiz, field_context); return cursor->fillWindow(window, startPos); #else return 0; #endif } // ---------------------------------------------------------------------------- Loading
media/jni/android_media_MtpDatabase.cpp +7 −0 Original line number Diff line number Diff line Loading @@ -49,6 +49,7 @@ MtpDatabase* getMtpDatabase(JNIEnv *env, jobject database) { return (MtpDatabase *)env->GetIntField(database, field_context); } #ifdef HAVE_ANDROID_OS // ---------------------------------------------------------------------------- class MyMtpDatabase : public MtpDatabase { Loading Loading @@ -368,26 +369,32 @@ static void checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodNa } } #endif // HAVE_ANDROID_OS // ---------------------------------------------------------------------------- static void android_media_MtpDatabase_setup(JNIEnv *env, jobject thiz) { #ifdef HAVE_ANDROID_OS LOGD("setup\n"); MyMtpDatabase* database = new MyMtpDatabase(env, thiz); env->SetIntField(thiz, field_context, (int)database); checkAndClearExceptionFromCallback(env, __FUNCTION__); #endif } static void android_media_MtpDatabase_finalize(JNIEnv *env, jobject thiz) { #ifdef HAVE_ANDROID_OS LOGD("finalize\n"); MyMtpDatabase* database = (MyMtpDatabase *)env->GetIntField(thiz, field_context); database->cleanup(env); delete database; env->SetIntField(thiz, field_context, 0); checkAndClearExceptionFromCallback(env, __FUNCTION__); #endif } // ---------------------------------------------------------------------------- Loading
media/jni/android_media_MtpServer.cpp +14 −0 Original line number Diff line number Diff line Loading @@ -42,6 +42,8 @@ extern MtpDatabase* getMtpDatabase(JNIEnv *env, jobject database); // ---------------------------------------------------------------------------- #ifdef HAVE_ANDROID_OS static bool ExceptionCheck(void* env) { return ((JNIEnv *)env)->ExceptionCheck(); Loading Loading @@ -111,9 +113,12 @@ public: } }; #endif // HAVE_ANDROID_OS static void android_media_MtpServer_setup(JNIEnv *env, jobject thiz, jobject javaDatabase, jstring storagePath) { #ifdef HAVE_ANDROID_OS LOGD("setup\n"); MtpDatabase* database = getMtpDatabase(env, javaDatabase); Loading @@ -123,6 +128,7 @@ android_media_MtpServer_setup(JNIEnv *env, jobject thiz, jobject javaDatabase, j env->SetIntField(thiz, field_context, (int)thread); env->ReleaseStringUTFChars(storagePath, storagePathStr); #endif } static void Loading @@ -135,42 +141,50 @@ android_media_MtpServer_finalize(JNIEnv *env, jobject thiz) static void android_media_MtpServer_start(JNIEnv *env, jobject thiz) { #ifdef HAVE_ANDROID_OS LOGD("start\n"); MtpThread *thread = (MtpThread *)env->GetIntField(thiz, field_context); thread->run("MtpThread"); #endif // HAVE_ANDROID_OS } static void android_media_MtpServer_stop(JNIEnv *env, jobject thiz) { #ifdef HAVE_ANDROID_OS LOGD("stop\n"); MtpThread *thread = (MtpThread *)env->GetIntField(thiz, field_context); if (thread) { thread->setDone(); env->SetIntField(thiz, field_context, 0); } #endif } static void android_media_MtpServer_send_object_added(JNIEnv *env, jobject thiz, jint handle) { #ifdef HAVE_ANDROID_OS LOGD("send_object_added %d\n", handle); MtpThread *thread = (MtpThread *)env->GetIntField(thiz, field_context); if (thread) thread->sendObjectAdded(handle); else LOGE("sendObjectAdded called while disconnected\n"); #endif } static void android_media_MtpServer_send_object_removed(JNIEnv *env, jobject thiz, jint handle) { #ifdef HAVE_ANDROID_OS LOGD("send_object_removed %d\n", handle); MtpThread *thread = (MtpThread *)env->GetIntField(thiz, field_context); if (thread) thread->sendObjectRemoved(handle); else LOGE("sendObjectRemoved called while disconnected\n"); #endif } // ---------------------------------------------------------------------------- Loading