android蓝牙键盘调试记录

  • Post author:
  • Post category:其他


情况:

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

主要观察scancode的值,编译系统源码,升级固件。

2.连接好蓝牙键盘,在adb shell中查看输入设备信息:

shell@android:/ $ cat /proc/bus/input/devices

其中有蓝牙键盘的信息:

I: Bus=0005 Vendor=05ac Product=0239 Version=0001
N: 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/keylayout
ls /system/usr/keylayout
ACCDET.kl
AVRCP.kl
Generic.kl
Vendor_045e_Product_028e.kl
Vendor_046d_Product_c216.kl
Vendor_046d_Product_c294.kl
Vendor_046d_Product_c299.kl
Vendor_046d_Product_c532.kl
Vendor_054c_Product_0268.kl
Vendor_05ac_Product_0239.kl
Vendor_22b8_Product_093d.kl
mtk-kpd.kl
qwerty.kl

这里可以看到有很多输入设备的按键映射配置文件,其中endor_05ac_Product_0239.kl是蓝牙键盘的转换表。

3.点击蓝牙键盘上,原来不响应的按键,比如ESC,可以观察到对应的scancode为0x000000ac,即172,这样就得到了扫描码。

4.因为要求将ESC响应为BACK键,所以,在Generic.kl中找到BACK键的定义:

shell@android:/ $ cat /system/usr/keylayout/Generic.kl | busybox grep BACK
cat /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/keylayout
pull: building file list...
pull: /system/usr/keylayout/qwerty.kl -> ./qwerty.kl
pull: /system/usr/keylayout/mtk-kpd.kl -> ./mtk-kpd.kl
pull: /system/usr/keylayout/Vendor_22b8_Product_093d.kl -> ./Vendor_22b8_Product_093d.kl
pull: /system/usr/keylayout/Vendor_05ac_Product_0239.kl -> ./Vendor_05ac_Product_0239.kl
pull: /system/usr/keylayout/Vendor_054c_Product_0268.kl -> ./Vendor_054c_Product_0268.kl
pull: /system/usr/keylayout/Vendor_046d_Product_c532.kl -> ./Vendor_046d_Product_c532.kl
pull: /system/usr/keylayout/Vendor_046d_Product_c299.kl -> ./Vendor_046d_Product_c299.kl
pull: /system/usr/keylayout/Vendor_046d_Product_c294.kl -> ./Vendor_046d_Product_c294.kl
pull: /system/usr/keylayout/Vendor_046d_Product_c216.kl -> ./Vendor_046d_Product_c216.kl
pull: /system/usr/keylayout/Vendor_045e_Product_028e.kl -> ./Vendor_045e_Product_028e.kl
pull: /system/usr/keylayout/Generic.kl -> ./Generic.kl
pull: /system/usr/keylayout/AVRCP.kl -> ./AVRCP.kl
pull: /system/usr/keylayout/ACCDET.kl -> ./ACCDET.kl
13 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 remount
e:\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

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



版权声明:本文为seableble原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。