android 新增 key按键(framework层适配和调试)

android 新增 key按键(framework层适配和调试)

// 查看input设备用的是哪个kl文件
dumpsys input | grep kl -C 10

例如:
设备里的:/system/usr/keylayout/Generic.kl
对应的是代码里的:frameworks/base/data/keyboards/Generioc.kl

// 查看input设备支持报哪些key事件
getevent -p
getevent -lp
adb device 1: /dev/input/event1
  name:    "adc-keys"
  events:
    KEY(001): KEY_VOLUEDOWN  KEY_VOLUMEUP  KEY_BACK  KEY_HOMEPAGE
 
// 查看input上报的input事件
getevent -l
getevent 

sendevent命令模拟按下音量减键:
例如,通过getevent -lp查看到/dev/input/event1支持上报KEY_VOLUEDOWN 
0x72(十六进展) = 114(十进制)
adb shell sendevent /dev/input/event1 0001 0114 00000001 && \
adb shell sendevent /dev/input/event1 0000 0000 00000000 && \
adb shell sendevent /dev/input/event1 0001 0114 00000000 && \
adb shell sendevent /dev/input/event1 0000 0000 00000000

adb shell // 进入手机中
$ getevent
$ getevent -l
$ getevent -ilp

$ dumpsys input

$ input keyevent 3 // KeyEvent.KEYCODE_HOME
$ input keyevent KEYCODE_POWER


**新增按键MY_KEY1:**
Input模块的两个映射表
1,android中的两个按键映射表
kl文件映射表: 
用于从linux扫描码映射到根据按键功能命名的字符串标签。
frameworks/base/data/keyboards/xxx.kl
如:Generic.kl
...
key 113   VOLUME_MUTE
key 114   VOLUME_DOWN
key 115   VOLUME_UP
key 116   POWER
+ key 600   MY_KEY1
...
在手机的/system/usr/keylayout中

InputEventLabels.h中的KEYCODES[]映射表:
static const InputEventLabel KEYCODES[] = {
   ...
   DEFINE_KEYCODE(VOLUME_UP),
   DEFINE_KEYCODE(VOLUME_DOWN),
   DEFINE_KEYCODE(POWER),
   ...
+  DEFINE_KEYCODE(MY_KEY1),
   ...
}
用于字符串标签映射到Android Keycode

frameworks/native/include/android/keycodes.h
  ...
  AKEYCODE_VOLUME_UP       = 24,
  AKEYCODE_VOLUME_DOWN     = 25,
  AKEYCODE_POWER           = 26,
  ...
  AKEYCODE_SYSRQ           = 120,
+ AKEYCODE_MY_KEY1           = 300,
  ...


调试:
例如通过:getevent -lp 查看到/dev/input/eventX 上报600   MY_KEY1
adb shell sendevent /dev/input/eventX 0001 0600 00000001 && \
adb shell sendevent /dev/input/eventX 0000 0000 00000000 && \
adb shell sendevent /dev/input/eventX 0001 0600 00000000 && \
adb shell sendevent /dev/input/eventX 0000 0000 00000000

在PhoneWindowManager.java中
打开DEBUG_INPUT = true;
// 查看MY_KEY1是否上传到framework层,通过设置 ACTION_PASS_TO_USER 决定是否传达给APP层
adb logcat | grep -i -E "interceptKeyTi|interceptKeyTq"

linux inpu驱动adc-keys.c添加新增key的调试代码,验证framework层是否正常适配
例如:在设备树dtsi文件adc-keys添加
http://aospxref.com/kernel-android13-5.10-lts/xref/drivers/input/keyboard/adc-keys.c
http://aospxref.com/kernel-android13-5.10-lts/xref/arch/arm64/boot/dts/rockchip/rk3399-sapphire-excavator.dts


 	adc-keys {
 		compatible = "adc-keys";
 		io-channels = <&saradc 1>;
 		io-channel-names = "buttons";
 		keyup-threshold-microvolt = <1800000>;
 		poll-interval = <100>;
        ...
 		back {
 			label = "Back";
 			linux,code = <KEY_BACK>;
 			press-threshold-microvolt = <985000>;
 		};
 
+ 		my_key1 {
+ 			label = "my_key1";
+ 			linux,code = <600>;
+ 			press-threshold-microvolt = <1314000>;
+ 		};
 	};

你可能感兴趣的:(Android,Framework,android)