0

Using python ppadb to automate clicks. Input tap worked fine but was slow, so I rooted my device (android 10, pixel 2) to use sendevent /dev/input/event#. I used adb shell getevent to listen to touches and figure out the specific values for my device (event2, and the commands for tap down, coordinate input, lifting, and the 0 0 0 to send them)

import utils as u, random, time, sys, os

driver= u.Driver(id)

sendCmd = "su +c sendevent /dev/input/event2 "
driver.device.shell(sendCmd + "3 57 374")
driver.device.shell(sendCmd + "3 54 970")
driver.device.shell(sendCmd + "3 53 900")
driver.device.shell(sendCmd + "0 0 0")
driver.device.shell(sendCmd + "3 57 -1")
driver.device.shell(sendCmd + "0 0 0")

It worked, but was also fairly slow. From what I've been reading it might be due to su opening a new shell instance each time. I've attempted to send "su" by itself, but it invariably hangs. (I've tried \n and ~ as line closers). When I manually send the code through cmd, "adb shell su" will hang, but if I type enter and paste the sendevent commands. I can send clicks to the phone. Also, if I try "adb shell" in cmd, then on the next line enter "su", it changes from walleye:/ $ to walleye:/ #, and I can paste the sendevents in there as well. (These clicks are pretty fast if I paste multiple in at a time)

My next attempt was to go into ppadb and look at how the sockets were handled, but it's a bit past me. I played around with it a bit but I couldn't get multiple commands sent through a single "su". I also tried to use the root function in ppadb.devices but got "RuntimeError: adbd cannot run as root in production builds".

Another possibility I've seen is to re-writing the sendevent.c file, as in the answer here: Android sendevent is really slow - how to speed it up?

At this point since I'm not certain what's causing sendevent to be slow, I'm not certain how to proceed.

Edit: I was able to use MagiskHide Props Config to change the prop values, ro.adb.secure=0 , ro.secure =0 and ro.debuggable = 1. I still get "adbd cannot run as root in production builds". getprop ro.build.type returns "user".

https://github.com/pcboy/adb-insecure-patcher looks promising, but I'm not sure how to use it.

Edit2: Opened the .sh in adb-insecure-patcher, looks like it does the same thing I did with MagiskHide Props. Currently looking more into how to rewrite sendevent.c

1 Answers1

0

You don't need to do any of that. Just use subprocess:

import subprocess

#now you can send any adb command to device using:
subprocess.call("adb shell input tap 2300 1220", shell = True)
subprocess.call("adb shell input swipe 3847 1223 2341 1232", shell = True)
subprocess.call("adb shell monkey -p com.instagram.android -c android.intent.category.LAUNCHER 1",shell = True)

You get the idea. Basically send any command in the format subprocess.call("adb shell <your command here>", shell = True)

Also, subprocess I imagine is already pre-installed but if not just type pip install subprocess in your command line. You should be good to go.