E
E
elgordo2013-05-11 19:26:00
Android
elgordo, 2013-05-11 19:26:00

What is the mechanism for handling hardware keys in Android?

Good afternoon!
There is an Android box on the Cortex A9, of course rooted, used in CarPC with a USB mini-keyboard. Funk. the keys are assigned to the main actions of Android: switching to the home screen (HOME), player control, "settings", calling the notification area, etc., etc.
At some point after updating the firmware, the HOME button stopped working. I have configured hard keys via /system/usr/keylayout/
Sample content of aml-usbkbd.kl file:
key 1 BACK # ESC
key 59 MENU # F1 #
key 60 CAMERA # F2
key 61 NOTIFICATION # F3
key 62 HOME # F4
key 63 MEDIA_PREVIOUS # F5
key 64 HEADSETHOOK # PLAY/PAUSE F6
#key 65 INFO # F7
key 66 VOLUME_UP # F8
key 67 VOLUME_DOWN # F9
key 200 HEADSETHOOK #
key 68 MEDIA_NEXT # F10
key 87 POWER # F11 #
key 88 EMAIL # F12 I
tried to change the key codes among themselves: the keys themselves and their polling work, namely, the call to the HOME function does not work. The "factory" icon in the form of a house on top does not work either. But at the same time, the HOME button in Button Savior (emulator of hard buttons on the screen) works fine. Calling the home screen from SSH with am start -a android.intent.action.MAIN -c android.intent.category.HOME also works.
So far, I “solved” this problem by writing a batch .sh file that runs at startup, which polls devices via geteventand executes the desired command, however, this thing, firstly, is terribly slow, and secondly, it crashes after a while, because. it is killed by the android core.
How are these keys configured in general and where is the task they perform assigned? I would like to add a few more keys, for example, to call navigation, etc., etc. I've looked all over the internet and haven't found any information. Or maybe there is software that performs similar actions? As far as I understand, in Android it is impossible, like in Windows, to constantly read the keyboard with a program hanging in memory, but only the activity whose window is currently open - protection against keyloggers ...
Thank you.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
E
elgordo, 2013-05-12
@elgordo

Unexpectedly, a solution was found. Android has a settings database in SQLite3 format:
/data/data/com.android.providers.settings/databases/settings.db
This is something like a Windows registry. It must have the device_provisioned parameter , value 1 . In its absence, the effect of the HOME and SEARCH buttons not working is manifested.
To fix, we merge this file onto the computer and open it with an editor, I used SQLiteman. Execute the query:
INSERT INTO secure (name,value) VALUES ('device_provisioned','1');
Save, upload, reload. The HOME button, as well as the "house" icon on top, have earned. )) When saving, it is important to check that the file has remained in the SQLite3 format and that the permissions have not changed (I had 0660). Otherwise, you are waiting for a flashing. ))
In principle, the database can be edited locally, but the sqlite3 file was not found on my device.
I found the solution here:
forum.cyanogenmod.org/topic/19605-home-button-issues-striking-back/
I don't use Cyanogenmod, what explains all this, I have no idea. :)

C
constv, 2013-05-11
@constv

pair of links: one and two

E
elgordo, 2013-05-11
@elgordo

Well, this is the same method that I use now. Although, the articles are more about passing keycodes than reading.
Only I have it in a batch file and run via autostart.sh

while true  
do

s=$(getevent -v0 -c1)  # считываем одно событие из всех устройств ввода
s=$(echo $s | awk '{print $4}') #выделяем код клавиши

case $s in    # выполняем нужную команду

    0007003d) am start -a android.intent.action.MAIN -c android.intent.category.HOME
    sleep 1
    ;;

esac

done


As I wrote, firstly, it works slowly (sometimes it takes
several seconds from pressing a key to launching the application!), Secondly, the kernel successfully kills this process after a while.
I'm interested in where the native android handler for these events is located and how it works.

C
constv, 2013-05-12
@constv

response from Nfc666 from w3bsit3-dns.com:

You need to pick /system/framework/android.policy.jar, this is where the processing takes place.
Arm yourself with dex2jar, JDGUI, APKTools to decompile and analyze code.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question