Avtar Guleria Avtar Guleria - 1 month ago 9
Android Question

Android Key logger

Intro: I want to create a POC on Android Security which requires to identify if there is any KeyLogger running on Android device or not. And if it is running or installed on device then, disable it throughout my Android application.

Queries:

1.) Is this possible to create Android keyloggers which intercepts keyboard events and running in background as services?

2.) Is this possible to identify if any of the background process handelling keyboard events?

3.) Can I stop any other background service (not owned by me) by my application code?

Please help me with suitable links if you have.

Answer

After research for 1 whole day I reached at below conclusion.

Android does not allow you to intercepts default soft keyboard inputs from background services. The only way to intercepts these events are custom keyboards.

I have summarized it as follows:

In Android Key logging for keyboard events is not supported in background services. Some of the links are as follows:

Point 1: Google Android Developer

As soft input methods can use multiple and inventive ways of inputting text, there is no guarantee that any key press on a soft keyboard will generate a key event: this is left to the IME's discretion, and in fact sending such events is discouraged. You should never rely on receiving KeyEvents for any key on a soft input method. In particular, the default software keyboard will never send any key event to any application targetting Jelly Bean or later, and will only send events for some presses of the delete and return keys to applications targetting Ice Cream Sandwich or earlier.

http://developer.android.com/reference/android/view/KeyEvent.html

Android Jelly Bean is: 4.1 to 4.3.1 Android IceCream Sandwich: 4.0

Key presses on soft input methods are not required to trigger the methods in this listener, and are in fact discouraged to do so. The default android keyboard will not trigger these for any key to any application targetting Jelly Bean or later, and will only deliver it for some key presses to applications targetting Ice Cream Sandwich or earlier.

http://developer.android.com/reference/android/text/method/KeyListener.html

Point 2: Stack Overflow KeyEvents can only be handled by Activities as they are the interface to the user pressing the keys and only when they are in the foreground. Even Services that run in the background are not intended to react on user input.

Android - Listener for hard keys press at background

Is it possible to create an Android Service that listens for hardware key presses?

Point 3: Romain Guy Romain Guy (http://stackoverflow.com/users/298575/romain-guy) who works for Google also confirms it onKeyDown in a service? (Global Hot Keys)

Point 4: Some Other reference:

Google android-developers Group : https://groups.google.com/forum/#!topic/android-developers/o--GUWmqXdI

It can be done only by using Custom KeyBoard: get pressed key and throw another key in android

Please add your comments if you think that I have missed anything.

Comments