轉載請注明出處:https://www.cnblogs.com/lialong1st/p/10071557.html
CPU:RK3288
系統:Android 5.1
1、在 dts 中增加紅外遙控器鍵值(點播按鍵),注意文件中加載的 input.h 頭文件路徑。
#include <dt-bindings/input/input.h>
diff --git a/kernel/arch/arm/boot/dts/rk3288-tb_8846.dts b/kernel/arch/arm/boot/dts/rk3288-tb_8846.dts index ba9b8f7..0f1a5a4 100755 --- a/kernel/arch/arm/boot/dts/rk3288-tb_8846.dts +++ b/kernel/arch/arm/boot/dts/rk3288-tb_8846.dts @@ -728,7 +728,7 @@ clock-frequency = <50000000>; <0xeb KEY_DOT>, // . <0xe3 KEY_DELETE>, // Del + <0xec KEY_VOD>, // Vod <0xa6 KEY_PAUSE>, // Pause <0xaa KEY_PLAY>; // Play
2、在內核頭文件 input.h 中增加按鍵定義,不能重復,input.h 路徑要與第一步 dts 文件中頭文件加載的一致。
diff --git a/kernel/include/dt-bindings/input/input.h b/kernel/include/dt-bindings/input/input.h index 2b1990d..b49dc4d 100755 --- a/kernel/include/dt-bindings/input/input.h +++ b/kernel/include/dt-bindings/input/input.h @@ -619,6 +619,8 @@ #define BTN_TRIGGER_HAPPY39 0x2e6 #define BTN_TRIGGER_HAPPY40 0x2e7 +#define KEY_VOD 0x2f0 + /* We avoid low common keys in module aliases so they don't get huge. */ #define KEY_MIN_INTERESTING KEY_MUTE #define KEY_MAX 0x2ff
3、增加鍵值與上層對應的關系。
diff --git a/device/rockchip/common/ff680000_pwm.kl b/device/rockchip/common/ff680000_pwm.kl index fb4cae7..eed2df8 100755 --- a/device/rockchip/common/ff680000_pwm.kl +++ b/device/rockchip/common/ff680000_pwm.kl @@ -35,6 +35,8 @@ key 111 DEL key 119 MEDIA_PAUSE key 207 MEDIA_PLAY +key 752 VOD + #key 400 TV_MEDIA_MULT_BACKWARD #key 401 TV_MEDIA_MULT_FORWARD #key 402 TV_MEDIA_PLAY_PAUSE
4、在 KeyEvent.java 中定義按鍵上層的鍵值,定義按鍵值后面有提示,新按鍵需要更新哪些地方。
public static final int KEYCODE_VOD = 275; private static final int LAST_KEYCODE = KEYCODE_VOD; // NOTE: If you add a new keycode here you must also add it to: // isSystem() // isWakeKey() // frameworks/native/include/android/keycodes.h // frameworks/native/include/input/InputEventLabels.h // frameworks/base/core/res/res/values/attrs.xml // emulator? // LAST_KEYCODE
在當前文件中定義鍵值,修改最后面的鍵值、isSystem 和 isWakeKey 兩個方法。
diff --git a/frameworks/base/core/java/android/view/KeyEvent.java b/frameworks/base/core/java/android/view/KeyEvent.java index bcf9a46..45f6ffb 100755 --- a/frameworks/base/core/java/android/view/KeyEvent.java +++ b/frameworks/base/core/java/android/view/KeyEvent.java @@ -773,7 +773,9 @@ public class KeyEvent extends InputEvent implements Parcelable { public static final int KEYCODE_TV_MEDIA_PAUSE = 274; //$_rbox_$_modify_$ end - private static final int LAST_KEYCODE = KEYCODE_TV_MEDIA_PAUSE; + public static final int KEYCODE_VOD = 275; + + private static final int LAST_KEYCODE = KEYCODE_VOD; // NOTE: If you add a new keycode here you must also add it to: // isSystem() @@ -1818,6 +1820,7 @@ public class KeyEvent extends InputEvent implements Parcelable { case KeyEvent.KEYCODE_BRIGHTNESS_DOWN: case KeyEvent.KEYCODE_BRIGHTNESS_UP: case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: + case KeyEvent.KEYCODE_VOD: return true; } @@ -1833,6 +1836,7 @@ public class KeyEvent extends InputEvent implements Parcelable { case KeyEvent.KEYCODE_WAKEUP: case KeyEvent.KEYCODE_PAIRING: case KeyEvent.KEYCODE_NOTIFICATION: + case KeyEvent.KEYCODE_VOD: return true; }
5、在 keycodes.h 文件中定義鍵值
diff --git a/frameworks/native/include/android/keycodes.h b/frameworks/native/include/android/keycodes.h index ff998df..212fef6 100755 --- a/frameworks/native/include/android/keycodes.h +++ b/frameworks/native/include/android/keycodes.h @@ -307,6 +307,7 @@ enum { AKEYCODE_TV_KEYMOUSE_UP = 262, AKEYCODE_TV_KEYMOUSE_DOWN = 263, AKEYCODE_TV_KEYMOUSE_MODE_SWITCH = 264, + AKEYCODE_VOD = 275, AKEYCODE_HELP = 259 // NOTE: If you add a new keycode here you must also add it to several other files.
6、在 InputEventLabels.h 中添加按鍵標簽
diff --git a/frameworks/native/include/input/InputEventLabels.h b/frameworks/native/include/input/InputEventLabels.h index d7a06dd..4359e3f 100755 --- a/frameworks/native/include/input/InputEventLabels.h +++ b/frameworks/native/include/input/InputEventLabels.h @@ -304,6 +304,7 @@ static const InputEventLabel KEYCODES[] = { DEFINE_KEYCODE(TV_KEYMOUSE_DOWN), DEFINE_KEYCODE(TV_KEYMOUSE_MODE_SWITCH), DEFINE_KEYCODE(HELP), + DEFINE_KEYCODE(VOD), { NULL, 0 } };
7、在 attrs.xml 中增加按鍵
diff --git a/frameworks/base/core/res/res/values/attrs.xml b/frameworks/base/core/res/res/values/attrs.xml index 75157be..e591fce 100755 --- a/frameworks/base/core/res/res/values/attrs.xml +++ b/frameworks/base/core/res/res/values/attrs.xml @@ -1791,6 +1791,7 @@ <enum name="KEYCODE_TV_MEDIA_MULT_BACKWARD" value="272" /> <enum name="KEYCODE_TV_MEDIA_PLAY" value="273" /> <enum name="KEYCODE_TV_MEDIA_PAUSE" value="274" /> + <enum name="KEYCODE_VOD" value="275" /> <!--$_rbox_$_modify_$_end--> </attr>
8、此時按鍵已經添加完畢,但是編譯會報錯如下,需要更新 api 文件,先執行指令 make update-api,再編譯。
****************************** You have tried to change the API from what has been previously approved. To make these errors go away, you have two choices: 1) You can add "@hide" javadoc comments to the methods, etc. listed in the errors above. 2) You can update current.txt by executing the following command: make update-api To submit the revised current.txt to the main Android repository, you will need approval. ******************************
9、編譯成功后,上層就可以接收到此鍵值,也可以通過 getevent 查看,但是看到的只是鍵值(02f0),沒有解析到實際含義。
$ adb shell root@rk3288:/ # getevent -rtl /dev/input/event0 getevent -rtl /dev/input/event0 [ 43.142191] EV_KEY 02f0 DOWN [ 43.142191] EV_SYN SYN_REPORT 00000000 [ 43.220034] EV_KEY 02f0 UP [ 43.220034] EV_SYN SYN_REPORT 00000000 rate 12
10、在 getevent.h 中添加此按鍵標簽
diff --git a/system/core/toolbox/getevent.h b/system/core/toolbox/getevent.h index 0482d04..785d4f4 100755 --- a/system/core/toolbox/getevent.h +++ b/system/core/toolbox/getevent.h @@ -537,6 +537,7 @@ static struct label key_labels[] = { LABEL(BTN_TRIGGER_HAPPY38), LABEL(BTN_TRIGGER_HAPPY39), LABEL(BTN_TRIGGER_HAPPY40), + LABEL(KEY_VOD), LABEL_END, };
11、上一步添加標簽后編譯會報錯,提示找不到 KEY_VOD,則需要在頭文件中定義。
diff --git a/bionic/libc/kernel/uapi/linux/input.h b/bionic/libc/kernel/uapi/linux/input.h index b9d5b2a..d7c99c3 100755 --- a/bionic/libc/kernel/uapi/linux/input.h +++ b/bionic/libc/kernel/uapi/linux/input.h @@ -787,6 +787,7 @@ struct input_keymap_entry { #define BTN_TRIGGER_HAPPY39 0x2e6 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ #define BTN_TRIGGER_HAPPY40 0x2e7 +#define KEY_VOD 0x2f0 #define KEY_MIN_INTERESTING KEY_MUTE #define KEY_MAX 0x2ff #define KEY_CNT (KEY_MAX+1)
此時,自定義按鍵添加大功告成,上層app可以接收到按鍵值,getevent 中也能解析此按鍵。
$ adb shell root@rk3288:/ # getevent -rtl /dev/input/event0 getevent -rtl /dev/input/event0 [ 138.898690] EV_KEY KEY_VOD DOWN [ 138.898690] EV_SYN SYN_REPORT 00000000 [ 138.980104] EV_KEY KEY_VOD UP [ 138.980104] EV_SYN SYN_REPORT 00000000 rate 12