diff options
author | Maurus Cuelenaere <mcuelenaere@gmail.com> | 2011-03-11 18:34:31 +0000 |
---|---|---|
committer | Maurus Cuelenaere <mcuelenaere@gmail.com> | 2011-03-11 18:34:31 +0000 |
commit | 2e5b7aebde6426058ea7b69424b0335a844a6a18 (patch) | |
tree | 2ce54c30eb646b1d78d38ff34ff3eb3f76955bff | |
parent | 7228f2fa9faf587bab51f2e3c1727b7ca962b441 (diff) | |
download | rockbox-2e5b7aebde6426058ea7b69424b0335a844a6a18.tar.gz rockbox-2e5b7aebde6426058ea7b69424b0335a844a6a18.zip |
Android: use NewGlobalRef for references that are used globally
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29568 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/hosted/android/keyboard.c | 11 | ||||
-rw-r--r-- | apps/hosted/android/notification.c | 7 | ||||
-rw-r--r-- | apps/hosted/android/yesno.c | 20 | ||||
-rw-r--r-- | firmware/target/hosted/android/lcd-android.c | 25 | ||||
-rw-r--r-- | firmware/target/hosted/android/pcm-android.c | 11 | ||||
-rw-r--r-- | firmware/target/hosted/android/system-android.c | 19 |
6 files changed, 64 insertions, 29 deletions
diff --git a/apps/hosted/android/keyboard.c b/apps/hosted/android/keyboard.c index 9407d970fd..7c16cff079 100644 --- a/apps/hosted/android/keyboard.c +++ b/apps/hosted/android/keyboard.c | |||
@@ -59,14 +59,17 @@ static void kdb_init(void) | |||
59 | { | 59 | { |
60 | semaphore_init(&kbd_wakeup, 1, 0); | 60 | semaphore_init(&kbd_wakeup, 1, 0); |
61 | /* get the class and its constructor */ | 61 | /* get the class and its constructor */ |
62 | RockboxKeyboardInput_class = e->FindClass(env_ptr, | 62 | jclass kbInput_class = e->FindClass(env_ptr, |
63 | "org/rockbox/RockboxKeyboardInput"); | 63 | "org/rockbox/RockboxKeyboardInput"); |
64 | RockboxKeyboardInput_class = e->NewGlobalRef(env_ptr, kbInput_class); | ||
64 | jmethodID constructor = e->GetMethodID(env_ptr, | 65 | jmethodID constructor = e->GetMethodID(env_ptr, |
65 | RockboxKeyboardInput_class, | 66 | RockboxKeyboardInput_class, |
66 | "<init>", "()V"); | 67 | "<init>", "()V"); |
67 | RockboxKeyboardInput_instance = e->NewObject(env_ptr, | 68 | jobject kbInput_instance = e->NewObject(env_ptr, |
68 | RockboxKeyboardInput_class, | 69 | RockboxKeyboardInput_class, |
69 | constructor); | 70 | constructor); |
71 | RockboxKeyboardInput_instance = e->NewGlobalRef(env_ptr, | ||
72 | kbInput_instance); | ||
70 | kbd_inputfunc = e->GetMethodID(env_ptr, RockboxKeyboardInput_class, | 73 | kbd_inputfunc = e->GetMethodID(env_ptr, RockboxKeyboardInput_class, |
71 | "kbd_input", | 74 | "kbd_input", |
72 | "(Ljava/lang/String;" | 75 | "(Ljava/lang/String;" |
diff --git a/apps/hosted/android/notification.c b/apps/hosted/android/notification.c index 443200698c..33a7717012 100644 --- a/apps/hosted/android/notification.c +++ b/apps/hosted/android/notification.c | |||
@@ -125,13 +125,14 @@ void notification_init(void) | |||
125 | JNIEnv e = *env_ptr; | 125 | JNIEnv e = *env_ptr; |
126 | jfieldID nNM = e->GetFieldID(env_ptr, RockboxService_class, | 126 | jfieldID nNM = e->GetFieldID(env_ptr, RockboxService_class, |
127 | "fg_runner", "Lorg/rockbox/Helper/RunForegroundManager;"); | 127 | "fg_runner", "Lorg/rockbox/Helper/RunForegroundManager;"); |
128 | NotificationManager_instance = e->GetObjectField(env_ptr, | 128 | jobject nMN_instance = e->GetObjectField(env_ptr, |
129 | RockboxService_instance, nNM); | 129 | RockboxService_instance, nNM); |
130 | if (NotificationManager_instance == NULL) | 130 | if (nMN_instance == NULL) |
131 | { | 131 | { |
132 | DEBUGF("Failed to get RunForegroundManager instance. Performance will be bad"); | 132 | DEBUGF("Failed to get RunForegroundManager instance. Performance will be bad"); |
133 | return; | 133 | return; |
134 | } | 134 | } |
135 | NotificationManager_instance = e->NewGlobalRef(env_ptr, nMN_instance); | ||
135 | 136 | ||
136 | jclass class = e->GetObjectClass(env_ptr, NotificationManager_instance); | 137 | jclass class = e->GetObjectClass(env_ptr, NotificationManager_instance); |
137 | updateNotification = e->GetMethodID(env_ptr, class, "updateNotification", | 138 | updateNotification = e->GetMethodID(env_ptr, class, "updateNotification", |
diff --git a/apps/hosted/android/yesno.c b/apps/hosted/android/yesno.c index a1de64e3f9..7aca3f7f79 100644 --- a/apps/hosted/android/yesno.c +++ b/apps/hosted/android/yesno.c | |||
@@ -30,7 +30,6 @@ | |||
30 | #include "kernel.h" | 30 | #include "kernel.h" |
31 | 31 | ||
32 | extern JNIEnv *env_ptr; | 32 | extern JNIEnv *env_ptr; |
33 | static jclass RockboxYesno_class = NULL; | ||
34 | static jobject RockboxYesno_instance = NULL; | 33 | static jobject RockboxYesno_instance = NULL; |
35 | static jmethodID yesno_func; | 34 | static jmethodID yesno_func; |
36 | static struct semaphore yesno_done; | 35 | static struct semaphore yesno_done; |
@@ -49,24 +48,25 @@ static void yesno_init(void) | |||
49 | { | 48 | { |
50 | JNIEnv e = *env_ptr; | 49 | JNIEnv e = *env_ptr; |
51 | static jmethodID yesno_is_usable; | 50 | static jmethodID yesno_is_usable; |
52 | if (RockboxYesno_class == NULL) | 51 | if (RockboxYesno_instance == NULL) |
53 | { | 52 | { |
54 | semaphore_init(&yesno_done, 1, 0); | 53 | semaphore_init(&yesno_done, 1, 0); |
55 | /* get the class and its constructor */ | 54 | /* get the class and its constructor */ |
56 | RockboxYesno_class = e->FindClass(env_ptr, | 55 | jclass yesno_class = e->FindClass(env_ptr, |
57 | "org/rockbox/RockboxYesno"); | 56 | "org/rockbox/RockboxYesno"); |
58 | jmethodID constructor = e->GetMethodID(env_ptr, | 57 | jmethodID constructor = e->GetMethodID(env_ptr, |
59 | RockboxYesno_class, | 58 | yesno_class, |
60 | "<init>", "()V"); | 59 | "<init>", "()V"); |
61 | RockboxYesno_instance = e->NewObject(env_ptr, | 60 | jobject yesno_instance = e->NewObject(env_ptr, |
62 | RockboxYesno_class, | 61 | yesno_class, |
63 | constructor); | 62 | constructor); |
64 | yesno_func = e->GetMethodID(env_ptr, RockboxYesno_class, | 63 | RockboxYesno_instance = e->NewGlobalRef(env_ptr, yesno_instance); |
64 | yesno_func = e->GetMethodID(env_ptr, yesno_class, | ||
65 | "yesno_display", | 65 | "yesno_display", |
66 | "(Ljava/lang/String;" | 66 | "(Ljava/lang/String;" |
67 | "Ljava/lang/String;" | 67 | "Ljava/lang/String;" |
68 | "Ljava/lang/String;)V"); | 68 | "Ljava/lang/String;)V"); |
69 | yesno_is_usable = e->GetMethodID(env_ptr, RockboxYesno_class, | 69 | yesno_is_usable = e->GetMethodID(env_ptr, yesno_class, |
70 | "is_usable", "()Z"); | 70 | "is_usable", "()Z"); |
71 | } | 71 | } |
72 | /* need to get it every time incase the activity died/restarted */ | 72 | /* need to get it every time incase the activity died/restarted */ |
diff --git a/firmware/target/hosted/android/lcd-android.c b/firmware/target/hosted/android/lcd-android.c index 0cde160e65..08a4075795 100644 --- a/firmware/target/hosted/android/lcd-android.c +++ b/firmware/target/hosted/android/lcd-android.c | |||
@@ -47,8 +47,16 @@ static bool display_on; | |||
47 | void connect_with_java(JNIEnv* env, jobject fb_instance) | 47 | void connect_with_java(JNIEnv* env, jobject fb_instance) |
48 | { | 48 | { |
49 | JNIEnv e = *env; | 49 | JNIEnv e = *env; |
50 | static bool have_class; | 50 | |
51 | RockboxFramebuffer_instance = fb_instance; | 51 | /* Update RockboxFramebuffer_instance */ |
52 | if (!e->IsSameObject(env, RockboxFramebuffer_instance, fb_instance)) { | ||
53 | if (RockboxFramebuffer_instance != NULL) | ||
54 | e->DeleteGlobalRef(env, RockboxFramebuffer_instance); | ||
55 | |||
56 | RockboxFramebuffer_instance = e->NewGlobalRef(env, fb_instance); | ||
57 | } | ||
58 | |||
59 | static bool have_class = false; | ||
52 | if (!have_class) | 60 | if (!have_class) |
53 | { | 61 | { |
54 | jclass fb_class = e->GetObjectClass(env, fb_instance); | 62 | jclass fb_class = e->GetObjectClass(env, fb_instance); |
@@ -70,10 +78,13 @@ void connect_with_java(JNIEnv* env, jobject fb_instance) | |||
70 | java_lcd_init = e->GetMethodID(env, fb_class, | 78 | java_lcd_init = e->GetMethodID(env, fb_class, |
71 | "java_lcd_init", | 79 | "java_lcd_init", |
72 | "(IILjava/nio/ByteBuffer;)V"); | 80 | "(IILjava/nio/ByteBuffer;)V"); |
73 | 81 | ||
74 | native_buffer = e->NewDirectByteBuffer(env, | 82 | jobject buffer = e->NewDirectByteBuffer(env, |
75 | lcd_framebuffer, | 83 | lcd_framebuffer, |
76 | (jlong)sizeof(lcd_framebuffer)); | 84 | (jlong)sizeof(lcd_framebuffer)); |
85 | |||
86 | native_buffer = e->NewGlobalRef(env, buffer); | ||
87 | |||
77 | have_class = true; | 88 | have_class = true; |
78 | } | 89 | } |
79 | /* we need to setup parts for the java object every time */ | 90 | /* we need to setup parts for the java object every time */ |
@@ -81,6 +92,12 @@ void connect_with_java(JNIEnv* env, jobject fb_instance) | |||
81 | (jint)LCD_WIDTH, (jint)LCD_HEIGHT, native_buffer); | 92 | (jint)LCD_WIDTH, (jint)LCD_HEIGHT, native_buffer); |
82 | } | 93 | } |
83 | 94 | ||
95 | void lcd_deinit(void) | ||
96 | { | ||
97 | (*env_ptr)->DeleteGlobalRef(env_ptr, RockboxFramebuffer_instance); | ||
98 | (*env_ptr)->DeleteGlobalRef(env_ptr, native_buffer); | ||
99 | } | ||
100 | |||
84 | /* | 101 | /* |
85 | * Do nothing here and connect with the java object later (if it isn't already) | 102 | * Do nothing here and connect with the java object later (if it isn't already) |
86 | */ | 103 | */ |
diff --git a/firmware/target/hosted/android/pcm-android.c b/firmware/target/hosted/android/pcm-android.c index c8bc410a54..f4ed4b1b33 100644 --- a/firmware/target/hosted/android/pcm-android.c +++ b/firmware/target/hosted/android/pcm-android.c | |||
@@ -35,7 +35,6 @@ static char *pcm_data_start; | |||
35 | static jmethodID play_pause_method; | 35 | static jmethodID play_pause_method; |
36 | static jmethodID stop_method; | 36 | static jmethodID stop_method; |
37 | static jmethodID set_volume_method; | 37 | static jmethodID set_volume_method; |
38 | static jclass RockboxPCM_class; | ||
39 | static jobject RockboxPCM_instance; | 38 | static jobject RockboxPCM_instance; |
40 | 39 | ||
41 | 40 | ||
@@ -155,10 +154,11 @@ void pcm_play_dma_init(void) | |||
155 | **/ | 154 | **/ |
156 | JNIEnv e = *env_ptr; | 155 | JNIEnv e = *env_ptr; |
157 | /* get the class and its constructor */ | 156 | /* get the class and its constructor */ |
158 | RockboxPCM_class = e->FindClass(env_ptr, "org/rockbox/RockboxPCM"); | 157 | jclass RockboxPCM_class = e->FindClass(env_ptr, "org/rockbox/RockboxPCM"); |
159 | jmethodID constructor = e->GetMethodID(env_ptr, RockboxPCM_class, "<init>", "()V"); | 158 | jmethodID constructor = e->GetMethodID(env_ptr, RockboxPCM_class, "<init>", "()V"); |
160 | /* instance = new RockboxPCM() */ | 159 | /* instance = new RockboxPCM() */ |
161 | RockboxPCM_instance = e->NewObject(env_ptr, RockboxPCM_class, constructor); | 160 | jobject PCM_instance = e->NewObject(env_ptr, RockboxPCM_class, constructor); |
161 | RockboxPCM_instance = e->NewGlobalRef(env_ptr, PCM_instance); | ||
162 | /* cache needed methods */ | 162 | /* cache needed methods */ |
163 | play_pause_method = e->GetMethodID(env_ptr, RockboxPCM_class, "play_pause", "(Z)V"); | 163 | play_pause_method = e->GetMethodID(env_ptr, RockboxPCM_class, "play_pause", "(Z)V"); |
164 | set_volume_method = e->GetMethodID(env_ptr, RockboxPCM_class, "set_volume", "(I)V"); | 164 | set_volume_method = e->GetMethodID(env_ptr, RockboxPCM_class, "set_volume", "(I)V"); |
@@ -167,6 +167,11 @@ void pcm_play_dma_init(void) | |||
167 | pcm_play_get_more_callback((void*)&pcm_data_start, &pcm_data_size); | 167 | pcm_play_get_more_callback((void*)&pcm_data_start, &pcm_data_size); |
168 | } | 168 | } |
169 | 169 | ||
170 | void pcm_deinit(void) | ||
171 | { | ||
172 | (*env_ptr)->DeleteGlobalRef(env_ptr, RockboxPCM_instance); | ||
173 | } | ||
174 | |||
170 | void pcm_postinit(void) | 175 | void pcm_postinit(void) |
171 | { | 176 | { |
172 | } | 177 | } |
diff --git a/firmware/target/hosted/android/system-android.c b/firmware/target/hosted/android/system-android.c index 92c2d7cf5d..66de4e0ebb 100644 --- a/firmware/target/hosted/android/system-android.c +++ b/firmware/target/hosted/android/system-android.c | |||
@@ -36,10 +36,18 @@ uintptr_t *stackend; | |||
36 | 36 | ||
37 | extern int main(void); | 37 | extern int main(void); |
38 | extern void telephony_init_device(void); | 38 | extern void telephony_init_device(void); |
39 | extern void lcd_deinit(void); | ||
40 | extern void pcm_deinit(void); | ||
39 | 41 | ||
40 | void system_exception_wait(void) { } | 42 | void system_exception_wait(void) { } |
41 | void system_reboot(void) { } | 43 | void system_reboot(void) { } |
42 | void power_off(void) { } | 44 | |
45 | void power_off(void) | ||
46 | { | ||
47 | lcd_deinit(); | ||
48 | pcm_deinit(); | ||
49 | (*env_ptr)->DeleteGlobalRef(env_ptr, RockboxService_class); | ||
50 | } | ||
43 | 51 | ||
44 | void system_init(void) | 52 | void system_init(void) |
45 | { | 53 | { |
@@ -51,18 +59,19 @@ void system_init(void) | |||
51 | JNIEXPORT void JNICALL | 59 | JNIEXPORT void JNICALL |
52 | Java_org_rockbox_RockboxService_main(JNIEnv *env, jobject this) | 60 | Java_org_rockbox_RockboxService_main(JNIEnv *env, jobject this) |
53 | { | 61 | { |
62 | jclass class = (*env)->GetObjectClass(env, this); | ||
63 | |||
54 | /* hack!!! we can't have a valid stack pointer otherwise. | 64 | /* hack!!! we can't have a valid stack pointer otherwise. |
55 | * but we don't really need it anyway, thread.c only needs it | 65 | * but we don't really need it anyway, thread.c only needs it |
56 | * for overflow detection which doesn't apply for the main thread | 66 | * for overflow detection which doesn't apply for the main thread |
57 | * (it's managed by the OS) */ | 67 | * (it's managed by the OS) */ |
58 | 68 | ||
59 | (void)env; | ||
60 | (void)this; | ||
61 | volatile uintptr_t stack = 0; | 69 | volatile uintptr_t stack = 0; |
62 | stackbegin = stackend = (uintptr_t*) &stack; | 70 | stackbegin = stackend = (uintptr_t*) &stack; |
63 | env_ptr = env; | 71 | env_ptr = env; |
64 | RockboxService_instance = this; | 72 | |
65 | RockboxService_class = (*env)->GetObjectClass(env, this); | 73 | RockboxService_instance = (*env)->NewGlobalRef(env, this); |
74 | RockboxService_class = (*env)->NewGlobalRef(env, class); | ||
66 | 75 | ||
67 | main(); | 76 | main(); |
68 | } | 77 | } |