diff options
-rw-r--r-- | apps/hosted/android/keyboard.c | 5 | ||||
-rw-r--r-- | apps/hosted/android/notification.c | 5 | ||||
-rw-r--r-- | apps/hosted/android/yesno.c | 14 | ||||
-rw-r--r-- | firmware/target/hosted/android/button-android.c | 1 | ||||
-rw-r--r-- | firmware/target/hosted/android/lcd-android.c | 5 | ||||
-rw-r--r-- | firmware/target/hosted/android/pcm-android.c | 20 | ||||
-rw-r--r-- | firmware/target/hosted/android/powermgmt-android.c | 6 | ||||
-rw-r--r-- | firmware/target/hosted/android/system-android.c | 21 | ||||
-rw-r--r-- | firmware/target/hosted/android/system-target.h | 24 | ||||
-rw-r--r-- | firmware/target/hosted/android/telephony-android.c | 4 |
10 files changed, 50 insertions, 55 deletions
diff --git a/apps/hosted/android/keyboard.c b/apps/hosted/android/keyboard.c index f9bbcbb261..9407d970fd 100644 --- a/apps/hosted/android/keyboard.c +++ b/apps/hosted/android/keyboard.c | |||
@@ -26,8 +26,8 @@ | |||
26 | #include "string-extra.h" | 26 | #include "string-extra.h" |
27 | #include "kernel.h" | 27 | #include "kernel.h" |
28 | #include "lang.h" | 28 | #include "lang.h" |
29 | #include "system.h" | ||
30 | 29 | ||
30 | extern JNIEnv *env_ptr; | ||
31 | static jclass RockboxKeyboardInput_class; | 31 | static jclass RockboxKeyboardInput_class; |
32 | static jobject RockboxKeyboardInput_instance; | 32 | static jobject RockboxKeyboardInput_instance; |
33 | static jmethodID kbd_inputfunc; | 33 | static jmethodID kbd_inputfunc; |
@@ -53,9 +53,7 @@ Java_org_rockbox_RockboxKeyboardInput_put_1result(JNIEnv *env, jobject this, | |||
53 | 53 | ||
54 | static void kdb_init(void) | 54 | static void kdb_init(void) |
55 | { | 55 | { |
56 | JNIEnv *env_ptr = getJavaEnvironment(); | ||
57 | JNIEnv e = *env_ptr; | 56 | JNIEnv e = *env_ptr; |
58 | |||
59 | static jmethodID kbd_is_usable; | 57 | static jmethodID kbd_is_usable; |
60 | if (RockboxKeyboardInput_class == NULL) | 58 | if (RockboxKeyboardInput_class == NULL) |
61 | { | 59 | { |
@@ -86,7 +84,6 @@ static void kdb_init(void) | |||
86 | 84 | ||
87 | int kbd_input(char* text, int buflen) | 85 | int kbd_input(char* text, int buflen) |
88 | { | 86 | { |
89 | JNIEnv *env_ptr = getJavaEnvironment(); | ||
90 | JNIEnv e = *env_ptr; | 87 | JNIEnv e = *env_ptr; |
91 | jstring str = e->NewStringUTF(env_ptr, text); | 88 | jstring str = e->NewStringUTF(env_ptr, text); |
92 | jstring ok_text = e->NewStringUTF(env_ptr, str(LANG_KBD_OK)); | 89 | jstring ok_text = e->NewStringUTF(env_ptr, str(LANG_KBD_OK)); |
diff --git a/apps/hosted/android/notification.c b/apps/hosted/android/notification.c index e7c425b7c1..443200698c 100644 --- a/apps/hosted/android/notification.c +++ b/apps/hosted/android/notification.c | |||
@@ -29,8 +29,8 @@ | |||
29 | #include "misc.h" | 29 | #include "misc.h" |
30 | #include "thread.h" | 30 | #include "thread.h" |
31 | #include "debug.h" | 31 | #include "debug.h" |
32 | #include "system.h" | ||
33 | 32 | ||
33 | extern JNIEnv *env_ptr; | ||
34 | extern jclass RockboxService_class; | 34 | extern jclass RockboxService_class; |
35 | extern jobject RockboxService_instance; | 35 | extern jobject RockboxService_instance; |
36 | 36 | ||
@@ -47,7 +47,6 @@ static const struct dim dim = { .width = 200, .height = 200 }; | |||
47 | static void track_changed_callback(void *param) | 47 | static void track_changed_callback(void *param) |
48 | { | 48 | { |
49 | struct mp3entry* id3 = (struct mp3entry*)param; | 49 | struct mp3entry* id3 = (struct mp3entry*)param; |
50 | JNIEnv *env_ptr = getJavaEnvironment(); | ||
51 | JNIEnv e = *env_ptr; | 50 | JNIEnv e = *env_ptr; |
52 | if (id3) | 51 | if (id3) |
53 | { | 52 | { |
@@ -110,7 +109,6 @@ static void track_changed_callback(void *param) | |||
110 | static void track_finished_callback(void *param) | 109 | static void track_finished_callback(void *param) |
111 | { | 110 | { |
112 | (void)param; | 111 | (void)param; |
113 | JNIEnv *env_ptr = getJavaEnvironment(); | ||
114 | JNIEnv e = *env_ptr; | 112 | JNIEnv e = *env_ptr; |
115 | e->CallVoidMethod(env_ptr, NotificationManager_instance, | 113 | e->CallVoidMethod(env_ptr, NotificationManager_instance, |
116 | finishNotification); | 114 | finishNotification); |
@@ -124,7 +122,6 @@ static void track_finished_callback(void *param) | |||
124 | 122 | ||
125 | void notification_init(void) | 123 | void notification_init(void) |
126 | { | 124 | { |
127 | JNIEnv *env_ptr = getJavaEnvironment(); | ||
128 | JNIEnv e = *env_ptr; | 125 | JNIEnv e = *env_ptr; |
129 | jfieldID nNM = e->GetFieldID(env_ptr, RockboxService_class, | 126 | jfieldID nNM = e->GetFieldID(env_ptr, RockboxService_class, |
130 | "fg_runner", "Lorg/rockbox/Helper/RunForegroundManager;"); | 127 | "fg_runner", "Lorg/rockbox/Helper/RunForegroundManager;"); |
diff --git a/apps/hosted/android/yesno.c b/apps/hosted/android/yesno.c index 2e85ea2bc1..f08e7b2dfb 100644 --- a/apps/hosted/android/yesno.c +++ b/apps/hosted/android/yesno.c | |||
@@ -28,8 +28,8 @@ | |||
28 | #include "settings.h" | 28 | #include "settings.h" |
29 | #include "lang.h" | 29 | #include "lang.h" |
30 | #include "kernel.h" | 30 | #include "kernel.h" |
31 | #include "system.h" | ||
32 | 31 | ||
32 | extern JNIEnv *env_ptr; | ||
33 | static jobject RockboxYesno_instance = NULL; | 33 | static jobject RockboxYesno_instance = NULL; |
34 | static jmethodID yesno_func; | 34 | static jmethodID yesno_func; |
35 | static struct semaphore yesno_done; | 35 | static struct semaphore yesno_done; |
@@ -44,7 +44,7 @@ Java_org_rockbox_RockboxYesno_put_1result(JNIEnv *env, jobject this, jboolean re | |||
44 | semaphore_release(&yesno_done); | 44 | semaphore_release(&yesno_done); |
45 | } | 45 | } |
46 | 46 | ||
47 | static void yesno_init(JNIEnv *env_ptr) | 47 | static void yesno_init(void) |
48 | { | 48 | { |
49 | JNIEnv e = *env_ptr; | 49 | JNIEnv e = *env_ptr; |
50 | static jmethodID yesno_is_usable; | 50 | static jmethodID yesno_is_usable; |
@@ -74,7 +74,7 @@ static void yesno_init(JNIEnv *env_ptr) | |||
74 | sleep(HZ/10); | 74 | sleep(HZ/10); |
75 | } | 75 | } |
76 | 76 | ||
77 | static jstring build_message(JNIEnv *env_ptr, const struct text_message *message) | 77 | jstring build_message(const struct text_message *message) |
78 | { | 78 | { |
79 | char msg[1024] = ""; | 79 | char msg[1024] = ""; |
80 | JNIEnv e = *env_ptr; | 80 | JNIEnv e = *env_ptr; |
@@ -98,12 +98,10 @@ enum yesno_res gui_syncyesno_run(const struct text_message * main_message, | |||
98 | { | 98 | { |
99 | (void)yes_message; | 99 | (void)yes_message; |
100 | (void)no_message; | 100 | (void)no_message; |
101 | JNIEnv *env_ptr = getJavaEnvironment(); | 101 | yesno_init(); |
102 | 102 | ||
103 | yesno_init(env_ptr); | ||
104 | |||
105 | JNIEnv e = *env_ptr; | 103 | JNIEnv e = *env_ptr; |
106 | jstring message = build_message(env_ptr, main_message); | 104 | jstring message = build_message(main_message); |
107 | jstring yes = (*env_ptr)->NewStringUTF(env_ptr, str(LANG_SET_BOOL_YES)); | 105 | jstring yes = (*env_ptr)->NewStringUTF(env_ptr, str(LANG_SET_BOOL_YES)); |
108 | jstring no = (*env_ptr)->NewStringUTF(env_ptr, str(LANG_SET_BOOL_NO)); | 106 | jstring no = (*env_ptr)->NewStringUTF(env_ptr, str(LANG_SET_BOOL_NO)); |
109 | 107 | ||
diff --git a/firmware/target/hosted/android/button-android.c b/firmware/target/hosted/android/button-android.c index e7a3d00a65..ed1e125223 100644 --- a/firmware/target/hosted/android/button-android.c +++ b/firmware/target/hosted/android/button-android.c | |||
@@ -29,6 +29,7 @@ | |||
29 | #include "system.h" | 29 | #include "system.h" |
30 | #include "touchscreen.h" | 30 | #include "touchscreen.h" |
31 | 31 | ||
32 | extern JNIEnv *env_ptr; | ||
32 | static int last_y, last_x; | 33 | static int last_y, last_x; |
33 | static int last_btns; | 34 | static int last_btns; |
34 | 35 | ||
diff --git a/firmware/target/hosted/android/lcd-android.c b/firmware/target/hosted/android/lcd-android.c index 19f077010f..abde72155d 100644 --- a/firmware/target/hosted/android/lcd-android.c +++ b/firmware/target/hosted/android/lcd-android.c | |||
@@ -28,6 +28,7 @@ | |||
28 | #include "lcd.h" | 28 | #include "lcd.h" |
29 | #include "button.h" | 29 | #include "button.h" |
30 | 30 | ||
31 | extern JNIEnv *env_ptr; | ||
31 | extern jobject RockboxService_instance; | 32 | extern jobject RockboxService_instance; |
32 | 33 | ||
33 | static jobject RockboxFramebuffer_instance; | 34 | static jobject RockboxFramebuffer_instance; |
@@ -90,8 +91,6 @@ void lcd_init_device(void) | |||
90 | 91 | ||
91 | void lcd_update(void) | 92 | void lcd_update(void) |
92 | { | 93 | { |
93 | JNIEnv *env_ptr = getJavaEnvironment(); | ||
94 | |||
95 | if (display_on) | 94 | if (display_on) |
96 | (*env_ptr)->CallVoidMethod(env_ptr, RockboxFramebuffer_instance, | 95 | (*env_ptr)->CallVoidMethod(env_ptr, RockboxFramebuffer_instance, |
97 | java_lcd_update); | 96 | java_lcd_update); |
@@ -99,8 +98,6 @@ void lcd_update(void) | |||
99 | 98 | ||
100 | void lcd_update_rect(int x, int y, int width, int height) | 99 | void lcd_update_rect(int x, int y, int width, int height) |
101 | { | 100 | { |
102 | JNIEnv *env_ptr = getJavaEnvironment(); | ||
103 | |||
104 | if (display_on) | 101 | if (display_on) |
105 | (*env_ptr)->CallVoidMethod(env_ptr, RockboxFramebuffer_instance, | 102 | (*env_ptr)->CallVoidMethod(env_ptr, RockboxFramebuffer_instance, |
106 | java_lcd_update_rect, x, y, width, height); | 103 | java_lcd_update_rect, x, y, width, height); |
diff --git a/firmware/target/hosted/android/pcm-android.c b/firmware/target/hosted/android/pcm-android.c index 24881bd3df..edb3503262 100644 --- a/firmware/target/hosted/android/pcm-android.c +++ b/firmware/target/hosted/android/pcm-android.c | |||
@@ -21,10 +21,13 @@ | |||
21 | 21 | ||
22 | #include <jni.h> | 22 | #include <jni.h> |
23 | #include <stdbool.h> | 23 | #include <stdbool.h> |
24 | #define _SYSTEM_WITH_JNI /* for getJavaEnvironment */ | ||
24 | #include <system.h> | 25 | #include <system.h> |
25 | #include "debug.h" | 26 | #include "debug.h" |
26 | #include "pcm.h" | 27 | #include "pcm.h" |
27 | 28 | ||
29 | extern JNIEnv *env_ptr; | ||
30 | |||
28 | /* infos about our pcm chunks */ | 31 | /* infos about our pcm chunks */ |
29 | static size_t pcm_data_size; | 32 | static size_t pcm_data_size; |
30 | static char *pcm_data_start; | 33 | static char *pcm_data_start; |
@@ -115,17 +118,17 @@ void pcm_play_dma_start(const void *addr, size_t size) | |||
115 | 118 | ||
116 | void pcm_play_dma_stop(void) | 119 | void pcm_play_dma_stop(void) |
117 | { | 120 | { |
118 | JNIEnv *env_ptr = getJavaEnvironment(); | 121 | /* NOTE: due to how pcm_play_get_more_callback() works, this is |
119 | 122 | * possibly called from pcmSamplesToByteArray(), i.e. another thread. | |
120 | (*env_ptr)->CallVoidMethod(env_ptr, | 123 | * => We need to discover the env_ptr */ |
121 | RockboxPCM_instance, | 124 | JNIEnv* env = getJavaEnvironment(); |
122 | stop_method); | 125 | (*env)->CallVoidMethod(env, |
126 | RockboxPCM_instance, | ||
127 | stop_method); | ||
123 | } | 128 | } |
124 | 129 | ||
125 | void pcm_play_dma_pause(bool pause) | 130 | void pcm_play_dma_pause(bool pause) |
126 | { | 131 | { |
127 | JNIEnv *env_ptr = getJavaEnvironment(); | ||
128 | |||
129 | (*env_ptr)->CallVoidMethod(env_ptr, | 132 | (*env_ptr)->CallVoidMethod(env_ptr, |
130 | RockboxPCM_instance, | 133 | RockboxPCM_instance, |
131 | play_pause_method, | 134 | play_pause_method, |
@@ -154,7 +157,6 @@ void pcm_play_dma_init(void) | |||
154 | * Luckily we only reference the PCM object from here, so it's safe (and | 157 | * Luckily we only reference the PCM object from here, so it's safe (and |
155 | * clean) to allocate it here | 158 | * clean) to allocate it here |
156 | **/ | 159 | **/ |
157 | JNIEnv *env_ptr = getJavaEnvironment(); | ||
158 | JNIEnv e = *env_ptr; | 160 | JNIEnv e = *env_ptr; |
159 | /* get the class and its constructor */ | 161 | /* get the class and its constructor */ |
160 | jclass RockboxPCM_class = e->FindClass(env_ptr, "org/rockbox/RockboxPCM"); | 162 | jclass RockboxPCM_class = e->FindClass(env_ptr, "org/rockbox/RockboxPCM"); |
@@ -175,8 +177,6 @@ void pcm_postinit(void) | |||
175 | 177 | ||
176 | void pcm_set_mixer_volume(int volume) | 178 | void pcm_set_mixer_volume(int volume) |
177 | { | 179 | { |
178 | JNIEnv *env_ptr = getJavaEnvironment(); | ||
179 | |||
180 | (*env_ptr)->CallVoidMethod(env_ptr, RockboxPCM_instance, set_volume_method, volume); | 180 | (*env_ptr)->CallVoidMethod(env_ptr, RockboxPCM_instance, set_volume_method, volume); |
181 | } | 181 | } |
182 | 182 | ||
diff --git a/firmware/target/hosted/android/powermgmt-android.c b/firmware/target/hosted/android/powermgmt-android.c index 222212f9c8..d23fece39a 100644 --- a/firmware/target/hosted/android/powermgmt-android.c +++ b/firmware/target/hosted/android/powermgmt-android.c | |||
@@ -23,8 +23,8 @@ | |||
23 | #include <jni.h> | 23 | #include <jni.h> |
24 | #include <stdbool.h> | 24 | #include <stdbool.h> |
25 | #include "config.h" | 25 | #include "config.h" |
26 | #include "system.h" | ||
27 | 26 | ||
27 | extern JNIEnv *env_ptr; | ||
28 | extern jclass RockboxService_class; | 28 | extern jclass RockboxService_class; |
29 | extern jobject RockboxService_instance; | 29 | extern jobject RockboxService_instance; |
30 | 30 | ||
@@ -32,8 +32,6 @@ static jfieldID _battery_level; | |||
32 | 32 | ||
33 | void powermgmt_init_target(void) | 33 | void powermgmt_init_target(void) |
34 | { | 34 | { |
35 | JNIEnv *env_ptr = getJavaEnvironment(); | ||
36 | |||
37 | jmethodID initBatteryMonitor = (*env_ptr)->GetMethodID(env_ptr, | 35 | jmethodID initBatteryMonitor = (*env_ptr)->GetMethodID(env_ptr, |
38 | RockboxService_class, | 36 | RockboxService_class, |
39 | "initBatteryMonitor", | 37 | "initBatteryMonitor", |
@@ -52,8 +50,6 @@ void powermgmt_init_target(void) | |||
52 | 50 | ||
53 | int battery_level(void) | 51 | int battery_level(void) |
54 | { | 52 | { |
55 | JNIEnv *env_ptr = getJavaEnvironment(); | ||
56 | |||
57 | return (*env_ptr)->GetIntField(env_ptr, RockboxService_instance, _battery_level); | 53 | return (*env_ptr)->GetIntField(env_ptr, RockboxService_instance, _battery_level); |
58 | } | 54 | } |
59 | 55 | ||
diff --git a/firmware/target/hosted/android/system-android.c b/firmware/target/hosted/android/system-android.c index 8d36198c61..686453cfbb 100644 --- a/firmware/target/hosted/android/system-android.c +++ b/firmware/target/hosted/android/system-android.c | |||
@@ -27,7 +27,8 @@ | |||
27 | 27 | ||
28 | 28 | ||
29 | /* global fields for use with various JNI calls */ | 29 | /* global fields for use with various JNI calls */ |
30 | JavaVM *vm_ptr; | 30 | static JavaVM *vm_ptr; |
31 | JNIEnv *env_ptr; | ||
31 | jobject RockboxService_instance; | 32 | jobject RockboxService_instance; |
32 | jclass RockboxService_class; | 33 | jclass RockboxService_class; |
33 | 34 | ||
@@ -47,6 +48,22 @@ void system_init(void) | |||
47 | telephony_init_device(); | 48 | telephony_init_device(); |
48 | } | 49 | } |
49 | 50 | ||
51 | JNIEXPORT jint JNICALL | ||
52 | JNI_OnLoad(JavaVM *vm, void* reserved) | ||
53 | { | ||
54 | (void)reserved; | ||
55 | vm_ptr = vm; | ||
56 | |||
57 | return JNI_VERSION_1_2; | ||
58 | } | ||
59 | |||
60 | JNIEnv* getJavaEnvironment(void) | ||
61 | { | ||
62 | JNIEnv* env; | ||
63 | (*vm_ptr)->GetEnv(vm_ptr, (void**) &env, JNI_VERSION_1_2); | ||
64 | return env; | ||
65 | } | ||
66 | |||
50 | /* this is the entry point of the android app initially called by jni */ | 67 | /* this is the entry point of the android app initially called by jni */ |
51 | JNIEXPORT void JNICALL | 68 | JNIEXPORT void JNICALL |
52 | Java_org_rockbox_RockboxService_main(JNIEnv *env, jobject this) | 69 | Java_org_rockbox_RockboxService_main(JNIEnv *env, jobject this) |
@@ -58,8 +75,8 @@ Java_org_rockbox_RockboxService_main(JNIEnv *env, jobject this) | |||
58 | 75 | ||
59 | volatile uintptr_t stack = 0; | 76 | volatile uintptr_t stack = 0; |
60 | stackbegin = stackend = (uintptr_t*) &stack; | 77 | stackbegin = stackend = (uintptr_t*) &stack; |
78 | env_ptr = env; | ||
61 | 79 | ||
62 | (*env)->GetJavaVM(env, &vm_ptr); | ||
63 | RockboxService_instance = this; | 80 | RockboxService_instance = this; |
64 | RockboxService_class = (*env)->GetObjectClass(env, this); | 81 | RockboxService_class = (*env)->GetObjectClass(env, this); |
65 | 82 | ||
diff --git a/firmware/target/hosted/android/system-target.h b/firmware/target/hosted/android/system-target.h index 9145ab1e84..325c1012af 100644 --- a/firmware/target/hosted/android/system-target.h +++ b/firmware/target/hosted/android/system-target.h | |||
@@ -21,8 +21,6 @@ | |||
21 | #ifndef __SYSTEM_TARGET_H__ | 21 | #ifndef __SYSTEM_TARGET_H__ |
22 | #define __SYSTEM_TARGET_H__ | 22 | #define __SYSTEM_TARGET_H__ |
23 | 23 | ||
24 | #include <jni.h> | ||
25 | |||
26 | #define disable_irq() | 24 | #define disable_irq() |
27 | #define enable_irq() | 25 | #define enable_irq() |
28 | #define disable_irq_save() 0 | 26 | #define disable_irq_save() 0 |
@@ -32,19 +30,15 @@ void power_off(void); | |||
32 | void wait_for_interrupt(void); | 30 | void wait_for_interrupt(void); |
33 | void interrupt(void); | 31 | void interrupt(void); |
34 | 32 | ||
35 | /* A JNI environment is specific to its thread, so use the correct way to | 33 | /* don't pull in jni.h for every user of this file, it should be only needed |
36 | * obtain it: share a pointer to the JavaVM structure and ask that the JNI | 34 | * within the target tree (if at all) |
37 | * environment attached to the current thread. */ | 35 | * define this before #including system.h or system-target.h */ |
38 | static inline JNIEnv* getJavaEnvironment(void) | 36 | #ifdef _SYSTEM_WITH_JNI |
39 | { | 37 | #include <jni.h> |
40 | extern JavaVM *vm_ptr; | 38 | /* |
41 | JNIEnv *env = NULL; | 39 | * discover the JNIEnv for this the calling thread in case it's not known */ |
42 | 40 | extern JNIEnv* getJavaEnvironment(void); | |
43 | if (vm_ptr) | 41 | #endif /* _SYSTEM_WITH_JNI */ |
44 | (*vm_ptr)->GetEnv(vm_ptr, (void**) &env, JNI_VERSION_1_2); | ||
45 | |||
46 | return env; | ||
47 | } | ||
48 | 42 | ||
49 | #endif /* __SYSTEM_TARGET_H__ */ | 43 | #endif /* __SYSTEM_TARGET_H__ */ |
50 | 44 | ||
diff --git a/firmware/target/hosted/android/telephony-android.c b/firmware/target/hosted/android/telephony-android.c index fb2dc37623..64ad436ca7 100644 --- a/firmware/target/hosted/android/telephony-android.c +++ b/firmware/target/hosted/android/telephony-android.c | |||
@@ -22,16 +22,14 @@ | |||
22 | 22 | ||
23 | #include <jni.h> | 23 | #include <jni.h> |
24 | #include "kernel.h" | 24 | #include "kernel.h" |
25 | #include "system.h" | ||
26 | 25 | ||
26 | extern JNIEnv *env_ptr; | ||
27 | extern jobject RockboxService_instance; | 27 | extern jobject RockboxService_instance; |
28 | 28 | ||
29 | 29 | ||
30 | void telephony_init_device(void) | 30 | void telephony_init_device(void) |
31 | { | 31 | { |
32 | JNIEnv *env_ptr = getJavaEnvironment(); | ||
33 | JNIEnv e = *env_ptr; | 32 | JNIEnv e = *env_ptr; |
34 | |||
35 | jclass class = e->FindClass(env_ptr, "org/rockbox/RockboxTelephony"); | 33 | jclass class = e->FindClass(env_ptr, "org/rockbox/RockboxTelephony"); |
36 | jmethodID constructor = e->GetMethodID(env_ptr, class, "<init>", "(Landroid/content/Context;)V"); | 34 | jmethodID constructor = e->GetMethodID(env_ptr, class, "<init>", "(Landroid/content/Context;)V"); |
37 | 35 | ||