summaryrefslogtreecommitdiffstats
path: root/firmware
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2011-03-16 15:17:24 +0000
committerThomas Martitz <kugel@rockbox.org>2011-03-16 15:17:24 +0000
commit8c46ddf9d719fb29f483dc21993167907953f39c (patch)
tree03d99235b88ba6f327db503f65e67061ae5568e3 /firmware
parent046cec3aa7fd58a9519cad8d693b47a2400e1742 (diff)
downloadrockbox-8c46ddf9d719fb29f483dc21993167907953f39c.tar.gz
rockbox-8c46ddf9d719fb29f483dc21993167907953f39c.zip
Android: Implement app shutdown and thus, sleep timer.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29602 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r--firmware/target/hosted/android/pcm-android.c12
-rw-r--r--firmware/target/hosted/android/system-android.c26
2 files changed, 32 insertions, 6 deletions
diff --git a/firmware/target/hosted/android/pcm-android.c b/firmware/target/hosted/android/pcm-android.c
index edb3503262..cc8bd9c48a 100644
--- a/firmware/target/hosted/android/pcm-android.c
+++ b/firmware/target/hosted/android/pcm-android.c
@@ -36,6 +36,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;
@@ -159,7 +160,7 @@ void pcm_play_dma_init(void)
**/
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() */
RockboxPCM_instance = e->NewObject(env_ptr, RockboxPCM_class, constructor);
@@ -180,6 +181,15 @@ void pcm_set_mixer_volume(int volume)
(*env_ptr)->CallVoidMethod(env_ptr, RockboxPCM_instance, set_volume_method, volume);
}
+/*
+ * release audio resources */
+void pcm_shutdown(void)
+{
+ JNIEnv e = *env_ptr;
+ jmethodID release = e->GetMethodID(env_ptr, RockboxPCM_class, "release", "()V");
+ e->CallVoidMethod(env_ptr, RockboxPCM_instance, release);
+}
+
/* Due to limitations of default_event_handler(), parameters gets swallowed when
* being posted with queue_broadcast(), so workaround this by caching the last
* value.
diff --git a/firmware/target/hosted/android/system-android.c b/firmware/target/hosted/android/system-android.c
index 686453cfbb..fba7ff4e2c 100644
--- a/firmware/target/hosted/android/system-android.c
+++ b/firmware/target/hosted/android/system-android.c
@@ -20,6 +20,7 @@
****************************************************************************/
+#include <setjmp.h>
#include <jni.h>
#include "config.h"
#include "system.h"
@@ -37,10 +38,17 @@ uintptr_t *stackend;
extern int main(void);
extern void telephony_init_device(void);
+extern void pcm_shutdown(void);
void system_exception_wait(void) { }
void system_reboot(void) { }
-void power_off(void) { }
+
+/* this is used to return from the entry point of the native library. */
+static jmp_buf poweroff_buf;
+void shutdown_hw(void)
+{
+ longjmp(poweroff_buf, 1);
+}
void system_init(void)
{
@@ -75,10 +83,18 @@ Java_org_rockbox_RockboxService_main(JNIEnv *env, jobject this)
volatile uintptr_t stack = 0;
stackbegin = stackend = (uintptr_t*) &stack;
- env_ptr = env;
+ /* setup a jmp_buf to come back later in case of exit */
+ if (setjmp(poweroff_buf) == 0)
+ {
+ env_ptr = env;
+
+ RockboxService_instance = this;
+ RockboxService_class = (*env)->GetObjectClass(env, this);
- RockboxService_instance = this;
- RockboxService_class = (*env)->GetObjectClass(env, this);
+ main();
+ }
- main();
+ pcm_shutdown();
+ /* simply return here. this will allow the VM to clean up objects and do
+ * garbage collection */
}