openatx / adbutils Goto Github PK
View Code? Open in Web Editor NEWpure python adb library for google adb service.
License: MIT License
pure python adb library for google adb service.
License: MIT License
Dependabot couldn't authenticate with https://pypi.python.org/simple/.
You can provide authentication details in your Dependabot dashboard by clicking into the account menu (in the top right) and selecting 'Config variables'.
Hello, when I try to get a list of devices using the adb.device_list
command, my script freezes. With the help of debug mode, I realized that adbutils hangs in this function:
def iter_device(self):
"""
Returns:
iter of AdbDevice
"""
with self._connect() as c:
c.send("host:devices")
c.check_okay()
output = c.read_string()
for line in output.splitlines():
parts = line.strip().split("\t")
if len(parts) != 2:
continue
if parts[1] == 'device':
yield AdbDevice(self, parts[0])
But more specifically, then on this line c.check_okay()
What could be the problem?
d.sync.stat("/sdcard/none-exists-file")
Can the adb command simulate the enter key or search key? . such as
device.press.enter ()
device.press.search (), similar to uiautomator, can simulate a carriage return, search,
If so what is the adb command? Look forward to your answer
d.package_info('com.ksxx.forestmonitoring')
{'package_name': 'com.ksxx.forestmonitoring', 'version_name': '', 'version_code': '38', 'flags': ['HAS_CODE', 'ALLOW_CLEAR_USER_DATA', 'ALLOW_BACKUP'], 'first_install_time': datetime.datetime(2021, 6, 9, 18, 54, 13), 'last_update_time': datetime.datetime(2021, 6, 9, 18, 54, 13), 'signature': 'aed60245'}
aapt dump badging YueLinJianCe.apk
package: name='com.ksxx.forestmonitoring' versionCode='38' versionName='forest_1.7.7' compileSdkVersion='29' compileSdkVersionCodename='10'
Exception in thread Thread-2:
Traceback (most recent call last):
File "D:\Python36\lib\threading.py", line 916, in _bootstrap_inner
self.run()
File "D:\Python36\lib\threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "G:/MyPython/Studty/65-多媒体-图片操作/21 循环重启判断systemui Launcher是否正常显示.py", line 116, in install
device.install(apk_path=apk_loaction)
File "D:\Python36\lib\site-packages\adbutils\mixin.py", line 126, in install
self.install_remote(dst, clean=True)
File "D:\Python36\lib\site-packages\adbutils\mixin.py", line 144, in install_remote
raise AdbInstallError(output)
adbutils.errors.AdbInstallError: cmd: Failure calling service package: Broken pipe (32)
if we want to get current Activity,
we can get from by this shell command->dumpsys activity | grep -w ResumedActivity
but ,failed.
print(d.shell_output("dumpsys activity |grep -w ResumedActivity"))
/system/bin/sh: dumpsys activity |grep -w ResumedActivity: not found
example:
adb shell
W-P311:/ $ dumpsys activity |grep -w ResumedActivity
ResumedActivity: ActivityRecord{b11e81c u0 com.tencent.mobileqq/.activity.SplashActivity t12623}
W-P311:/ $
使用 PyInstaller 打包时未能将 binaries 文件夹内容打包到产物里,导致运行时出现 No adb exe could be found
错误。
不知道是否能提供一个初始化参数来指定一个自定义的 adb 可执行文件路径呢?
command "adb shell screencap -p > 1.png" can work in terminal,but can not work with d.shell("screencap -p > 1.png")...
And,d.shell("screencap -p /sdcard/1.png") works,BUT d.shell("pull /sdcard/1.png 1.png")
I would like to be able to send sensor data to the emulator. From command line I can use something like this to simulate, for example, a 1 second device shake:
adb emu sensor set acceleration 100:100:100; sleep 1; adb emu sensor set acceleration 0:0:0
It would be nice to be able to use adbutils
to send this emu
commands.
Some logs
[57480]: 001bhost:connect:102.2.2.3:4433
[ 5037]: OKAY
[ 5037]: 0023failed to connect to 102.2.2.3:4433
[proxy] ('127.0.0.1', 5037) has disconnected
[proxy] ('127.0.0.1', 57480) has disconnected, too
我的命令如下:
adb_device = adbutils.AdbClient(host=params.adbIP, port=params.adbPort).device()
adb_device.sync.push('本地的二进制文件', '设备的路径文件')
问题:
失败原因不知道
如果我推送,这样子貌似可以
adb_device.sync.push(b'本地的二进制文件内容', '设备的路径文件')
I have two or more devices connected to my computer, and I want to monitor a specific one. How can I achieve this? Can I use track_devices()?
thanks
So I was using Adbutils. However, I face an error while pushing a file onto an android:
OSError: [Errno subprocess] 'C:\Users\shiba\AppData\Local\Programs\Python\Python310\lib\site-packages\adbutils\binaries\adb.exe' -s N9XDU17207002827 push 'c:\Users\shiba\Documents\Mirror\src\scrcpy\scrcpy-server-v1.24.jar' /data/local/tmp/: 'The filename, directory name, or volume label syntax is incorrect.\r\n'
I first thought the files were just not there, but I'm fairly confident that the file exists.
Here is the code I'm running:
jar_name = "scrcpy-server-v1.24.jar"
server_file_path = os.path.join(
os.path.abspath(os.path.dirname(__file__)), jar_name
)
self.device.push(server_file_path, "/data/local/tmp/")
the device is connected, when run i get this, please help, thx :D
from adbutils import adb
out = adb.connect("127.0.0.1:62026")
d = adb.device()
return d.adb_output("screencap -p")
Traceback (most recent call last):
File "D:\App\Python\Python37-32\lib\site-packages\adbutils\__init__.py", line 312, in adb_output
return subprocess.check_output(cmdline, stderr=subprocess.STDOUT, shell=True).decode('utf-8')
File "D:\App\Python\Python37-32\lib\subprocess.py", line 395, in check_output
**kwargs).stdout
File "D:\App\Python\Python37-32\lib\subprocess.py", line 487, in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command 'D:\App\Android\SDK\platform-tools\adb.EXE -s 127.0.0.1:62026 "screencap -p"' returned non-zero exit status 1.
[57599]: 003ahost-serial:123.59.119.126:13020:forward:tcp:7912;tcp:4000
[ 5037]: OKAYOKAY
[57470]: 0011host:list-forward
[ 5037]: OKAY0000
This is a feature request to download and extract the adb binaries directly from android.com during setup, instead of from your other repo (https://github.com/openatx/adb-binaries). The binaries in that repo have been outdated since at least April 2020 (when wireless pairing was introduced).
windows: https://dl.google.com/android/repository/platform-tools-latest-windows.zip
mac: https://dl.google.com/android/repository/platform-tools-latest-darwin.zip
linux: https://dl.google.com/android/repository/platform-tools-latest-linux.zip
As the title
def adb_output(self, *args, **kwargs):
"""Run adb command use subprocess and get its content
Returns:
string of output
Raises:
EnvironmentError
"""
cmds = [adb_path(), '-s', self._serial
] if self._serial else [adb_path()]
cmds.extend(args)
cmdline = subprocess.list2cmdline(map(str, cmds))
try:
return subprocess.check_output(cmdline,
stderr=subprocess.STDOUT,
shell=True).decode('utf-8')
except subprocess.CalledProcessError as e:
if kwargs.get('raise_error', True):
raise EnvironmentError(
"subprocess", cmdline,
e.output.decode('utf-8', errors='ignore'))
使用 adbutils 过程中,要使用 adb logcat -c
这样的命令,所以找到了 adb_output()
这个函数,但是发现他的传参是通过 args 接收的,调用: adb_output("logcat", "-c")
,这样感觉比较麻烦呀;
直接实现成类似 shell()
的调用方式:adb_output("logcat -c")
会更方便一些,请教下。
code:
import adbutils
adb = adbutils.AdbClient(host="127.0.0.1", port=5037)
for event in adb.track_devices():
print(event.present, event.serial, event.status)
result:
True WRU6R20603000237 offline
False WRU6R20603000237 absent
True WRU6R20603000237 device
False WRU6R20603000237 absent
True WRU6R20603000237 offline
False WRU6R20603000237 absent
True WRU6R20603000237 device
False WRU6R20603000237 absent
True WRU6R20603000237 offline
False WRU6R20603000237 absent
True WRU6R20603000237 device
False WRU6R20603000237 absent
True c69d9b9f9ac7175b offline
False c69d9b9f9ac7175b absent
True WRU6R20603000237 offline
False WRU6R20603000237 absent
True WRU6R20603000237 device
False WRU6R20603000237 absent
True WRU6R20603000237 offline
False WRU6R20603000237 absent
True WRU6R20603000237 device
Line 455 in 47ff701
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/adbutils/mixin.py", line 461, in stop_and_pull
self.stop()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/adbutils/mixin.py", line 455, in stop
self._stream.read_until_close()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/adbutils/__init__.py", line 137, in read_until_close
chunk = self.read_raw(4096)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/adbutils/__init__.py", line 112, in read_raw
chunk = self.conn.recv(t)
KeyboardInterrupt
卡在这
手机:OPPO R15 android8
PC:MacBook pro
Is it possible to get binary screenshot data directly from the phone’s memory, without saving to the phone’s SD card and then saving it to local storage?
I'm using the below code block:
r = d.screenrecord(no_autostart=True)
r.start() # start record
r.stop_and_pull("video.mp4") # stop recording and pull video to local, then remove video from device
but when I stop recording I'm getting this error:
Traceback (most recent call last):
File "C:\Users...\main.py", line 277, in on_click_record
self.r.stop_and_pull("~/Desktop/video.mp4")
File "C:\Users...\Python39\site-packages\adbutils\mixin.py", line 565, in stop_and_pull
self.stop()
File "C:\Users...\Python39\site-packages\adbutils\mixin.py", line 558, in stop
self._stream.send("\003")
AttributeError: '_AdbStreamConnection' object has no attribute 'send'
Any help on this would be appreciated.
Hello, I want to ask if there is a way to connect 2 devices at once?
So according to #46 (comment) '_AdbStreamConnection' was removed from 'adbutils'. However, when removing and replacing with 'AdbConnection'.
Error Message:
Traceback (most recent call last): File "src/main.py", line 1, in <module> import scrcpy File "/mnt/c/Users/shiba/OneDrive/Documents/Mirror/src/scrcpy/__init__.py", line 6, in <module> from .core import Client File "/mnt/c/Users/shiba/OneDrive/Documents/Mirror/src/scrcpy/core.py", line 11, in <module> from adbutils import AdbDevice, AdbError, Network, AdbConnection, adb ImportError: cannot import name 'AdbConnection' from 'adbutils' (/home/poka/.local/lib/python3.8/site-packages/adbutils/__init__.py)
README.md tells me that to list all the devices connected i have to adb.devices().
But this raises an erorr:
adb.devices()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Input In [3], in <cell line: 1>()
----> 1 adb.devices()
AttributeError: 'AdbClient' object has no attribute 'devices'
I've tried help(adb) and found device_list method, which listed all the devices connected.
So, I suggest updating README.md https://github.com/openatx/adbutils#list-all-the-devices-and-get-device-object
想要pull /system,但是需要root权限
在使用sync.pull时,当原路径文件不存在时,python直接报错退出
I am getting per "error: [Errno 13] Permission denied: 'git'" when I run pip install adbutils
Distributor ID: Ubuntu
Description: Ubuntu 20.04.1 LTS
Release: 20.04
Codename: focal
ERROR: Failed building wheel for adbutils
Running setup.py clean for adbutils
Failed to build adbutils
Installing collected packages: adbutils
Running setup.py install for adbutils ... error
ERROR: Command errored out with exit status 1:
command: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/var/tmp/pip-install-d1c4tyzw/adbutils_cd3060821fbb4327b2a3bc27d37c0b4f/setup.py'"'"'; file='"'"'/var/tmp/pip-install-d1c4tyzw/adbutils_cd3060821fbb4327b2a3bc27d37c0b4f/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' install --record /var/tmp/pip-record-8xp3owcn/install-record.txt --single-version-externally-managed --user --prefix= --compile --install-headers /home/i_am_user/.local/include/python3.8/adbutils
cwd: /var/tmp/pip-install-d1c4tyzw/adbutils_cd3060821fbb4327b2a3bc27d37c0b4f/
Complete output (3 lines):
setup.py arguments: ['/var/tmp/pip-install-d1c4tyzw/adbutils_cd3060821fbb4327b2a3bc27d37c0b4f/setup.py', 'install', '--record', '/var/tmp/pip-record-8xp3owcn/install-record.txt', '--single-version-externally-managed', '--user', '--prefix=', '--compile', '--install-headers', '/home/i_am_user/.local/include/python3.8/adbutils']
running install
error: [Errno 13] Permission denied: 'git'
----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/var/tmp/pip-install-d1c4tyzw/adbutils_cd3060821fbb4327b2a3bc27d37c0b4f/setup.py'"'"'; file='"'"'/var/tmp/pip-install-d1c4tyzw/adbutils_cd3060821fbb4327b2a3bc27d37c0b4f/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' install --record /var/tmp/pip-record-8xp3owcn/install-record.txt --single-version-externally-managed --user --prefix= --compile --install-headers /home/i_am_user/.local/include/python3.8/adbutils Check the logs for full command output.
A divide by zero happens when using install() function to install a small APK. When the time to copy the APK is less than a second 'copytime' becomes zero:
copytime = time.time() - self.start_time
speed = humanize(self.copied / copytime) + "/s"
主要卡在checkOk那里,不知道能否修复
In Android 11 it appears to choose a random ADB port (from what I've seen between 30000 and 50000)... what's the best way to find the port number from python?
This might not be all devices, but it's what I've observed on Pixel 3 and 2.
import time
from adbutils import adb
d = adb.device()
rec = d.screenrecord(remote_path="/data/local/tmp/cu.mp4")
time.sleep(5)
rec.stop_and_pull("fc.mp4")
The result:
AttributeError: '_AdbStreamConnection' object has no attribute 'send'
adbutils==1.0.2
use like:
device.push("resource/Gallery/AutoTest/A_GIF/rain.gif", "/storage/emulated/0/DCIM/")
return error
Command ''D:\python_workspace\TestKit\venv\lib\site-packages\adbutils\binaries\adb.exe' -s 6a6b10bd push resource/Gallery/. /storage/emulated/0/DCIM/' returned non-zero exit status 1.
push source code:
self.adb_output("push", local, remote)
adb_output -> list2cmdline -> map(shlex.quote, args)
shlex.quote will convert 'D:\\python_workspace\\TestKit\\venv\\lib\\site-packages\\adbutils\\binaries\\adb.exe'
to '\'D:\\python_workspace\\TestKit\\venv\\lib\\site-packages\\adbutils\\binaries\\adb.exe\''
, this will lead this error
For some reason it seems that the stop()
method on the ScreenRecord
class does not work. After sending a stop_and_pull
call the function hangs until the 3 min timeout on the read_until_close
step.
To reproduce:
import time
from adbutils import adb
device = adb.device()
recording = device.screenrecord(remote_path="/data/local/tmp/foo.mp4")
time.sleep(5)
recording.stop_and_pull("foo.mp4")
This should take around 5 seconds to run, but takes a little over 3 minutes
no "disconnect" , how to disconnect device ?
def app_stop(self, package_name: str): """ stop app with "am force-stop" """ self._run('am', 'force-stop', package_name)
这里调的self._run()传入应该是个列表吧,改为self._run(['am', 'force-stop', package_name])运行正常
import adbutils
d = adbutils.AdbClient(host="127.0.0.1", port=5037)
我在调试这句代码时,报了下面的错误:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Program Files\JetBrains\PyCharm Community Edition 2021.1\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_umd.py", line 197, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "C:\Program Files\JetBrains\PyCharm Community Edition 2021.1\plugins\python-ce\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "C:/Users/lenovo/Desktop/camera_factory _auto_test/untils/demo.py", line 2, in <module>
from adbutils import adb
File "C:\Program Files\JetBrains\PyCharm Community Edition 2021.1\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "C:\python_env\camera_factory _case\lib\site-packages\adbutils\__init__.py", line 23, in <module>
from adbutils.mixin import ShellMixin
File "C:\Program Files\JetBrains\PyCharm Community Edition 2021.1\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "C:\python_env\camera_factory _case\lib\site-packages\adbutils\mixin.py", line 11, in <module>
from retry import retry
File "C:\Program Files\JetBrains\PyCharm Community Edition 2021.1\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "C:\python_env\camera_factory _case\lib\site-packages\retry\__init__.py", line 5, in <module>
from .api import retry
File "C:\Program Files\JetBrains\PyCharm Community Edition 2021.1\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "C:\python_env\camera_factory _case\lib\site-packages\retry\api.py", line 7, in <module>
from retry.compat import decorator
File "C:\Program Files\JetBrains\PyCharm Community Edition 2021.1\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "C:\python_env\camera_factory _case\lib\site-packages\retry\compat.py", line 5, in <module>
from decorator import decorator
File "C:\Program Files\JetBrains\PyCharm Community Edition 2021.1\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "C:\Users\lenovo\Desktop\camera_factory _auto_test\untils\decorator.py", line 9, in <module>
import wda
File "C:\Program Files\JetBrains\PyCharm Community Edition 2021.1\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "C:\python_env\camera_factory _case\lib\site-packages\wda\__init__.py", line 260, in <module>
class BaseClient(object):
File "C:\python_env\camera_factory _case\lib\site-packages\wda\__init__.py", line 383, in BaseClient
@retry.retry(exceptions=WDAEmptyResponseError, tries=3, delay=2)
AttributeError: module 'retry' has no attribute 'retry'
Script:
import adbutils
devide=adbutils.AdbClient(host="127.0.0.1",port=5037)
d=devide.device_list()[0]
#print(d.is_screen_on())
print(d.current_app())
d.app_start("com.android.launcher3")
d.rotation()
Error:
Traceback (most recent call last):
File "G:/MyPython/MyAirTest/V500/adb的代码库测试.py", line 12, in
d.rotation()
File "C:\Program Files\Python38\lib\site-packages\adbutils\mixin.py", line 292, in rotation
raise AdbError("rotation get failed")
adbutils.errors.AdbError: rotation get failed
类似这种:adb pull /device/tmp ./tmp
FROM williamfzc/pyatool#2
WIP https://github.com/williamfzc/adbutils
加入自定义函数以及定制方法,以应对更为复杂的操作场景。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.