知方号

知方号

Android 13 (T) 增加P1物理按键实现开启和关闭虚拟键盘<安卓禁用物理按键>

Android 13 (T) 增加物理按键实现开启和关闭虚拟键盘 一 .增加物理按键P1

驱动已配置节点,直接上代码

1.system/frameworks/base/data/keyboards/Generic.kl

# key 175 "KEY_MOVE"# key 176 "KEY_EDIT"key 177 PAGE_UPkey 178 PAGE_DOWNkey 179 NUMPAD_LEFT_PARENkey 180 NUMPAD_RIGHT_PAREN# key 181 "KEY_NEW"# key 182 "KEY_REDO"# key 183 F13# key 184 F14 key 185 P1# key 186 F16# key 187 F17# key 188 F18# key 189 F19# key 190 F20# key 191 F21# key 192 F22# key 193 F23# key 194 F24# key 195 (undefined)

2.system/frameworks/base/data/keyboards/qwerty.kl

key 165 MEDIA_PREVIOUSkey 166 MEDIA_STOPkey 167 MEDIA_RECORDkey 168 MEDIA_REWINDkey 142 SLEEPkey 581 STEM_PRIMARYkey 582 STEM_1key 583 STEM_2key 584 STEM_3key 185 P1 system/frameworks/native/include/android/keycodes.h /** all apps */ AKEYCODE_ALL_APPS = 284, /** refresh key */ AKEYCODE_REFRESH = 285, /** Thumbs up key. Apps can use this to let user upvote content. */ AKEYCODE_THUMBS_UP = 286, /** Thumbs down key. Apps can use this to let user downvote content. */ AKEYCODE_THUMBS_DOWN = 287, /** Used to switch current account that is consuming content. * May be consumed by system to switch current viewer profile. */ AKEYCODE_PROFILE_SWITCH = 288, AKEYCODE_P1= 305 // add key P1 by ysliu 2023.8.16 // NOTE: If you add a new keycode here you must also add it to several other files. // Refer to frameworks/base/core/java/android/view/KeyEvent.java for the full list.};#ifdef __cplusplus}#endif

4.system/frameworks/native/libs/input/InputEventLabels.cpp

DEFINE_KEYCODE(COPY), DEFINE_KEYCODE(PASTE), DEFINE_KEYCODE(SYSTEM_NAVIGATION_UP), DEFINE_KEYCODE(SYSTEM_NAVIGATION_DOWN), DEFINE_KEYCODE(SYSTEM_NAVIGATION_LEFT), DEFINE_KEYCODE(SYSTEM_NAVIGATION_RIGHT), DEFINE_KEYCODE(ALL_APPS), DEFINE_KEYCODE(REFRESH), DEFINE_KEYCODE(THUMBS_UP), DEFINE_KEYCODE(THUMBS_DOWN), DEFINE_KEYCODE(PROFILE_SWITCH), DEFINE_KEYCODE(P1) //add key P1 by ysliu 2023.8.16// NOTE: If you add a new axis here you must also add it to several other files.// Refer to frameworks/base/core/java/android/view/MotionEvent.java for the full list.#define AXES_SEQUENCE DEFINE_AXIS(X), DEFINE_AXIS(Y), DEFINE_AXIS(PRESSURE), DEFINE_AXIS(SIZE), DEFINE_AXIS(TOUCH_MAJOR), DEFINE_AXIS(TOUCH_MINOR), system/frameworks/base/core/java/android/view/KeyEvent.java public static final int KEYCODE_DEMO_APP_1 = 301; /** Key code constant: Demo Application key #2. */ public static final int KEYCODE_DEMO_APP_2 = 302; /** Key code constant: Demo Application key #3. */ public static final int KEYCODE_DEMO_APP_3 = 303; /** Key code constant: Demo Application key #4. */ public static final int KEYCODE_DEMO_APP_4 = 304; //add key P1 by ysliu 2023.8.16 start public static final int KEYCODE_P1 = 305; //add key P1 by ysliu 2023.8.16 end /** * Integer value of the last KEYCODE. Increases as new keycodes are added to KeyEvent. * @hide */ @TestApi public static final int LAST_KEYCODE = KEYCODE_P1;//add key P1 by ysliu 2023.8.16 // 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

6.system/frameworks/base/core/res/res/values/attrs.xml

system/frameworks/base/core/api/current.txt field public static final int KEYCODE_NUMPAD_LEFT_PAREN = 162; // 0xa2 field public static final int KEYCODE_NUMPAD_MULTIPLY = 155; // 0x9b field public static final int KEYCODE_NUMPAD_RIGHT_PAREN = 163; // 0xa3 field public static final int KEYCODE_NUMPAD_SUBTRACT = 156; // 0x9c field public static final int KEYCODE_NUM_LOCK = 143; // 0x8f field public static final int KEYCODE_O = 43; // 0x2b field public static final int KEYCODE_P = 44; // 0x2c field public static final int KEYCODE_P1 = 305; // 0x131 field public static final int KEYCODE_PAGE_DOWN = 93; // 0x5d field public static final int KEYCODE_PAGE_UP = 92; // 0x5c field public static final int KEYCODE_PAIRING = 225; // 0xe1 field public static final int KEYCODE_PASTE = 279; // 0x117 system/frameworks/base/core/api/test-current.txt public final class InputDevice implements android.os.Parcelable { method @RequiresPermission("android.permission.DISABLE_INPUT_DEVICE") public void disable(); method @RequiresPermission("android.permission.DISABLE_INPUT_DEVICE") public void enable(); method @NonNull public android.hardware.input.InputDeviceIdentifier getIdentifier(); } public class KeyEvent extends android.view.InputEvent implements android.os.Parcelable { method public static String actionToString(int); method public final void setDisplayId(int); field public static final int FLAG_IS_ACCESSIBILITY_EVENT = 2048; // 0x800 field public static final int LAST_KEYCODE = 305; // 0x131 } public final class KeyboardShortcutGroup implements android.os.Parcelable { ctor public KeyboardShortcutGroup(@Nullable CharSequence, @NonNull java.util.List, boolean); ctor public KeyboardShortcutGroup(@Nullable CharSequence, boolean); method public boolean isSystemGroup(); } 二.按物理按键P1开启或者关闭软键盘

本来是想在PhoneWindowManager.java里的interceptKeyBeforeQueueing方法进行P1按键逻辑处理,但是PhoneWindowManager里无法获取到InputMethodManager服务,因为IMS服务启动比PWM晚,所以导致无法在PWM里实现通过IMS开启或者关闭软键盘。

最终在PhoneWindow的onKeyDown方法实现此功能。 system/frameworks/base/core/java/com/android/internal/policy/PhoneWindow.java

case KeyEvent.KEYCODE_BACK: { if (event.getRepeatCount() > 0) break; if (featureId

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至lizi9903@foxmail.com举报,一经查实,本站将立刻删除。