Je souhaite injecter des événements tactiles dans l'appareil. J'utilise l'instrumentation pour cela. La méthode fonctionne bien sur Jelly Bean
, mais elle n'injecte pas et ne donne aucune erreur dans Lollipop
.Pourquoi la simulation d'événements tactiles dans Lollipop ne fonctionne pas
Lorsque j'ai cherché, j'ai trouvé que cela pouvait être dû à l'application de SELinux
qui empêche certaines actions d'être exécutées à des fins de sécurité. J'ai téléchargé SELinux Mode Changer
et mis SELinux
à permissive
, et je me suis assuré qu'il a été mis à permissive
en vérifiant son statut dans About phone
dans le settings
. Mon appareil est enraciné, et j'ai essayé avec su
et sans elle. Mais, vraiment, je ne sais pas quel est le problème.
Voici mon code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
View view = findViewById (R.id.face);
try {
Runtime.getRuntime().exec("supoliciy –live \"allow appdomain input_device dir (ioctl read getattr search open)\" \"allow appdomain input_device dir (ioctl read write getattr lock append open)\"");
//supoliciy –live "allow appdomain input_device dir (ioctl read getattr search open)" "allow appdomain input_device dir (ioctl read write getattr lock append open)"
// Runtime.getRuntime().exec("reboot");
// Runtime.getRuntime().exec("su -c reboot");
/*
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 }\"");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
String cmd = "/system/bin/input tap 100 200\n";
os.writeBytes(cmd);
os.writeBytes("exit\n");
os.flush();
os.close();
process.waitFor();
*/
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 }\"");
}
catch (IOException e) {
Toast toast = Toast.makeText(getApplicationContext(), "ERROR", Toast.LENGTH_LONG);
toast.show();
e.printStackTrace();
// Log.e(" ", e.getStackTrace().toString());
}
/*
used in cmd case only
catch (InterruptedException e){
Toast toast = Toast.makeText(getApplicationContext(), "ERROR 2", Toast.LENGTH_LONG);
toast.show();
}
*/
final Instrumentation m_Instrumentation = new Instrumentation();
final MotionEvent down = MotionEvent.obtain(SystemClock.uptimeMillis(),
SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN, 400, 600, 0);
down.setSource(InputDevice.SOURCE_TOUCHSCREEN);
final MotionEvent up = MotionEvent.obtain(SystemClock.uptimeMillis(),
SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, 400, 600, 0);
up.setSource(InputDevice.SOURCE_TOUCHSCREEN);
Thread t = new Thread(new Runnable() {
@Override
public void run() {
m_Instrumentation.sendPointerSync(down);
m_Instrumentation.sendPointerSync(up);
}
});
view.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Toast toast = Toast.makeText(getApplicationContext(), "View touched", Toast.LENGTH_LONG);
toast.show();
return false;
}
});
t.start();
}
@Override
public boolean onTouchEvent(MotionEvent event) {
Toast toast = Toast.makeText(getApplicationContext(), "View touched", Toast.LENGTH_LONG);
toast.show();
return true;
}
}
J'ai même essayé d'exécuter supoliciy
comme vous pouvez le voir dans le code ci-dessus, mais rien ne fonctionnait.
Comment puis-je résoudre ce problème?