Search code examples
pythonandroidadbtouch

adb shell input touchscreen tap is not working


I am trying to simulate tap and swipe gesture from adb to my android device. I've tried to run the following command adb shell input tap 500 500 and adb shell input touchscreen tap 500 500 from windows command prompt. It is giving me the following error,

    java.lang.SecurityException: Injecting to another application requires INJECT_EVENTS permission
        at android.os.Parcel.createException(Parcel.java:2074)
        at android.os.Parcel.readException(Parcel.java:2042)
        at android.os.Parcel.readException(Parcel.java:1990)
        at android.hardware.input.IInputManager$Stub$Proxy.injectInputEvent(IInputManager.java:925)
        at android.hardware.input.InputManager.injectInputEvent(InputManager.java:886)
        at com.android.commands.input.Input.injectMotionEvent(Input.java:428)
        at com.android.commands.input.Input.access$200(Input.java:41)
        at com.android.commands.input.Input$InputTap.sendTap(Input.java:224)
        at com.android.commands.input.Input$InputTap.run(Input.java:218)
        at com.android.commands.input.Input.onRun(Input.java:108)
        at com.android.internal.os.BaseCommand.run(BaseCommand.java:56)
        at com.android.commands.input.Input.main(Input.java:71)
        at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
        at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:380)
Caused by: android.os.RemoteException: Remote stack trace:
        at com.android.server.input.InputManagerService.injectInputEventInternal(InputManagerService.java:732)
        at com.android.server.input.InputManagerService.injectInputEvent(InputManagerService.java:706)
        at android.hardware.input.IInputManager$Stub.onTransact(IInputManager.java:422)
        at android.os.Binder.execTransactInternal(Binder.java:1021)
        at android.os.Binder.execTransact(Binder.java:994)

I've also tried to execute the same command from python script with the pure-python-adb package. The following is script I've exucted.

from ppadb.client import Client


adb = Client()
devices = adb.devices()
if len(devices) == 0:
    print("No devices attached")
    quit()
device = devices[0]
print(device)
device.shell('input touchscreen tap 700 1453')

I got the following output with no tap noticed on device and no error from the script.

<ppadb.device.Device object at 0x02B30E50>

Am I missing anything (Might be in developer's option setting for android)?

I am on windows 10 machine with adb version 1.0.41. And using an android device with Android 10 (Android Q) over a usb.


Solution

  • Look for a "USB debugging (Security Settings)" or something similar in your developer options in the debugging section -- This is where you grant ADB special permissions and allow input.

    Best of luck; I hope you find it.