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;
NULL,
get_protocol_mode_callback,
NULL,
- NULL,
+ get_report_callback,
virtual_unplug_callback
};
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");
/*
}
}
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;
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;
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);