summaryrefslogtreecommitdiff
path: root/firmware/target/hosted/android
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2011-07-19 23:44:56 +0000
committerThomas Martitz <kugel@rockbox.org>2011-07-19 23:44:56 +0000
commitb2f52477dfce620c11e1707e69d3a5f8cab5f6d7 (patch)
tree094d7a9ce51c684ebec417cdcd954f379b49dfa7 /firmware/target/hosted/android
parentb8bfa84d1bf74fcb133d7f5bbf49c39d38d9ed7d (diff)
downloadrockbox-b2f52477dfce620c11e1707e69d3a5f8cab5f6d7.zip
rockbox-b2f52477dfce620c11e1707e69d3a5f8cab5f6d7.tar.gz
rockbox-b2f52477dfce620c11e1707e69d3a5f8cab5f6d7.tar.bz2
rockbox-b2f52477dfce620c11e1707e69d3a5f8cab5f6d7.tar.xz
Android: Change headphone detection to call into native.
Making a JNI call from tick tasks is not permitted as the underlying thread is not attached to the Java VM. This is an error and crashes in the emulator (which has stricter JNI checks enabled by default). git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30173 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target/hosted/android')
-rw-r--r--firmware/target/hosted/android/button-android.c32
-rw-r--r--firmware/target/hosted/android/kernel-android.c8
2 files changed, 25 insertions, 15 deletions
diff --git a/firmware/target/hosted/android/button-android.c b/firmware/target/hosted/android/button-android.c
index c913a3d..6751eff 100644
--- a/firmware/target/hosted/android/button-android.c
+++ b/firmware/target/hosted/android/button-android.c
@@ -34,8 +34,6 @@ extern JNIEnv *env_ptr;
extern jclass RockboxService_class;
extern jobject RockboxService_instance;
-static jobject HeadphoneMonitor_instance;
-static jfieldID headphone_state;
static int last_y, last_x;
static int last_btns;
@@ -120,13 +118,9 @@ void button_init_device(void)
jmethodID constructor = e->GetMethodID(env_ptr, class,
"<init>",
"(Landroid/content/Context;)V");
- HeadphoneMonitor_instance = e->NewObject(env_ptr, class,
- constructor,
- RockboxService_instance);
- /* cache the battery level field id */
- headphone_state = (*env_ptr)->GetFieldID(env_ptr,
- class,
- "mHpState", "I");
+ e->NewObject(env_ptr, class,
+ constructor,
+ RockboxService_instance);
}
int button_read_device(int *data)
@@ -145,13 +139,23 @@ int button_read_device(int *data)
return btn;
}
-
-/* Tell if anything is in the jack. */
+static int hp_state;
+JNIEXPORT void JNICALL
+Java_org_rockbox_monitors_HeadphoneMonitor_postCallHungUp(JNIEnv *env,
+ jobject this,
+ jint state)
+{
+ (void)env; (void)this;
+ hp_state = state;
+}
+/* Tell if anything is in the jack.
+ *
+ * since this is called from the tick task, which isn't attached to
+ * the dalvik VM, it's not permitted to make JNI calls (therefore
+ * we need the above callback) */
bool headphones_inserted(void)
{
- int state = (*env_ptr)->GetIntField(env_ptr, HeadphoneMonitor_instance,
- headphone_state);
/* 0 is disconnected, 1 and 2 are connected */
- return (state == 0) ? false : true;
+ return (hp_state == 0) ? false : true;
}
diff --git a/firmware/target/hosted/android/kernel-android.c b/firmware/target/hosted/android/kernel-android.c
index 80ff88f..e352241 100644
--- a/firmware/target/hosted/android/kernel-android.c
+++ b/firmware/target/hosted/android/kernel-android.c
@@ -60,7 +60,13 @@ void interrupt(void)
}
/*
- * setup a hrtimer to send a signal to our process every tick */
+ * setup a hrtimer to send a signal to our process every tick
+ *
+ * WARNING: JNI calls are not permitted from tick tasks, as the
+ * underlying thread is not attached to the Java VM
+ *
+ * Can be possibly be attached if it really needs to be. but let's
+ * keep this leightweight */
void tick_start(unsigned int interval_in_ms)
{
int ret = 0;