Search code examples
androidtouchrootinstrumentation

How to perform instrumentation with elevated root permissions


I want to use Instrumentation to perform touch events outside my app. I've already given INJECT_EVENTS permission but it is not working. I searched for solutions and found: if I install my app as the system app (in system/app) the system will grant my app INJECT_EVENTS permission automatically.

My question is how to perform such elevated instrumentation operation using root privileges. What command should I use to execute this method?

instrumentationObj.sendPointerSync(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN, x, y, 0));

My app has a small floating window which is generating the touch events such as ACTION_DOWN, ACTION_UP at specific x and y coordinates.


Solution

  • I solved my problem using this answer.

    https://stackoverflow.com/a/32815010/9303062

    I used xposed frame work along with XInstaller to disable app signature checks and app verifications. This allowed my app to use INJECT_EVENTS permission.