127|YT_r:/ # getevent -l
add device 1: /dev/input/event1
name: "goodix-ts"
add device 2: /dev/input/event2
name: "adc-keys"
add device 3: /dev/input/event0
name: "rk805 pwrkey"
/dev/input/event2: EV_KEY KEY_VOLUMEUP DOWN
/dev/input/event2: EV_SYN SYN_REPORT 00000000
/dev/input/event2: EV_KEY KEY_VOLUMEUP UP
/dev/input/event2: EV_SYN SYN_REPORT 00000000
实践:
--- a/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
+++ b/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
@@ -2732,7 +2732,15 @@ public class PhoneWindowManager implements WindowManagerPolicy {
@Override
public long interceptKeyBeforeDispatching(IBinder focusedToken, KeyEvent event,
int policyFlags) {
...
Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
+ repeatCount + " keyguardOn=" + keyguardOn + " canceled=" + canceled);
}
-
+ Log.d("tag","policyFlags:"+policyFlags);//长按也会产生不同的policyFlags
+ if(keyCode == KeyEvent.KEYCODE_VOLUME_UP && policyFlags == 1644167168){
+ //mContext.startActivity(new Intent(android.provider.Settings.ACTION_SETTINGS))//进入Settings app
+ DisplayHomeButtonHandler handler = mDisplayHomeButtonHandlers.get(displayId);
+ if (handler == null) {
+ handler = new DisplayHomeButtonHandler(displayId);
+ mDisplayHomeButtonHandlers.put(displayId, handler);
+ }
+ return handler.handleHomeButton(focusedToken, event);
+ }
//infrare simulate mouse
boolean isBox = "box".equals(SystemProperties.get("ro.target.product"));
if(isBox){
...
demo:
1.先获取按键对应的key
2.找到系统对应的 .kl 文件,修改按键的映射
3.在/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java 的
interceptKeyBeforeQueueing(KeyEvent event, int policyFlags)方法中做按键对应的逻辑。
原文链接:https://blog.csdn.net/qq_35611559/article/details/79915034
标签:java,policyFlags,dev,handler,音量,input,home,event2,替换
From: https://www.cnblogs.com/kato-T/p/18253081