三.应用(Settings.apk)
最后需要修改应用部分,应用部分的修改点比较分散,不想框架层那样整块模仿A2DP的样子那么方便,但也不是说jni部分有多么容易。反而对于我这种对C语言不熟悉的人来说,修改jni是最头疼得事了。好在蓝牙HID 这部分框架层的修改都是整块进行的,理解上还算比价容易。
总的来说在Settings.apk中要修改的文件主要是这么几个:
LocalBluetoothProfileManager.Java 这里主要提供一个HID的profile以便应用层访问。建一个HIDProfile的class调用framework中的BluetoothHID。实际上就是通过bender机制调用了BluetoothHidService。
CashedBluetoothDevice中添加显示蓝牙键盘的图标,BluetoothPairingDialog中则需要添加一段蓝牙配对验证处理的代码,我是参照i9000中先弹出一个随机数,然后在键盘中敲入相同的随机数即配对成功,具体实现如下:
- Private view createView(){
- if (mType == BluetoothDevice.PAIRING_VARIANT_PIN) {
- ……
- // HID
- if (isDeviceKeyboard(mDevice)) {
- String pin = String.format("%06d", Long.valueOf(Math
- .abs(new Random().nextLong() % 1000000L)));
- mPairingView.setVisibility(View.GONE);
- messageView.setText(getString(
- R.string.bluetooth_enter_keyboard_pin_msg, pin, name));
- byte[] bytePin = BluetoothDevice.convertPinToBytes(pin);
- if (bytePin != null) {
- mDevice.setPin(bytePin);
- }
- }
- ……
- }
