Android uses event device for user input. There are three devices such as keypad, qwerty2 keyboard and mouse. The qwerty2 keyboard and mouse are normal devices. So I just explain the keypad and touchscreen which mouse device is replaced with.
On the Android shell, Cat the /proc/bus/input/{devices,handlers} and then you will see the devices used for the Android.
$ adb shell
# cat /proc/bus/input/devices
I: Bus=0000 Vendor=0000 Product=0000 Version=0000
N: Name="goldfish-events-keyboard"
P: Phys=
S: Sysfs=/class/inut/input0
U: Uniq=
H: Handlers=kbd mouse0 event0
...
#
# cat /proc/bus/input/handlers
N: Number=0 Name=kbd
N: Number=1 Name=mousedev Minor=32
N: Number=2 Name=evdev Minor=64
#
Qemu emulates goldfish-events-keyboard. It is a keypad using event device(/dev/input/event0). So you should know which key event and values come from the event device to activate Android applications. To do that, read event0 device with cat and redirect the output to a file. If you push and release the key button on emulator, the output values will be saved.
The output format is struct input_event. So the output on each event is 16 bytes like 8 bytes for time, 2 bytes for type, 2 bytes for code, 4 bytes for value. Read input.txt and input-programming.txt about input event devices in the Documentation/input directory of the Linux kernel source code.
struct input_event {
struct timeval time;
unsigned short type;
unsigned short code;
unsigned int value;
};
The Tiger7 evaluation board has it's own scancode table. The following shows the key layout on evaluation board, scancode table, and Android keycodes:
/*
* Key Layout Scancode Table
*
* 1 2 3 0x1 0x10 0x100
* 4 5 6 0x2 0x20 0x200
* 7 8 9 0x4 0x40 0x400
* * 0 # 0x8 0x80 0x800
*/
static unsigned short android_keycode[] = {
/*
* 0x66 0x67 0x9e Home Up Back
* 0x69 0xe8 0x6a Left Ok Right
* 0xe7 0x6c 0x6b Send Down Hangup
* 0xe5 Menu just_distinction_for_private
*/
KEY_HOME, KEY_UP, KEY_BACK,
KEY_LEFT, KEY_REPLY, KEY_RIGHT,
KEY_SEND, KEY_DOWN, KEY_END,
KEY_KBDILLUMDOWN, KEY_RESERVED, KEY_PLAY
};
There is a power button on emulator, but I skipped it to get output value.
If an interrupt of the keypad is caught, translate the scancode with the keycode of the Android on the above table and send event to user space application.
...
keycode = translate_keycode(scancode);
...
input_event(keydev->input, EV_KEY, keycode, KEY_PRESSED);
or
input_event(keydev->input, EV_KEY, keycode, KEY_RELEASED);
...
The high resolution timer - hrtimer is used for reduce keypad debounce.
If you have a touchscreen driver supporting the event interface for a pointing device, it'll work well. If you do not have it, you may implement it or use other pointing devices. Fortunately the evaluation board has already implemented touchscreen driver - drivers/input/touchscreen/tsc2007.c - which is made just before beginning to porting Android. Refer the drivers on drivers/input/touchscreen/ to implement your own driver and the text files on Documentation/input/.
Here is the output of the /proc/bus/input/{devices,handlers} on evaluation board.
# cat /proc/bus/input/devices
I: Bus=0000 Vendor=0000 Product=0000 Version=0000
N: Name="MVT7 KEYPAD"
P: Phys=
S: Sysfs=/class/input/input0
U: Uniq=
H: Handlers=kbd event0 evbug
B: EV=f
...
I: Bus=0000 Vendor=0000 Product=0000 Version=0000
N: Name="TSC2007 Touchscreen"
P: Phys=0-0090/input0
S: Sysfs=/class/input/input1
U: Uniq=
H: Handlers=event1 evbug
B: EV=b
B: KEY=400 0 0 0 0 0 0 0 0 0 0
B: ABS=1000003
# cat /proc/bus/input/handlers
N: Number=0 Name=kbd
N: Number=1 Name=evdev Minor=64
N: Number=2 Name=evbug
As a result, the keypad uses /dev/input/event0 and the touchscreen interface uses /dev/input/event1 on application layer.