Partly revert "Android: use NewGlobalRef for references that are used globally"
The added complexity wasn't needed for most subsystems, as main() never returns so local references can't be freed. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29570 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
66f2a08f8a
commit
c2ee32b22a
6 changed files with 23 additions and 48 deletions
|
@ -61,17 +61,14 @@ static void kdb_init(void)
|
|||
{
|
||||
semaphore_init(&kbd_wakeup, 1, 0);
|
||||
/* get the class and its constructor */
|
||||
jclass kbInput_class = e->FindClass(env_ptr,
|
||||
RockboxKeyboardInput_class = e->FindClass(env_ptr,
|
||||
"org/rockbox/RockboxKeyboardInput");
|
||||
RockboxKeyboardInput_class = e->NewGlobalRef(env_ptr, kbInput_class);
|
||||
jmethodID constructor = e->GetMethodID(env_ptr,
|
||||
RockboxKeyboardInput_class,
|
||||
"<init>", "()V");
|
||||
jobject kbInput_instance = e->NewObject(env_ptr,
|
||||
RockboxKeyboardInput_class,
|
||||
constructor);
|
||||
RockboxKeyboardInput_instance = e->NewGlobalRef(env_ptr,
|
||||
kbInput_instance);
|
||||
RockboxKeyboardInput_instance = e->NewObject(env_ptr,
|
||||
RockboxKeyboardInput_class,
|
||||
constructor);
|
||||
kbd_inputfunc = e->GetMethodID(env_ptr, RockboxKeyboardInput_class,
|
||||
"kbd_input",
|
||||
"(Ljava/lang/String;"
|
||||
|
|
|
@ -128,14 +128,13 @@ void notification_init(void)
|
|||
JNIEnv e = *env_ptr;
|
||||
jfieldID nNM = e->GetFieldID(env_ptr, RockboxService_class,
|
||||
"fg_runner", "Lorg/rockbox/Helper/RunForegroundManager;");
|
||||
jobject nMN_instance = e->GetObjectField(env_ptr,
|
||||
RockboxService_instance, nNM);
|
||||
if (nMN_instance == NULL)
|
||||
NotificationManager_instance = e->GetObjectField(env_ptr,
|
||||
RockboxService_instance, nNM);
|
||||
if (NotificationManager_instance == NULL)
|
||||
{
|
||||
DEBUGF("Failed to get RunForegroundManager instance. Performance will be bad");
|
||||
return;
|
||||
}
|
||||
NotificationManager_instance = e->NewGlobalRef(env_ptr, nMN_instance);
|
||||
|
||||
jclass class = e->GetObjectClass(env_ptr, NotificationManager_instance);
|
||||
updateNotification = e->GetMethodID(env_ptr, class, "updateNotification",
|
||||
|
|
|
@ -52,21 +52,20 @@ static void yesno_init(JNIEnv *env_ptr)
|
|||
{
|
||||
semaphore_init(&yesno_done, 1, 0);
|
||||
/* get the class and its constructor */
|
||||
jclass yesno_class = e->FindClass(env_ptr,
|
||||
"org/rockbox/RockboxYesno");
|
||||
jclass RockboxYesno_class = e->FindClass(env_ptr,
|
||||
"org/rockbox/RockboxYesno");
|
||||
jmethodID constructor = e->GetMethodID(env_ptr,
|
||||
yesno_class,
|
||||
RockboxYesno_class,
|
||||
"<init>", "()V");
|
||||
jobject yesno_instance = e->NewObject(env_ptr,
|
||||
yesno_class,
|
||||
constructor);
|
||||
RockboxYesno_instance = e->NewGlobalRef(env_ptr, yesno_instance);
|
||||
yesno_func = e->GetMethodID(env_ptr, yesno_class,
|
||||
RockboxYesno_instance = e->NewObject(env_ptr,
|
||||
RockboxYesno_class,
|
||||
constructor);
|
||||
yesno_func = e->GetMethodID(env_ptr, RockboxYesno_class,
|
||||
"yesno_display",
|
||||
"(Ljava/lang/String;"
|
||||
"Ljava/lang/String;"
|
||||
"Ljava/lang/String;)V");
|
||||
yesno_is_usable = e->GetMethodID(env_ptr, yesno_class,
|
||||
yesno_is_usable = e->GetMethodID(env_ptr, RockboxYesno_class,
|
||||
"is_usable", "()Z");
|
||||
}
|
||||
/* need to get it every time incase the activity died/restarted */
|
||||
|
|
|
@ -46,7 +46,6 @@ static bool display_on;
|
|||
void connect_with_java(JNIEnv* env, jobject fb_instance)
|
||||
{
|
||||
JNIEnv e = *env;
|
||||
|
||||
/* Update RockboxFramebuffer_instance */
|
||||
if (!e->IsSameObject(env, RockboxFramebuffer_instance, fb_instance)) {
|
||||
if (RockboxFramebuffer_instance != NULL)
|
||||
|
@ -55,7 +54,7 @@ void connect_with_java(JNIEnv* env, jobject fb_instance)
|
|||
RockboxFramebuffer_instance = e->NewGlobalRef(env, fb_instance);
|
||||
}
|
||||
|
||||
static bool have_class = false;
|
||||
static bool have_class;
|
||||
if (!have_class)
|
||||
{
|
||||
jclass fb_class = e->GetObjectClass(env, fb_instance);
|
||||
|
@ -77,13 +76,10 @@ void connect_with_java(JNIEnv* env, jobject fb_instance)
|
|||
java_lcd_init = e->GetMethodID(env, fb_class,
|
||||
"java_lcd_init",
|
||||
"(IILjava/nio/ByteBuffer;)V");
|
||||
|
||||
jobject buffer = e->NewDirectByteBuffer(env,
|
||||
|
||||
native_buffer = e->NewDirectByteBuffer(env,
|
||||
lcd_framebuffer,
|
||||
(jlong)sizeof(lcd_framebuffer));
|
||||
|
||||
native_buffer = e->NewGlobalRef(env, buffer);
|
||||
|
||||
have_class = true;
|
||||
}
|
||||
/* we need to setup parts for the java object every time */
|
||||
|
@ -96,7 +92,6 @@ void lcd_deinit(void)
|
|||
JNIEnv *env_ptr = getJavaEnvironment();
|
||||
|
||||
(*env_ptr)->DeleteGlobalRef(env_ptr, RockboxFramebuffer_instance);
|
||||
(*env_ptr)->DeleteGlobalRef(env_ptr, native_buffer);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -33,6 +33,7 @@ static char *pcm_data_start;
|
|||
static jmethodID play_pause_method;
|
||||
static jmethodID stop_method;
|
||||
static jmethodID set_volume_method;
|
||||
static jclass RockboxPCM_class;
|
||||
static jobject RockboxPCM_instance;
|
||||
|
||||
|
||||
|
@ -157,11 +158,10 @@ void pcm_play_dma_init(void)
|
|||
JNIEnv *env_ptr = getJavaEnvironment();
|
||||
JNIEnv e = *env_ptr;
|
||||
/* get the class and its constructor */
|
||||
jclass RockboxPCM_class = e->FindClass(env_ptr, "org/rockbox/RockboxPCM");
|
||||
RockboxPCM_class = e->FindClass(env_ptr, "org/rockbox/RockboxPCM");
|
||||
jmethodID constructor = e->GetMethodID(env_ptr, RockboxPCM_class, "<init>", "()V");
|
||||
/* instance = new RockboxPCM() */
|
||||
jobject PCM_instance = e->NewObject(env_ptr, RockboxPCM_class, constructor);
|
||||
RockboxPCM_instance = e->NewGlobalRef(env_ptr, PCM_instance);
|
||||
RockboxPCM_instance = e->NewObject(env_ptr, RockboxPCM_class, constructor);
|
||||
/* cache needed methods */
|
||||
play_pause_method = e->GetMethodID(env_ptr, RockboxPCM_class, "play_pause", "(Z)V");
|
||||
set_volume_method = e->GetMethodID(env_ptr, RockboxPCM_class, "set_volume", "(I)V");
|
||||
|
@ -170,13 +170,6 @@ void pcm_play_dma_init(void)
|
|||
pcm_play_get_more_callback((void*)&pcm_data_start, &pcm_data_size);
|
||||
}
|
||||
|
||||
void pcm_deinit(void)
|
||||
{
|
||||
JNIEnv *env_ptr = getJavaEnvironment();
|
||||
|
||||
(*env_ptr)->DeleteGlobalRef(env_ptr, RockboxPCM_instance);
|
||||
}
|
||||
|
||||
void pcm_postinit(void)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -37,19 +37,13 @@ uintptr_t *stackend;
|
|||
extern int main(void);
|
||||
extern void telephony_init_device(void);
|
||||
extern void lcd_deinit(void);
|
||||
extern void pcm_deinit(void);
|
||||
|
||||
void system_exception_wait(void) { }
|
||||
void system_reboot(void) { }
|
||||
|
||||
void power_off(void)
|
||||
{
|
||||
JNIEnv *env_ptr = getJavaEnvironment();
|
||||
|
||||
lcd_deinit();
|
||||
pcm_deinit();
|
||||
|
||||
(*env_ptr)->DeleteGlobalRef(env_ptr, RockboxService_class);
|
||||
}
|
||||
|
||||
void system_init(void)
|
||||
|
@ -62,8 +56,6 @@ void system_init(void)
|
|||
JNIEXPORT void JNICALL
|
||||
Java_org_rockbox_RockboxService_main(JNIEnv *env, jobject this)
|
||||
{
|
||||
jclass class = (*env)->GetObjectClass(env, this);
|
||||
|
||||
/* hack!!! we can't have a valid stack pointer otherwise.
|
||||
* but we don't really need it anyway, thread.c only needs it
|
||||
* for overflow detection which doesn't apply for the main thread
|
||||
|
@ -73,8 +65,8 @@ Java_org_rockbox_RockboxService_main(JNIEnv *env, jobject this)
|
|||
stackbegin = stackend = (uintptr_t*) &stack;
|
||||
|
||||
(*env)->GetJavaVM(env, &vm_ptr);
|
||||
RockboxService_instance = (*env)->NewGlobalRef(env, this);
|
||||
RockboxService_class = (*env)->NewGlobalRef(env, class);
|
||||
RockboxService_instance = this;
|
||||
RockboxService_class = (*env)->GetObjectClass(env, this);
|
||||
|
||||
main();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue