Fix: Compatible with old and new adbutils

This commit is contained in:
LmeSzinc 2023-05-16 23:39:18 +08:00
parent 541cd866eb
commit 00fcba432a
2 changed files with 13 additions and 6 deletions

View File

@ -6,14 +6,14 @@ import typing as t
from time import sleep
import numpy as np
from adbutils import _AdbStreamConnection, AdbError, Network
from adbutils import AdbError, Network
from module.base.decorator import cached_property
from module.base.timer import Timer
from module.device.connection import Connection
from module.device.method.scrcpy.control import ControlSender
from module.device.method.scrcpy.options import ScrcpyOptions
from module.device.method.utils import recv_all
from module.device.method.utils import AdbConnection, recv_all
from module.exception import RequestHumanTakeover
from module.logger import logger
@ -32,7 +32,7 @@ class ScrcpyCore(Connection):
_scrcpy_last_frame_time: float = 0.
_scrcpy_alive = False
_scrcpy_server_stream: t.Optional[_AdbStreamConnection] = None
_scrcpy_server_stream: t.Optional[AdbConnection] = None
_scrcpy_video_socket: t.Optional[socket.socket] = None
_scrcpy_control_socket: t.Optional[socket.socket] = None
_scrcpy_control_socket_lock = threading.Lock()
@ -68,7 +68,7 @@ class ScrcpyCore(Connection):
"""
logger.hr('Scrcpy server start')
commands = ScrcpyOptions.command_v120(jar_path=self.config.SCRCPY_FILEPATH_REMOTE)
self._scrcpy_server_stream: _AdbStreamConnection = self.adb.shell(
self._scrcpy_server_stream: AdbConnection = self.adb.shell(
commands,
stream=True,
)

View File

@ -4,9 +4,16 @@ import socket
import time
import uiautomator2 as u2
from adbutils import AdbTimeout, _AdbStreamConnection
from adbutils import AdbTimeout
from lxml import etree
try:
# adbutils 0.x
from adbutils import _AdbStreamConnection as AdbConnection
except ImportError:
# adbutils >= 1.0
from adbutils import AdbConnection
from module.base.decorator import cached_property
from module.logger import logger
@ -51,7 +58,7 @@ def recv_all(stream, chunk_size=4096, recv_interval=0.000) -> bytes:
Raises:
AdbTimeout
"""
if isinstance(stream, _AdbStreamConnection):
if isinstance(stream, AdbConnection):
stream = stream.conn
stream.settimeout(10)
else: