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

Commit ff164a7d authored by Mike Lockwood's avatar Mike Lockwood
Browse files

Exclude MTP implementation from simulator build



Change-Id: I93364c74c26ba6e2bf6b08f1bd82802b966c8dfb
Signed-off-by: default avatarMike Lockwood <lockwood@android.com>
parent 5a23f8c4
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -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 \
+20 −0
Original line number Diff line number Diff line
@@ -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);
@@ -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;
}

@@ -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;
}

@@ -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;
}

+8 −0
Original line number Diff line number Diff line
@@ -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);

@@ -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");
@@ -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
}

// ----------------------------------------------------------------------------
+7 −0
Original line number Diff line number Diff line
@@ -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 {
@@ -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
}

// ----------------------------------------------------------------------------
+14 −0
Original line number Diff line number Diff line
@@ -42,6 +42,8 @@ extern MtpDatabase* getMtpDatabase(JNIEnv *env, jobject database);

// ----------------------------------------------------------------------------

#ifdef HAVE_ANDROID_OS

static bool ExceptionCheck(void* env)
{
    return ((JNIEnv *)env)->ExceptionCheck();
@@ -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);
@@ -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
@@ -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