diff options
Diffstat (limited to 'firmware/target/hosted/android/button-android.c')
-rw-r--r-- | firmware/target/hosted/android/button-android.c | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/firmware/target/hosted/android/button-android.c b/firmware/target/hosted/android/button-android.c index c913a3d7f7..6751effd1b 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; | |||
34 | extern jclass RockboxService_class; | 34 | extern jclass RockboxService_class; |
35 | extern jobject RockboxService_instance; | 35 | extern jobject RockboxService_instance; |
36 | 36 | ||
37 | static jobject HeadphoneMonitor_instance; | ||
38 | static jfieldID headphone_state; | ||
39 | static int last_y, last_x; | 37 | static int last_y, last_x; |
40 | static int last_btns; | 38 | static int last_btns; |
41 | 39 | ||
@@ -120,13 +118,9 @@ void button_init_device(void) | |||
120 | jmethodID constructor = e->GetMethodID(env_ptr, class, | 118 | jmethodID constructor = e->GetMethodID(env_ptr, class, |
121 | "<init>", | 119 | "<init>", |
122 | "(Landroid/content/Context;)V"); | 120 | "(Landroid/content/Context;)V"); |
123 | HeadphoneMonitor_instance = e->NewObject(env_ptr, class, | 121 | e->NewObject(env_ptr, class, |
124 | constructor, | 122 | constructor, |
125 | RockboxService_instance); | 123 | RockboxService_instance); |
126 | /* cache the battery level field id */ | ||
127 | headphone_state = (*env_ptr)->GetFieldID(env_ptr, | ||
128 | class, | ||
129 | "mHpState", "I"); | ||
130 | } | 124 | } |
131 | 125 | ||
132 | int button_read_device(int *data) | 126 | int button_read_device(int *data) |
@@ -145,13 +139,23 @@ int button_read_device(int *data) | |||
145 | return btn; | 139 | return btn; |
146 | } | 140 | } |
147 | 141 | ||
148 | 142 | static int hp_state; | |
149 | /* Tell if anything is in the jack. */ | 143 | JNIEXPORT void JNICALL |
144 | Java_org_rockbox_monitors_HeadphoneMonitor_postCallHungUp(JNIEnv *env, | ||
145 | jobject this, | ||
146 | jint state) | ||
147 | { | ||
148 | (void)env; (void)this; | ||
149 | hp_state = state; | ||
150 | } | ||
151 | /* Tell if anything is in the jack. | ||
152 | * | ||
153 | * since this is called from the tick task, which isn't attached to | ||
154 | * the dalvik VM, it's not permitted to make JNI calls (therefore | ||
155 | * we need the above callback) */ | ||
150 | bool headphones_inserted(void) | 156 | bool headphones_inserted(void) |
151 | { | 157 | { |
152 | int state = (*env_ptr)->GetIntField(env_ptr, HeadphoneMonitor_instance, | ||
153 | headphone_state); | ||
154 | /* 0 is disconnected, 1 and 2 are connected */ | 158 | /* 0 is disconnected, 1 and 2 are connected */ |
155 | return (state == 0) ? false : true; | 159 | return (hp_state == 0) ? false : true; |
156 | } | 160 | } |
157 | 161 | ||