2

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.

Viral Limbani
  • 110
  • 2
  • 6
  • Does this answer your question? [Android INJECT\_EVENTS permission](https://stackoverflow.com/questions/5383401/android-inject-events-permission) – tir38 Sep 22 '20 at 22:42
  • @tir38 The question you suggested address the problem with creating an android application and using touch events from that application to the device. However, my problem is that I'm not able to send the input touch events over an ADB. – Viral Limbani Sep 23 '20 at 05:15

2 Answers2

5

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.

Meer
  • 66
  • 1
  • 2
1

I tried this to tap a xy coordinate using adb command. Enabling the "USB debugging (Security Settings)" is worked for me. But the phone should connect to the internet inorder to enable the settings. Thanks @Meer