From 6499ce3e445e1acc5f5707fd164ad5e3c5ab0a43 Mon Sep 17 00:00:00 2001 From: Thomas Martitz Date: Sun, 9 Mar 2014 18:08:06 +0100 Subject: android: Get the port up and running again The build system needed fixes because the tools paths changed and one tool that we used (apkbuilder) was removed entirely. Recent NDKs don't ship gcc 4.4.3 anymore, therefore switch to 4.6. The code itself needed a fix for a jni reference bug that was uncovered by KitKat. The port now builds with latest sdk (r22) and ndk (r9d). Change-Id: Id74fa54ba93bbb0ee30373fbe79e92c5ff03201d --- firmware/target/hosted/android/lcd-android.c | 64 +++++++++++++--------------- 1 file changed, 30 insertions(+), 34 deletions(-) (limited to 'firmware/target/hosted/android/lcd-android.c') diff --git a/firmware/target/hosted/android/lcd-android.c b/firmware/target/hosted/android/lcd-android.c index 2b383741d1..a161406cc0 100644 --- a/firmware/target/hosted/android/lcd-android.c +++ b/firmware/target/hosted/android/lcd-android.c @@ -34,7 +34,6 @@ extern jobject RockboxService_instance; static jobject RockboxFramebuffer_instance; static jmethodID java_lcd_update; static jmethodID java_lcd_update_rect; -static jmethodID java_lcd_init; static jclass AndroidRect_class; static jmethodID AndroidRect_constructor; @@ -42,6 +41,7 @@ static jmethodID AndroidRect_constructor; static int dpi; static int scroll_threshold; static bool display_on; +static bool connected; /* this might actually be called before lcd_init_device() or even main(), so * be sure to only access static storage initalized at library loading, @@ -49,38 +49,26 @@ static bool display_on; static void connect_with_java(JNIEnv* env, jobject fb_instance) { JNIEnv e = *env; - static bool have_class; - if (!have_class) - { - jclass fb_class = e->GetObjectClass(env, fb_instance); - /* cache update functions */ - java_lcd_update = e->GetMethodID(env, fb_class, - "update", - "(Ljava/nio/ByteBuffer;)V"); - java_lcd_update_rect = e->GetMethodID(env, fb_class, - "update", - "(Ljava/nio/ByteBuffer;" - "Landroid/graphics/Rect;)V"); - jmethodID get_dpi = e->GetMethodID(env, fb_class, - "getDpi", "()I"); - jmethodID thresh = e->GetMethodID(env, fb_class, - "getScrollThreshold", "()I"); - /* these don't change with new instances so call them now */ - dpi = e->CallIntMethod(env, fb_instance, get_dpi); - scroll_threshold = e->CallIntMethod(env, fb_instance, thresh); - - java_lcd_init = e->GetMethodID(env, fb_class, - "initialize", "(II)V"); - AndroidRect_class = e->FindClass(env, "android/graphics/Rect"); - AndroidRect_constructor = e->GetMethodID(env, AndroidRect_class, - "", "(IIII)V"); - have_class = true; - } - - /* we need to setup parts for the java object every time */ - (*env)->CallVoidMethod(env, fb_instance, java_lcd_init, - (jint)LCD_WIDTH, (jint)LCD_HEIGHT); + jclass fb_class = e->GetObjectClass(env, fb_instance); + /* cache update functions */ + java_lcd_update = e->GetMethodID(env, fb_class, + "update", + "(Ljava/nio/ByteBuffer;)V"); + java_lcd_update_rect = e->GetMethodID(env, fb_class, + "update", + "(Ljava/nio/ByteBuffer;" + "Landroid/graphics/Rect;)V"); + jmethodID get_dpi = e->GetMethodID(env, fb_class, + "getDpi", "()I"); + jmethodID thresh = e->GetMethodID(env, fb_class, + "getScrollThreshold", "()I"); + /* these don't change with new instances so call them now */ + dpi = e->CallIntMethod(env, fb_instance, get_dpi); + scroll_threshold = e->CallIntMethod(env, fb_instance, thresh); + + AndroidRect_constructor = e->GetMethodID(env, AndroidRect_class, + "", "(IIII)V"); } /* @@ -132,12 +120,18 @@ Java_org_rockbox_RockboxFramebuffer_surfaceCreated(JNIEnv *env, jobject this, jobject surfaceholder) { (void)surfaceholder; + jclass rect; /* Update RockboxFramebuffer_instance */ RockboxFramebuffer_instance = (*env)->NewGlobalRef(env, this); - + rect = (*env)->FindClass(env, "android/graphics/Rect"); + AndroidRect_class = (*env)->NewGlobalRef(env, rect); /* possibly a new instance - reconnect */ - connect_with_java(env, this); + if (!connected) + { + connect_with_java(env, this); + connected = true; + } display_on = true; /* need to wait for button_queue to be valid to post to */ @@ -163,6 +157,8 @@ Java_org_rockbox_RockboxFramebuffer_surfaceDestroyed(JNIEnv *e, jobject this, (*e)->DeleteGlobalRef(e, RockboxFramebuffer_instance); RockboxFramebuffer_instance = NULL; + (*e)->DeleteGlobalRef(e, AndroidRect_class); + AndroidRect_class = NULL; } bool lcd_active(void) -- cgit v1.2.3