Android Key Management (Framework)

There are some parts of the framework that are not yet entirely clear to me. I am well acquainted with the flow of the input event (Kernel -> Eventhub -> InputReader -> InputDispatcher -> ...).

Situation

(Requirements: the key entry handle without changing the Android Framework.) I want to handle key events coming from the device (keyboard / gamepad / controller / ...), but there are some requirements. Firstly, I do not want to change the Android platform. This means that I do not want to extend WindowManagerPolicy and its functions, such as interceptKeyBeforeDispatching , where the home key is processed. This will cause the key event to be sent to the application layer. The downside is that I have one more difficult requirement. Example: When I play Angry Birds and I press the GoToAlpha button on a connected input device, you need to run an Alpha application. Angry Birds has no idea which GoToAlpha button will not process / recognize it, and, for example, there will be no translation to launch my Alpha application.

Question

Is there a way to handle my (custom) key event after sending it, knowing that the application in the foreground cannot process the key?

My (unsuccessful) decisions

  • Create a service that will handle key events. This is not possible because an application like Angry Birds will not be tied to my service and the key event will not be caught on my service. If I am mistaken, provide additional information :).

  • Create an external library where I allow my applications to inherit their own ActivityBase. All key events and default behavior can be handled here. Downside, existing applications will not support my custom key events because they do not use the library.

  • Expanding the scope will be in my eyes the purest solution, but this will lead to non-compliance with my requirements.

Any help or helpful information would be appreciated.

Extra

If the first question can be resolved anyway .. I want to configure my Intent behind the GoToAlpha button. This means that by default the Alpha application will be launched, but after the user has configured it, the beta application will be launched from this point on .. Any thoughts?

thanks

+8
android key-events
source share
2 answers

Thanks for the comment of Victor.

Using InputMethodService will not provide me with enough freedom and functionality to solve my problems.

My decision / compromise

Within the Android Framework, there is a PhoneWindowManager that is responsible for handling InputEvents . WindowManagerService , which is launched by SystemServer , is the owner of this manager and creates an instance.

By creating my own custom WindowManager and letting it inherit from Android PhoneWindowManager , I don’t lose any functions by default, and this allows me to add my own implementation in this class. This leads to adding a new file to the framework and changing only one line in the Android Framework: WindowManagerService will not create PhoneWindowManager , but create CustomPhoneWindowManager (extends PhoneWindowManager).

If someone sees a better solution or has any specific thoughts about my agreement, feel free to comment. :)

+3
source share

I doubt that this is possible using the public API (Boy and Martijn pointed out security issues).

More than your best bids (if you don't want to tune Android), there will be

a) Try using InputMethodService (http://developer.android.com/reference/android/inputmethodservice/InputMethodService.html)

He does not give the control that you desire, but this may be enough for some needs.

b) Try to go through the entire stack (from the kernel to the application) and find some vulnerabilities to exploit.

It will definitely take a long time and does not guarantee to bear fruit.

0
source share

All Articles