Android4.2.2 auto-increment physical buttons (frameworks)

Source: Internet
Author: User

After frameworks is modified, the following error may occur:
Make: *** [out/target/common/obj/PACKAGING/checkapi-current-timestamp] Error 38
Solution: make update-api


Add a physical key in Android: KEYCODE_HELP
1. Add buttons for Android:
ScanCode-> KeyCodeLabel-> KeyCode-> Keyevent
-----
1) The key scan code ScanCode is an integer type defined by the linux Input driver framework. For details, see input. h header file (. /external/kernel-headers/original/linux/input. h ).
2) KeyCode, which is an integer. In the upper-layer JAVA program, this value is used to determine the system implementation.
----
Implementation process:
1. ScanCode-> KeyCodeLabel.
The keyboard layout file (*. kl) converts ScanCode to KeyCodeLabel. *. Kl files in the source code's devices folder such as/device/rockchip/rk30sdk_bnd/rk29-keypad.kl) or/system/usr/keylayout/*. kl in the device.
Key 138 HELP // here the HELP is the character form of the android key value we define, and 138 is the linux key value. HELP cannot be used for no reason and must have a defined position, this location is KeycodeLabels. h
2. KeyCodeLabel-> KeyCode.
Find the KEYCODES [] array to obtain the KeyCode value corresponding to the KeyCodeLabel string. KEYCODES [] is in the file/frameworks/base/include/androidfw/KeycodeLabels. h.
What we define here is actually the linux key value and the android key value name in the linux key-to-android key ing table in kl file, such as rk29-keypad.kl:
Static const KeycodeLabel KEYCODES [] = {
...
{"ASSIST", 219 },
// Add by hcm
{"HELP", 220 },
Define the enumerated values of KeyCode in/frameworks/native/include/android/keycodes. h.
Enum {
....
AKEYCODE_ASSIST = 219,
// Add by hcm
Akeycode_helper = 220,
......}
In EventHub. cpp load and parse this map: rk29-keypad.kl, then get the linux key value 138 for the key string, this string is HELP, with the above KEYCODES array, you can get the corresponding android key value.




3. KeyCode-> Keyevent.
Corresponding KeyCode in KeyEvent. java: (file path:/frameworks/base/core/java/android/view/KeyEvent. java ).
KeyEvent. java has a very important prompt, that is, we fill in the special button process, but I am the source code of ruixinwei 3168, Android4.2.2, and the comment path in the source code is incorrect! :
// NOTE: If you add a new keycode here you must also add it:
// IsSystem ()
// Native/include/android/keycodes. h
// Frameworks/base/include/ui/KeycodeLabels. h should be/frameworks/base/include/androidfw/KeycodeLabels. h
// External/webkit/WebKit/android/plugins/ANPKeyCodes. h
// Frameworks/base/core/res/values/attrs. xml
// Emulator?
// LAST_KEYCODE
// KEYCODE_SYMBOLIC_NAMES
//
// Also Android currently does not reserve code ranges for vendor-
// Specific key codes. If you have new key codes to have, you
// MUST contribute a patch to the open source project to define
// Those new codes. This is intended to maintain a consistent
// Set of key code definitions each SS all Android devices.
If the KeyEvent is changed and the API is affected, make update-api must be called.
LAST_KEYCODE modification:
/** Key code constant: add by hcm, help key .*/
Public static final int key code_help = 220;
Private static final int LAST_KEYCODE = KEYCODE_HELP;
....
(Modify KEYCODE_SYMBOLIC_NAMES)
Names. append (KEYCODE_ASSIST, "KEYCODE_ASSIST ");
Names. append (KEYCODE_HELP, "KEYCODE_HELP ");
....
4. Modify isSystem () according to the above prompt and trace the Code:
IsSystem () in/frameworks/base/core/java/android/view/KeyEvent. java
Public final boolean isSystem (){
Return native_isSystemKey (mKeyCode );
}

/Frameworks/base/core/jni/android_view_KeyEvent.cpp
Static jboolean native_isSystemKey (JNIEnv * env, jobject clazz, jint keyCode ){
Return KeyEvent: isSystemKey (keyCode );
}

/Frameworks/base/libs/androidfw/Input. cpp
Bool KeyEvent: isSystemKey (int32_t keyCode ){
Switch (keyCode ){
......
Case AKEYCODE_SEARCH:
// Add by hcm
Case AKEYCODE_HELP:
}
}
5./external/webkit/Source/WebKit/android/plugins/ANPKeyCodes. h
Enum ANPKeyCodes {
......

KAppSwitch_ANPKeyCode = 187,
// Add by hcm
Khelp_anpkeycode= 220,
};
6. frameworks/base/core/res/values/attrs. xml

.....................







After these operations are completed, the linux key-to-android key-value ing is completed. That is, the value of KEYCODE_HELP in android is 220.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.