デバイスにタッチ イベントを挿入したい。そのために楽器を使っています。このメソッドは でうまく機能しますがJelly Bean
、 では注入もエラーも発生しませんLollipop
。
SELinux
検索したところ、セキュリティ上の目的で一部のアクションが実行されないようにするための強制が原因である可能性があることがわかりました。をダウンロードSELinux Mode Changer
して に設定SELinux
し、 でステータスをpermissive
確認して に設定されていることを確認しました。私のデバイスはルート化されており、ルート化して試してみました。しかし、実際には何が問題なのかわかりません。permissive
About phone
settings
su
これが私のコードです:
@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;
}
}
supoliciy
上記のコードでわかるように実行しようとしましたが、何も機能しませんでした。
どうすればこの問題を解決できますか?