How to add new key to Android from kernel to Android framework and Android Application Test

Source: Internet
Author: User

How to add new key to Android from kernel to Android framework and Android Application Test

Kernel layer:

1: We use kernel matrix-keypad to register 3*3 key

# Ifdef config_keyboard_matrix
/* Gpio matrix keyboard */
Static const uint32_t 89c64xx_matrix_keys [] = {
Key (0, 0, key_p1 ),
Key (0, 1, key_left ),
Key (0, 2, key_up ),

Key (1, 0, key_p2 ),
Key (1, 1, key_enter ),
Key (1, 2, key_right ),

Key (2, 0, key_frontdoor ),
Key (2, 1, key_down ),
Key (2, 2, key_start ),
};

Const struct matrix_keymap_data initi64xx_keymap_data = {
. Keymap = maid,
. Keymap_size = array_size (89c64xx_matrix_keys ),
};

/* Row key
Gpn0, gpn1, gpn2
Input --> extern interrupt
*/

Static const unsigned int initi64xx_keypad_row_gpios [] = {
144,145,146
};

/* Col key: gpn3, gpn6, gpn7 */
Static const unsigned int initi64xx_keypad_col_gpios [] = {
147,150,151
};

Static struct matrix_keypad_platform_data initi64xx_keypad_platform_data = {
. Keymap_data = & courseware 64xx_keymap_data,
. Row_gpios = 89c64xx_keypad_row_gpios,
. Num_row_gpios = array_size (89c64xx_keypad_row_gpios ),
. Col_gpios = 89c64xx_keypad_col_gpios,
. Num_col_gpios = array_size (89c64xx_keypad_col_gpios ),
. Active_low = 1,

. Debounce_ms = 20,
. Col_scan_delay_us = 5,
};

Static struct platform_device initi64xx_matrix_keyboard = {
. Name = "Matrix-keypad ",
. ID =-1,
. Dev = {
. Platform_data = & 89c64xx_keypad_platform_data,
},
};

Static struct platform_device * smdk6410_devices [] _ initdata = {
# Ifdef config_keyboard_matrix
& Amp; cloud64xx_matrix_keyboard,
# Endif
};

2: We add new defition of key_p1, key_p2, key_frontdoor, key_start in Linux/include/Linux/input. h
/* Jiujin. Hong 2011/1011
# Define key_p1 247
# Define key_p2 248
# Define key_frontdoor 249
# Define key_start 250
/* End */

3: We make menuconfig to support matrix keyboard arch to register into Kernel Input subsystem

Android framework layer:

1:

++/Project/sec_android/eclair/android2.1/smdk6410/Android/frameworks/base/include/UI/keycodelabels. h 11:23:23. 326802179 + 0800
@-114,12 + 114,6 @@
{"Media_rewind", 89 },
{"Media_fast_forward", 90 },
{"Mute", 91 },
-// Jiujin. Hong 2011/10/12, 3*3 key new key
-{"P1", 92 },
-{"P2", 93 },
-{"Frontdoor", 94 },
-{"Start", 95 },
-//

// Note: if you add a new keycode here you must also add it:
// (Enum keycode, in this file)
@-224,13 + 218,7 @@
Kkeycodepreviussong = 88,
Kkeycoderewind = 89,
Kkeycodeforward = 90,
-Kkeycodemute = 91,
-// Jiujin. Hong 2011/1012, 3*3 key
-Kkeycodep1 = 92,
-Kkeycodep2 = 93,
-Kkeycodefrontdoor = 94,
-Kkeycodestart = 95
-// End
+ Kkeycodemute = 91
} Keycode;

2:

--- Frameworks/base/CORE/Java/Android/View/keyevent. Java 2011-10-14 16:29:55. 480750044 + 0800
++/Project/sec_android/eclair/android2.1/smdk6410/Android/frameworks/base/CORE/Java/Android/View/keyevent. Java 11:23:14. 279382459 + 0800
@-120,12 + 120,6 @@
Public static final int keycode_media_rewind = 89;
Public static final int keycode_media_fast_forward = 90;
Public static final int keycode_mute = 91;
-// Jiujin. Hong 2011/10/12 3*3 new key exhibiton
-Public static final int keycode_p1 = 92;
-Public static final int keycode_p2 = 93;
-Public static final int keycode_frontdoor = 94;
-Public static final int keycode_start = 95;
-//
 
// Note: if you add a new keycode here you must also add it:
// Issystem ()
@-141,9 + 135,7 @@
// Those new codes. This is intended to maintain a consistent
// Set of key code definitions each SS all Android devices.

-// Private Static final int last_keycode = keycode_mute;
-// Jiujin. Hong 2011/10/12 3*3 key Exhibition
-Private Static final int last_keycode = keycode_start;
+ Private Static final int last_keycode = keycode_mute;

/**
* @ Deprecated there are now more than max_keycode keycodes.
@-700,12 + 692,6 @@
Case keycode_camera:
Case keycode_focus:
Case keycode_search:
-// Jiujin. Hong 2011/10/12 3*3 key new key
-Case keycode_p1:
-Case keycode_p2:
-Case keycode_frontdoor:
-Case keycode_start:
-// End
Return true;
Default:
Return false;

3:
--- Frameworks/base/CORE/RES/values/attrs. xml 2011-10-14 16:29:19. 448748629 + 0800
++/Project/sec_android/eclair/android2.1 _ 6410/smdk6410/Android/frameworks/base/CORE/RES/values/attrs. xml 11:23:16. 606738864 + 0800
@-912,12 + 912,6 @@
<Enum name = "keycode_media_rewind" value = "89"/>
<Enum name = "keycode_media_fast_forward" value = "90"/>
<Enum name = "keycode_mute" value = "91"/>
-<! -- Jiujin. Hong 2011/1012 3*3 key new key -->
-<Enum name = "keycode_p1" value = "92"/>
-<Enum name = "keycode_p2" value = "93"/>
-<Enum name = "keycode_frontdoor" value = "94"/>
-<Enum name = "keycode_start" value = "95"/>
-<! -- End -->
</ATTR>
 
<! --*************************************** ************************** -->

4:

Qwerty. KL (not missing)

Key 247 p1
Key 248 p2
Key 249 frontdoor
Key 250 start

Android Application Test:

1: Android has setfocusable/request focus for view if you use onkeydown, so we need dispatch event

// Since we register new keycode map in frameworks/base/CORE/RES/values/attrs. xml
// So we use it to judge
// Keycode_p1 --- 92
// Keycode_p2 --- 93
// Keycode_frontdoor --- 94
// Keycode_start --- 95
@ Override
Public Boolean dispatchkeyevent (keyevent event ){
Int action = event. getaction ();
Int keycode = event. getkeycode ();
System. Out. println ("keycode --->" + keycode );
Switch (keycode ){

Case 92:
If (Action = keyevent. action_down ){
// Todo
System. Out. println ("p1 down ");
}
If (Action = keyevent. action_up ){
// Todo
System. Out. println ("p1 up ");
}
Return true;

Case 93:
If (Action = keyevent. action_down ){
// Todo
System. Out. println ("p2 down ");
}
If (Action = keyevent. action_up ){
// Todo
System. Out. println ("p2 up ");
}
Return true;

Case 94:
If (Action = keyevent. action_down ){
// Todo
System. Out. println ("frontdoor down ");
}
If (Action = keyevent. action_up ){
// Todo
System. Out. println ("frontdoor up ");
}
Return true;
Case 95:
If (Action = keyevent. action_down ){
// Todo
System. Out. println ("start down ");
}
If (Action = keyevent. action_up ){
// Todo
System. Out. println ("start up ");
}
Return true;
Default:
Return super. dispatchkeyevent (event );
}
}

// End

ADB logcat:

I/system. Out (1687): keycode ---> 92
I/system. Out (1687): P1 down
I/system. Out (1687): keycode ---> 92
I/system. Out (1687): P1 up

I/system. Out (1687): keycode ---> 92
I/system. Out (1687): P1 down
I/system. Out (1687): keycode ---> 92
I/system. Out (1687): P1 up
I/system. Out (1687): keycode ---> 92
I/system. Out (1687): P1 down
I/system. Out (1687): keycode ---> 92
I/system. Out (1687): P1 up
I/system. Out (1687): keycode ---> 92
I/system. Out (1687): P1 down
I/system. Out (1687): keycode ---> 92
I/system. Out (1687): P1 up

I/system. Out (1687): keycode ---> 93
I/system. Out (1687): P2 down
I/system. Out (1687): keycode ---> 93
I/system. Out (1687): P2 up
I/system. Out (1687): keycode ---> 93
I/system. Out (1687): P2 down
I/system. Out (1687): keycode ---> 93
I/system. Out (1687): P2 up
I/system. Out (1687): keycode ---> 93
I/system. Out (1687): P2 down
I/system. Out (1687): keycode ---> 93
I/system. Out (1687): P2 up
I/system. Out (1687): keycode ---> 93
I/system. Out (1687): P2 down
I/system. Out (1687): keycode ---> 93
I/system. Out (1687): P2 up
I/system. Out (1687): keycode ---> 93
I/system. Out (1687): P2 down
I/system. Out (1687): keycode ---> 93
I/system. Out (1687): P2 up
I/system. Out (1687): keycode ---> 93
I/system. Out (1687): P2 down
I/system. Out (1687): keycode ---> 93
I/system. Out (1687): P2 up
I/system. Out (1687): keycode ---> 93
I/system. Out (1687): P2 down
I/system. Out (1687): keycode ---> 93
I/system. Out (1687): P2 up

I/system. Out (1687): keycode ---> 94
I/system. Out (1687): frontdoor down
I/system. Out (1687): keycode ---> 94
I/system. Out (1687): frontdoor up
I/system. Out (1687): keycode ---> 94
I/system. Out (1687): frontdoor down
I/system. Out (1687): keycode ---> 94
I/system. Out (1687): frontdoor up
I/system. Out (1687): keycode ---> 94
I/system. Out (1687): frontdoor down
I/system. Out (1687): keycode ---> 94
I/system. Out (1687): frontdoor up
I/system. Out (1687): keycode ---> 94
I/system. Out (1687): frontdoor down
I/system. Out (1687): keycode ---> 94
I/system. Out (1687): frontdoor up
I/system. Out (1687): keycode ---> 94
I/system. Out (1687): frontdoor down
I/system. Out (1687): keycode ---> 94
I/system. Out (1687): frontdoor up

I/system. Out (1687): keycode ---> 95
I/system. Out (1687): start down
I/system. Out (1687): keycode ---> 95
I/system. Out (1687): Start Up
I/system. Out (1687): keycode ---> 95
I/system. Out (1687): start down
I/system. Out (1687): keycode ---> 95
I/system. Out (1687): Start Up
I/system. Out (1687): keycode ---> 95
I/system. Out (1687): start down
I/system. Out (1687): keycode ---> 95
I/system. Out (1687): Start Up
I/system. Out (1687): keycode ---> 95
I/system. Out (1687): start down
I/system. Out (1687): keycode ---> 95
I/system. Out (1687): Start Up
D/dalvikvm (1687): GC freed 9526 objects/375728 bytes in 66 Ms
I/system. Out (1687): keycode ---> 95
I/system. Out (1687): start down
I/system. Out (1687): keycode ---> 95
I/system. Out (1687): Start Up
I/system. Out (1687): keycode ---> 95
I/system. Out (1687): start down
I/system. Out (1687): keycode ---> 95
I/system. Out (1687): Start Up
I/system. Out (1687): keycode ---> 95
I/system. Out (1687): start down
I/system. Out (1687): keycode ---> 95
I/system. Out (1687): Start Up
I/system. Out (1687): keycode ---> 95
I/system. Out (1687): start down
I/system. Out (1687): keycode ---> 95
I/system. Out (1687): Start Up

Related Article

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.