From dfdca2fcf0ce20c807447bc96da07d44fa246fad Mon Sep 17 00:00:00 2001 From: Maurus Cuelenaere Date: Mon, 31 Jan 2011 00:11:25 +0100 Subject: [PATCH 09/10] Android: graceful shutdown (WIP) --- android/src/org/rockbox/RockboxService.java | 11 +++++++++-- firmware/target/hosted/android/system-android.c | 23 ++++++++++++++++++++++- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/android/src/org/rockbox/RockboxService.java b/android/src/org/rockbox/RockboxService.java index c0c6703..15a94e9 100644 --- a/android/src/org/rockbox/RockboxService.java +++ b/android/src/org/rockbox/RockboxService.java @@ -283,6 +283,7 @@ public class RockboxService extends Service rb.setDaemon(false); rb.start(); } + private native void shutdown(); private native void main(); /* returns true once rockbox is up and running. @@ -299,7 +300,6 @@ public class RockboxService extends Service // TODO Auto-generated method stub return null; } - @SuppressWarnings("unused") /* @@ -353,7 +353,14 @@ public class RockboxService extends Service public void onDestroy() { super.onDestroy(); - fb.destroy(); + + if (fb != null) + fb.destroy(); + + /* Gracefully shutdown native code */ + if (isRockboxRunning()) + shutdown(); + /* Make sure our notification is gone. */ stopForeground(); } diff --git a/firmware/target/hosted/android/system-android.c b/firmware/target/hosted/android/system-android.c index 009630e..fa24d25 100644 --- a/firmware/target/hosted/android/system-android.c +++ b/firmware/target/hosted/android/system-android.c @@ -40,7 +40,6 @@ extern void telephony_init_device(void); void system_exception_wait(void) { } void system_reboot(void) { } -void power_off(void) { } void system_init(void) { @@ -51,6 +50,26 @@ void system_init(void) telephony_init_device(); } +static struct wakeup shutdown_completed; + +JNIEXPORT void JNICALL +Java_org_rockbox_RockboxService_shutdown(JNIEnv *env, jobject this) +{ + (void) env; + (void) this; + + /* Mimic sys_poweroff()... */ + queue_broadcast(SYS_POWEROFF, 0); + + /* ... and sleep till the system indicated it has cleaned up */ + wakeup_wait(&shutdown_completed, TIMEOUT_BLOCK); +} + +void power_off(void) +{ + wakeup_signal(&shutdown_completed); +} + /* this is the entry point of the android app initially called by jni */ JNIEXPORT void JNICALL Java_org_rockbox_RockboxService_main(JNIEnv *env, jobject this) @@ -68,5 +87,7 @@ Java_org_rockbox_RockboxService_main(JNIEnv *env, jobject this) RockboxService_instance = this; RockboxService_class = (*env)->GetObjectClass(env, this); + wakeup_init(&shutdown_completed); + main(); } -- 1.7.1