android蓝牙键盘调试记录

来源:互联网 发布:中国人在西班牙 知乎 编辑:程序博客网 时间:2024/03/29 13:31
情况:
android平板已经可以和蓝牙键盘连接,并可以输入文本等,大部分按键可以正常响应。但有少数几个按键不响应,ESC、锁屏键、搜索键。


调试步骤:
1.打开键盘输入的调试信息,以便获取按键的扫描码:
frameworks/base/services/input/InputReader.cpp
#define DEBUG_RAW_EVENTS 1//0 修改为1,打开调试信息


在方法InputDevice::process()可以看到打印信息如下:
#if DEBUG_RAW_EVENTS        LOGD("Input event: device=%d type=0x%04x scancode=0x%04x "                "keycode=0x%04x value=0x%08x flags=0x%08x",                rawEvent->deviceId, rawEvent->type, rawEvent->scanCode, rawEvent->keyCode,                rawEvent->value, rawEvent->flags);#endif

 

2.编译系统源码,升级固件,连接好蓝牙键盘,点击ESC键,观察打印消息中scancode的值,可以得到对应的scancode为0x000000ac,即172,这样就得到了扫描码。


3.在adb shell中查看输入设备信息:
shell@android:/ $ cat /proc/bus/input/devices

其中有蓝牙键盘的信息:
I: Bus=0005 Vendor=05ac Product=0239 Version=0001N: Name="Bluetooth 3.0 Keyboard"...(略)

这里重点关注Vendor=05ac Product=0239,根据对应规则:
Vendor_<Vendor>_Product_<Product>.kl
应该在/system/usr/keylayout有文件Vendor_05ac_Product_0239.kl,
查看一下,的确有这个文件:
shell@android:/ $ ls /system/usr/keylayoutls /system/usr/keylayoutACCDET.klAVRCP.klGeneric.klVendor_045e_Product_028e.klVendor_046d_Product_c216.klVendor_046d_Product_c294.klVendor_046d_Product_c299.klVendor_046d_Product_c532.klVendor_054c_Product_0268.klVendor_05ac_Product_0239.klVendor_22b8_Product_093d.klmtk-kpd.klqwerty.kl
这里可以看到有很多输入设备的按键映射配置文件,其中Vendor_05ac_Product_0239.kl是蓝牙键盘的转换表。

4.因为要求将ESC响应为BACK键,所以,在Generic.kl中找到BACK键的定义:
shell@android:/ $ cat /system/usr/keylayout/Generic.kl | busybox grep BACKcat /system/usr/keylayout/Generic.kl | busybox grep "BACK "key 158   BACK              WAKE_DROPPED

5.先将文件Vendor_05ac_Product_0239.kl提取到电脑中:
e:\android\doc\bluetooth keyboard\keylayout>adb pull /system/usr/keylayoutpull: building file list...pull: /system/usr/keylayout/qwerty.kl -> ./qwerty.klpull: /system/usr/keylayout/mtk-kpd.kl -> ./mtk-kpd.klpull: /system/usr/keylayout/Vendor_22b8_Product_093d.kl -> ./Vendor_22b8_Product_093d.klpull: /system/usr/keylayout/Vendor_05ac_Product_0239.kl -> ./Vendor_05ac_Product_0239.klpull: /system/usr/keylayout/Vendor_054c_Product_0268.kl -> ./Vendor_054c_Product_0268.klpull: /system/usr/keylayout/Vendor_046d_Product_c532.kl -> ./Vendor_046d_Product_c532.klpull: /system/usr/keylayout/Vendor_046d_Product_c299.kl -> ./Vendor_046d_Product_c299.klpull: /system/usr/keylayout/Vendor_046d_Product_c294.kl -> ./Vendor_046d_Product_c294.klpull: /system/usr/keylayout/Vendor_046d_Product_c216.kl -> ./Vendor_046d_Product_c216.klpull: /system/usr/keylayout/Vendor_045e_Product_028e.kl -> ./Vendor_045e_Product_028e.klpull: /system/usr/keylayout/Generic.kl -> ./Generic.klpull: /system/usr/keylayout/AVRCP.kl -> ./AVRCP.klpull: /system/usr/keylayout/ACCDET.kl -> ./ACCDET.kl13 files pulled. 0 files skipped.262 KB/s (27925 bytes in 0.104s)

在Vendor_05ac_Product_0239.kl,增加一行即可:
key 172   BACK              WAKE_DROPPED

6.修改完成后重新挂载system分区为可读写,再文件push到机器中,重启机器,查看是否修改成功:
e:\android\doc\bluetooth keyboard\keylayout>adb remounte:\android\doc\bluetooth keyboard\keylayout>adb push Vendor_05ac_Product_0239.kl /system/usr/keylayout/e:\android\doc\bluetooth keyboard\keylayout>adb reboot


7.同样方法,添加好锁屏键、搜索键,并验证好了,就可以把修改添加到源码中,重新编译,升级固件验证:

frameworks/base/data/keyboards/Vendor_05ac_Product_0239.kl

验证后,不要忘记去掉调试信息。

原创粉丝点击