I want to send touch events throughout Android system. I'm sending events from a background service. My device is rooted and I've stored my app in /system/app.
I tried instrumentation and system/bin/input tab
, instrumentation didn't work outside the app, and the second one doesn't generate an error, but does nothing. I've tried injecting directly to /dev/input/event2, but I get no effect.
Here is the code:
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
Process process = Runtime.getRuntime().exec("su");//supolicy --live \"allow appdomain input_device dir { ioctl read getattr search open }\" \"allow appdomain input_device chr_file { ioctl read write getattr lock append open }\"");
Runtime.getRuntime().exec ("su chmod 666 /dev/input/event2");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
String cmd = "su /dev/input/event2 ABS_X "+ xPos + " ABS_Y "+ yPos+ "\n";
Runtime.getRuntime().exec(cmd);
}
catch (IOException e) {
e.printStackTrace();
}
}
});
t.start();
I used this website as a reference: https://yhcting.wordpress.com/2010/11/29/linux-writing-input-event-directly/, but I'm not sure if I'm applying it correctly. How can I inject events in /dev/input/event2?
Also, what is /dev/input/eventX? I always see it, but it's not clear whether it's an input node or it's just a general indication of the event node. Finally, how can I know to which event node (event1, event2, etc.) should I send the event?
EDIT: I tried su /dev/input/event2 ABS_X xPos ABS_Y yPos via adb shell I got a line saying: unknown username or uid, what does that mean?
Thanks.