简体   繁体   English

在 python 中使用 sendevent 到 usb 由于 su 访问连接手机速度慢

[英]Using sendevent in python to usb connected phone slow due to su access

Using python ppadb to automate clicks.使用 python ppadb 自动点击。 Input tap worked fine but was slow, so I rooted my device (android 10, pixel 2) to use sendevent /dev/input/event#.输入点击工作正常但速度很慢,所以我将我的设备(android 10,像素 2)植根以使用 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)我使用 adb shell getevent 来监听触摸并找出我的设备的特定值(事件2,以及用于点击、坐标输入、提升的命令以及发送它们的 0 0 0)

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.从我一直在阅读的内容来看,这可能是由于 su 每次都打开一个新的 shell 实例。 I've attempted to send "su" by itself, but it invariably hangs.我试图自己发送“su”,但它总是挂起。 (I've tried \n and ~ as line closers). (我已经尝试过 \n 和 ~ 作为线路关闭器)。 When I manually send the code through cmd, "adb shell su" will hang, but if I type enter and paste the sendevent commands.当我通过 cmd 手动发送代码时,“adb shell su”将挂起,但如果我输入并粘贴 sendevent 命令。 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.另外,如果我在 cmd 中尝试“adb shell”,然后在下一行输入“su”,它会从 walleye:/$ 变为 walleye:/#,我也可以将 sendevents 粘贴在那里。 (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.我的下一个尝试是将 go 放入 ppadb 并查看 sockets 是如何处理的,但这对我来说有点过了。 I played around with it a bit but I couldn't get multiple commands sent through a single "su".我玩了一下,但我无法通过单个“su”发送多个命令。 I also tried to use the root function in ppadb.devices but got "RuntimeError: adbd cannot run as root in production builds".我还尝试在 ppadb.devices 中使用根 function 但得到“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?我见过的另一种可能性是重写 sendevent.c 文件,如这里的答案: Android sendevent is really slow - how to speed up it?

At this point since I'm not certain what's causing sendevent to be slow, I'm not certain how to proceed.在这一点上,由于我不确定是什么导致 sendevent 变慢,所以我不确定如何进行。

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".编辑:我能够使用 MagiskHide Props Config 来更改 prop 值,ro.adb.secure=0、ro.secure =0 和 ro.debuggable = 1。我仍然得到“adbd 无法在生产构建中以 root 身份运行”。 getprop ro.build.type returns "user". getprop ro.build.type 返回“用户”。

https://github.com/pcboy/adb-insecure-patcher looks promising, but I'm not sure how to use it. https://github.com/pcboy/adb-insecure-patcher看起来很有希望,但我不确定如何使用它。

Edit2: Opened the.sh in adb-insecure-patcher, looks like it does the same thing I did with MagiskHide Props. Edit2:在 adb-insecure-patcher 中打开了.sh,看起来它和我对 MagiskHide Props 所做的事情一样。 Currently looking more into how to rewrite sendevent.c目前正在研究如何重写 sendevent.c

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)基本上以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.此外,我想象的子进程已经预先安装,但如果不只是在命令行中键入pip install subprocess You should be good to go.你应该对 go 好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM