Android4.1添加新的按键(3)

添加新的物理按键 DECT_REGISTER, DECT_PHONE
1.kl文件添加按键码映射,251,252 是 驱动上报上来的键值
key 251 DECT_REGISTER
key 252 DECT_PHONE
2.frameworks/base/include/androidfw/KeycodeLabels.h
 对KEYCODES,添加按键码
static const KeycodeLabel KEYCODES[] = {
...
 { "DECT_REGISTER",220},
 { "DECT_PHONE",221},
3.frameworks/base/core/res/res/values/attr.xml
<enum name="KEYCODE_DECT_REGISTER" value="220"/>
<enum name="KEYCODE_DECT_PHONE" value="221"/>
4.frameworks/native/include/android/keycode.h
enum {
    AKEYCODE_UNKNOWN         = 0,
    ....
    ....
添加
AKEYCODE_DECT_REGISTER   =220,
AKEYCODE_DECT_PHONE      =221,
5.frameworks/base/core/java/android/view/KeyEvent.java
添加
 public static final int KEYCODE_DECT_REGISTER=   220;
 public static final int KEYCODE_DECT_PHONE=221;
修改 LAST_KEYCODE  和 KEYCODE_SYMBOLIC_NAMES
private static final int LAST_KEYCODE           = KEYCODE_DECT_REGISTER;
// NOTE: If you add a new keycode here you must also add it to:
//  isSystem()
//  native/include/android/keycodes.h
//  frameworks/base/include/ui/KeycodeLabels.h
//  external/webkit/WebKit/android/plugins/ANPKeyCodes.h
//  frameworks/base/core/res/res/values/attrs.xml
//  emulator?
//  LAST_KEYCODE
//  KEYCODE_SYMBOLIC_NAMES
private static void populateKeycodeSymbolicNames() {
        SparseArray<String> names = KEYCODE_SYMBOLIC_NAMES;
        names.append(KEYCODE_UNKNOWN, "KEYCODE_UNKNOWN");
        ...
        ...
        names.append(KEYCODE_DECT_REGISTER, "KEYCODE_DECT_REGISTER");
        names.append(KEYCODE_DECT_PHONE, "KEYCODE_DECT_PHONE");
}
修改 isSystem(),追踪jni需要修改frameworks/base/lib/androidrw/input.cpp  KeyEvent::isSystemKey
bool KeyEvent::isSystemKey(int32_t keyCode) {
    switch (keyCode) {
        ....
        case AKEYCODE_DECT_REGISTER:
        case AKEYCODE_DECT_PHONE:
            return true;
    }   
    return false;
}
6.external/webkit/Source/WebKit/android/plugins/ANPKeyCodes.h
修改
   enum ANPKeyCodes {
    kUnknown_ANPKeyCode = 0,
   ...
   ...
   kDectRegister_ANPKeyCode=220,
   kDectPhone_ANPKeyCode=221,
}
以上修改完成后,可以在PhoneWindowManager 测试下这个两个键是否成功上报,如果上报成功,就可以在自己的应用中添加与这个按键相关的逻辑处理。



   
 


你可能感兴趣的:(Android4.1添加新的按键(3))