OSDN Git Service

android/hal: Associate thread to Java
authorAndrei Emeltchenko <andrei.emeltchenko@intel.com>
Fri, 25 Oct 2013 11:34:46 +0000 (14:34 +0300)
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Fri, 25 Oct 2013 13:08:04 +0000 (16:08 +0300)
Without thread assiciation callbacks are not received by Java.
They are blocked by JNI:
E/BluetoothServiceJni( 2844): Callback env check fail: env: 0x0, callback: 0x0
E/BluetoothServiceJni( 2844): Callback: 'adapter_state_change_callback' is not
called on the correct thread

android/hal-bluetooth.c
android/hal-ipc.c
android/hal.h

index 9c7fbea..894f5b5 100644 (file)
@@ -66,6 +66,18 @@ static void handle_adapter_props_changed(void *buf, uint16_t len)
        bt_hal_cbacks->adapter_properties_cb(ev->status, ev->num_props, props);
 }
 
+void bt_thread_associate(void)
+{
+       if (bt_hal_cbacks->thread_evt_cb)
+               bt_hal_cbacks->thread_evt_cb(ASSOCIATE_JVM);
+}
+
+void bt_thread_disassociate(void)
+{
+       if (bt_hal_cbacks->thread_evt_cb)
+               bt_hal_cbacks->thread_evt_cb(DISASSOCIATE_JVM);
+}
+
 /* will be called from notification thread context */
 void bt_notify_adapter(uint16_t opcode, void *buf, uint16_t len)
 {
index c7764ab..5723841 100644 (file)
@@ -67,6 +67,8 @@ static void *notification_handler(void *data)
        ssize_t ret;
        int fd;
 
+       bt_thread_associate();
+
        while (true) {
                memset(&msg, 0, sizeof(msg));
                memset(buf, 0, sizeof(buf));
@@ -133,6 +135,8 @@ static void *notification_handler(void *data)
        close(notif_sk);
        notif_sk = -1;
 
+       bt_thread_disassociate();
+
        DBG("exit");
 
        return NULL;
index ef9a107..5cd5cab 100644 (file)
@@ -27,3 +27,5 @@ btpan_interface_t *bt_get_pan_interface(void);
 btav_interface_t *bt_get_av_interface(void);
 
 void bt_notify_adapter(uint16_t opcode, void *buf, uint16_t len);
+void bt_thread_associate(void);
+void bt_thread_disassociate(void);