I have an Android service running in the background that receives Key input from the HAL layer. The service should execute DPAD movements UP/DOWN/RIGHT/LEFT/CENTER.
The DPAD directions can be caught but not consumed automatically by the app.
Meanwhile, if I try to inject the same key events using the adb shell input keyevent
it works inside the app, works in the sense of they are consumed and executed, if I inject DPAD Right, the focus goes to the right on the app screen.
What is the actual difference between my service injection to the keyevent and the ADB injection of keyevents? Am I missing any permissions?
Here is the code of my service:
private boolean sendKeyEvent(int keycode) {
boolean bResult = false;
InputManager im = InputManager.getInstance();
if (im == null) {
Log.e(TAG, "Input Manager not available.");
return false;
}
KeyEvent evDown = new KeyEvent(1, new Date().getTime(), android.view.KeyEvent.ACTION_DOWN, keycode, 1);
KeyEvent evUp = new KeyEvent(1, new Date().getTime(), android.view.KeyEvent.ACTION_UP, keycode, 1);
Log.d(TAG, "sending: keycode: " + keycode);
boolean retval = im.injectInputEvent(evDown, InputManager.INJECT_INPUT_EVENT_MODE_ASYNC);
Log.d(TAG, "injectedInputEvent down returned with: " + retval);
boolean retval2 = im.injectInputEvent(evUp, InputManager.INJECT_INPUT_EVENT_MODE_ASYNC);
Log.d(TAG, "injectedInputEvent up returned with: " + retval2);
return bResult = retval && retval2;
}
The service is actually built with the whole system image, so any permissions can be added.
Thanks.