Loading android/app/jni/com_android_bluetooth_hid.cpp +36 −1 Original line number Diff line number Diff line Loading @@ -96,6 +96,40 @@ static void get_protocol_mode_callback(bt_bdaddr_t *bd_addr, bthh_status_t hh_st sCallbackEnv->DeleteLocalRef(addr); } static void get_report_callback(bt_bdaddr_t *bd_addr, bthh_status_t hh_status, uint8_t *rpt_data, int rpt_size) { jbyteArray addr; jbyteArray data; CHECK_CALLBACK_ENV if (hh_status != BTHH_OK) { ALOGE("BTHH Status is not OK!"); checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); return; } addr = sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t)); if (!addr) { ALOGE("Fail to new jbyteArray bd addr for get report callback"); checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); return; } data = sCallbackEnv->NewByteArray(rpt_size); if (!data) { ALOGE("Fail to new jbyteArray data for get report callback"); checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); sCallbackEnv->DeleteLocalRef(addr); return; } sCallbackEnv->SetByteArrayRegion(addr, 0, sizeof(bt_bdaddr_t), (jbyte *) bd_addr); sCallbackEnv->SetByteArrayRegion(data, 0, rpt_size, (jbyte *) rpt_data); sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onGetReport, addr, data, (jint) rpt_size); checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); sCallbackEnv->DeleteLocalRef(addr); sCallbackEnv->DeleteLocalRef(data); } static void virtual_unplug_callback(bt_bdaddr_t *bd_addr, bthh_status_t hh_status) { ALOGD("call to virtual_unplug_callback"); jbyteArray addr; Loading Loading @@ -136,7 +170,7 @@ static bthh_callbacks_t sBluetoothHidCallbacks = { NULL, get_protocol_mode_callback, NULL, NULL, get_report_callback, virtual_unplug_callback }; Loading @@ -149,6 +183,7 @@ static void classInitNative(JNIEnv* env, jclass clazz) { method_onConnectStateChanged = env->GetMethodID(clazz, "onConnectStateChanged", "([BI)V"); method_onGetProtocolMode = env->GetMethodID(clazz, "onGetProtocolMode", "([BI)V"); method_onGetReport = env->GetMethodID(clazz, "onGetReport", "([B[BI)V"); method_onVirtualUnplug = env->GetMethodID(clazz, "onVirtualUnplug", "([BI)V"); /* Loading android/app/src/com/android/bluetooth/hid/HidService.java +28 −0 Original line number Diff line number Diff line Loading @@ -240,6 +240,15 @@ public class HidService extends ProfileService { } } break; case MESSAGE_ON_GET_REPORT: { BluetoothDevice device = getDevice((byte[])msg.obj); Bundle data = msg.getData(); byte[] report = data.getByteArray(BluetoothInputDevice.EXTRA_REPORT); int bufferSize = data.getInt(BluetoothInputDevice.EXTRA_REPORT_BUFFER_SIZE); broadcastReport(device, report, bufferSize); } break; case MESSAGE_SET_REPORT: { BluetoothDevice device = (BluetoothDevice) msg.obj; Loading Loading @@ -545,6 +554,16 @@ public class HidService extends ProfileService { mHandler.sendMessage(msg); } private void onGetReport(byte[] address, byte[] report, int rpt_size) { Message msg = mHandler.obtainMessage(MESSAGE_ON_GET_REPORT); msg.obj = address; Bundle data = new Bundle(); data.putByteArray(BluetoothInputDevice.EXTRA_REPORT, report); data.putInt(BluetoothInputDevice.EXTRA_REPORT_BUFFER_SIZE, rpt_size); msg.setData(data); mHandler.sendMessage(msg); } private void onVirtualUnplug(byte[] address, int status) { Message msg = mHandler.obtainMessage(MESSAGE_ON_VIRTUAL_UNPLUG); msg.obj = address; Loading Loading @@ -593,6 +612,15 @@ public class HidService extends ProfileService { if (DBG) log("Protocol Mode (" + device + "): " + protocolMode); } private void broadcastReport(BluetoothDevice device, byte[] report, int rpt_size) { Intent intent = new Intent(BluetoothInputDevice.ACTION_REPORT); intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); intent.putExtra(BluetoothInputDevice.EXTRA_REPORT, report); intent.putExtra(BluetoothInputDevice.EXTRA_REPORT_BUFFER_SIZE, rpt_size); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); sendBroadcast(intent, BLUETOOTH_PERM); } private void broadcastVirtualUnplugStatus(BluetoothDevice device, int status) { Intent intent = new Intent(BluetoothInputDevice.ACTION_VIRTUAL_UNPLUG_STATUS); intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); Loading Loading
android/app/jni/com_android_bluetooth_hid.cpp +36 −1 Original line number Diff line number Diff line Loading @@ -96,6 +96,40 @@ static void get_protocol_mode_callback(bt_bdaddr_t *bd_addr, bthh_status_t hh_st sCallbackEnv->DeleteLocalRef(addr); } static void get_report_callback(bt_bdaddr_t *bd_addr, bthh_status_t hh_status, uint8_t *rpt_data, int rpt_size) { jbyteArray addr; jbyteArray data; CHECK_CALLBACK_ENV if (hh_status != BTHH_OK) { ALOGE("BTHH Status is not OK!"); checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); return; } addr = sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t)); if (!addr) { ALOGE("Fail to new jbyteArray bd addr for get report callback"); checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); return; } data = sCallbackEnv->NewByteArray(rpt_size); if (!data) { ALOGE("Fail to new jbyteArray data for get report callback"); checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); sCallbackEnv->DeleteLocalRef(addr); return; } sCallbackEnv->SetByteArrayRegion(addr, 0, sizeof(bt_bdaddr_t), (jbyte *) bd_addr); sCallbackEnv->SetByteArrayRegion(data, 0, rpt_size, (jbyte *) rpt_data); sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onGetReport, addr, data, (jint) rpt_size); checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__); sCallbackEnv->DeleteLocalRef(addr); sCallbackEnv->DeleteLocalRef(data); } static void virtual_unplug_callback(bt_bdaddr_t *bd_addr, bthh_status_t hh_status) { ALOGD("call to virtual_unplug_callback"); jbyteArray addr; Loading Loading @@ -136,7 +170,7 @@ static bthh_callbacks_t sBluetoothHidCallbacks = { NULL, get_protocol_mode_callback, NULL, NULL, get_report_callback, virtual_unplug_callback }; Loading @@ -149,6 +183,7 @@ static void classInitNative(JNIEnv* env, jclass clazz) { method_onConnectStateChanged = env->GetMethodID(clazz, "onConnectStateChanged", "([BI)V"); method_onGetProtocolMode = env->GetMethodID(clazz, "onGetProtocolMode", "([BI)V"); method_onGetReport = env->GetMethodID(clazz, "onGetReport", "([B[BI)V"); method_onVirtualUnplug = env->GetMethodID(clazz, "onVirtualUnplug", "([BI)V"); /* Loading
android/app/src/com/android/bluetooth/hid/HidService.java +28 −0 Original line number Diff line number Diff line Loading @@ -240,6 +240,15 @@ public class HidService extends ProfileService { } } break; case MESSAGE_ON_GET_REPORT: { BluetoothDevice device = getDevice((byte[])msg.obj); Bundle data = msg.getData(); byte[] report = data.getByteArray(BluetoothInputDevice.EXTRA_REPORT); int bufferSize = data.getInt(BluetoothInputDevice.EXTRA_REPORT_BUFFER_SIZE); broadcastReport(device, report, bufferSize); } break; case MESSAGE_SET_REPORT: { BluetoothDevice device = (BluetoothDevice) msg.obj; Loading Loading @@ -545,6 +554,16 @@ public class HidService extends ProfileService { mHandler.sendMessage(msg); } private void onGetReport(byte[] address, byte[] report, int rpt_size) { Message msg = mHandler.obtainMessage(MESSAGE_ON_GET_REPORT); msg.obj = address; Bundle data = new Bundle(); data.putByteArray(BluetoothInputDevice.EXTRA_REPORT, report); data.putInt(BluetoothInputDevice.EXTRA_REPORT_BUFFER_SIZE, rpt_size); msg.setData(data); mHandler.sendMessage(msg); } private void onVirtualUnplug(byte[] address, int status) { Message msg = mHandler.obtainMessage(MESSAGE_ON_VIRTUAL_UNPLUG); msg.obj = address; Loading Loading @@ -593,6 +612,15 @@ public class HidService extends ProfileService { if (DBG) log("Protocol Mode (" + device + "): " + protocolMode); } private void broadcastReport(BluetoothDevice device, byte[] report, int rpt_size) { Intent intent = new Intent(BluetoothInputDevice.ACTION_REPORT); intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); intent.putExtra(BluetoothInputDevice.EXTRA_REPORT, report); intent.putExtra(BluetoothInputDevice.EXTRA_REPORT_BUFFER_SIZE, rpt_size); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); sendBroadcast(intent, BLUETOOTH_PERM); } private void broadcastVirtualUnplugStatus(BluetoothDevice device, int status) { Intent intent = new Intent(BluetoothInputDevice.ACTION_VIRTUAL_UNPLUG_STATUS); intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); Loading