Notification thread is started on IPC init and it can be scheduled
before main thread.
Fix following crash on HAL init:
pid: 3392, tid: 3492, name: droid.bluetooth >>> com.android.bluetooth <<<
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000028
eax 00000000 ebx ce047f64 ecx ce0405d0 edx f7763724
esi cdf3af00 edi f837fb90
xcs 00000023 xds 0000002b xes 0000002b xfs 00000000 xss 0000002b
eip ce042289 ebp cdf3a9f8 esp cdf3a9e0 flags 00010292
backtrace:
#00 pc 00003289 /system/lib/hw/bluetooth.default.so (bt_thread_associate+25)
#01 pc 000015f8 /system/lib/hw/bluetooth.default.so (notification_handler+40)
#02 pc 0000f804 /system/lib/libc.so (__thread_entry+276)
#03 pc 0002999d /system/lib/libc.so
#04 pc 00082ae7 /system/lib/libdvm.so (dvmThreadSelf()+39)
#05 pc 00010db9 /system/lib/libc.so (pthread_mutex_unlock+25)
Debug helpers really helps a lot when debugging on Android target. The
patch uses helper functions already defined for hal test tool so
we do not need to reimplement them.
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
Handle error response inside helper so that users don't expecting any
response don't need to provide dummy buffer only for error (which is
already return value of helper).
hal-ipc will provide functionality related to IPC initialization and
sockets handling (including upcoming callbacks thread).
This allow to remove code from bluetooth HAL not related to adapter.