summaryrefslogtreecommitdiffstats
path: root/firmware
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2011-06-04 19:17:47 +0000
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2011-06-04 19:17:47 +0000
commit6c22be4a3db4ad72acf67f99059872e92d1931b4 (patch)
tree110956169d637cdda501a2dfb3f9097d89d09ad8 /firmware
parent304312dc2fe17d9cdec2cc03a5883eade62e661b (diff)
downloadrockbox-6c22be4a3db4ad72acf67f99059872e92d1931b4.tar.gz
rockbox-6c22be4a3db4ad72acf67f99059872e92d1931b4.zip
Android: implement headphone detection thus enabling pause on unplug (FS#12097).
Listen to headphone plug events. There are currently two glitches with this: - Android takes a while until it reports the unplug event, so there will be some delay until playback gets paused. This is an Android limitation. - Rockbox debounces headphone state changes for one second. Therefore playback will shortly be routed to the speaker on unplug until Rockbox does the actual pause. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29956 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r--firmware/export/config/android.h2
-rw-r--r--firmware/target/hosted/android/button-android.c28
2 files changed, 30 insertions, 0 deletions
diff --git a/firmware/export/config/android.h b/firmware/export/config/android.h
index 69a758d69b..41ecacfb9d 100644
--- a/firmware/export/config/android.h
+++ b/firmware/export/config/android.h
@@ -84,6 +84,8 @@
#define HAVE_SW_TONE_CONTROLS
+#define HAVE_HEADPHONE_DETECTION
+
/* Define current usage levels. */
#define CURRENT_NORMAL 88 /* 18 hours from a 1600 mAh battery */
#define CURRENT_BACKLIGHT 30 /* TBD */
diff --git a/firmware/target/hosted/android/button-android.c b/firmware/target/hosted/android/button-android.c
index 61d7256a11..dfc5bd0fb3 100644
--- a/firmware/target/hosted/android/button-android.c
+++ b/firmware/target/hosted/android/button-android.c
@@ -31,6 +31,10 @@
#include "powermgmt.h"
extern JNIEnv *env_ptr;
+extern jclass RockboxService_class;
+extern jobject RockboxService_instance;
+
+static jfieldID _headphone_state;
static int last_y, last_x;
static int last_btns;
@@ -110,6 +114,20 @@ Java_org_rockbox_RockboxFramebuffer_buttonHandler(JNIEnv*env, jclass class,
void button_init_device(void)
{
+ jmethodID initHeadphoneMonitor = (*env_ptr)->GetMethodID(env_ptr,
+ RockboxService_class,
+ "initHeadphoneMonitor",
+ "()V");
+ /* start the monitor */
+ (*env_ptr)->CallVoidMethod(env_ptr,
+ RockboxService_instance,
+ initHeadphoneMonitor);
+
+ /* cache the headphone state field id */
+ _headphone_state = (*env_ptr)->GetFieldID(env_ptr,
+ RockboxService_class,
+ "headphone_state",
+ "I");
}
int button_read_device(int *data)
@@ -127,3 +145,13 @@ int button_read_device(int *data)
return btn;
}
+
+
+/* Tell if anything is in the jack. */
+bool headphones_inserted(void)
+{
+ int state = (*env_ptr)->GetIntField(env_ptr, RockboxService_instance, _headphone_state);
+ /* 0 is disconnected, 1 and 2 are connected */
+ return (state == 0) ? false : true;
+}
+