mirror of
https://github.com/LmeSzinc/AzurLaneAutoScript.git
synced 2025-01-08 12:47:32 +08:00
Opt: Serial in ADB commands now optional
This commit is contained in:
parent
ffa36b0fc2
commit
5b38d82f06
@ -19,8 +19,8 @@ class AScreenCap(Connection):
|
||||
def _ascreencap_init(self):
|
||||
logger.hr('aScreenCap init')
|
||||
|
||||
arc = self.adb_exec_out(['getprop', 'ro.product.cpu.abi'], serial=self.serial).decode('utf-8').strip()
|
||||
sdk = self.adb_exec_out(['getprop', 'ro.build.version.sdk'], serial=self.serial).decode('utf-8').strip()
|
||||
arc = self.adb_exec_out(['getprop', 'ro.product.cpu.abi']).decode('utf-8').strip()
|
||||
sdk = self.adb_exec_out(['getprop', 'ro.build.version.sdk']).decode('utf-8').strip()
|
||||
logger.info(f'cpu_arc: {arc}, sdk_ver: {sdk}')
|
||||
|
||||
filepath = os.path.join(self.config.ASCREENCAP_FILEPATH_LOCAL, arc, 'ascreencap')
|
||||
@ -30,10 +30,10 @@ class AScreenCap(Connection):
|
||||
exit(1)
|
||||
|
||||
logger.info(f'pushing {filepath}')
|
||||
self.adb_command(['push', filepath, self.config.ASCREENCAP_FILEPATH_REMOTE], serial=self.serial)
|
||||
self.adb_push([filepath, self.config.ASCREENCAP_FILEPATH_REMOTE])
|
||||
|
||||
logger.info(f'chmod 0777 {self.config.ASCREENCAP_FILEPATH_REMOTE}')
|
||||
self.adb_shell(['chmod', '0777', self.config.ASCREENCAP_FILEPATH_REMOTE], serial=self.serial)
|
||||
self.adb_shell(['chmod', '0777', self.config.ASCREENCAP_FILEPATH_REMOTE])
|
||||
|
||||
def _ascreencap_reposition_byte_pointer(self, byte_array):
|
||||
"""Method to return the sanitized version of ascreencap stdout for devices
|
||||
@ -50,7 +50,7 @@ class AScreenCap(Connection):
|
||||
|
||||
def _ascreencap_execute(self):
|
||||
raw_compressed_data = self._ascreencap_reposition_byte_pointer(
|
||||
self.adb_exec_out([self.config.ASCREENCAP_FILEPATH_REMOTE, '--pack', '2', '--stdout'], serial=self.serial))
|
||||
self.adb_exec_out([self.config.ASCREENCAP_FILEPATH_REMOTE, '--pack', '2', '--stdout']))
|
||||
|
||||
compressed_data_header = np.frombuffer(raw_compressed_data[0:20], dtype=np.uint32)
|
||||
if compressed_data_header[0] != 828001602:
|
||||
|
@ -51,7 +51,7 @@ class Connection:
|
||||
if serial:
|
||||
cmd = [self.adb_binary, '-s', serial] + cmd
|
||||
else:
|
||||
cmd = [self.adb_binary] + cmd
|
||||
cmd = [self.adb_binary, '-s', self.serial] + cmd
|
||||
|
||||
# Use shell=True to disable console window when using GUI.
|
||||
# Although, there's still a window when you stop running in GUI, which cause by gooey.
|
||||
@ -71,6 +71,10 @@ class Connection:
|
||||
cmd.insert(0, 'forward')
|
||||
return self.adb_command(cmd, serial)
|
||||
|
||||
def adb_push(self, cmd, serial=None):
|
||||
cmd.insert(0, 'push')
|
||||
self.adb_command(cmd, serial)
|
||||
|
||||
def _adb_connect(self, serial):
|
||||
if serial.startswith('127.0.0.1'):
|
||||
msg = self.adb_command(['connect', serial]).decode("utf-8")
|
||||
@ -94,5 +98,5 @@ class Connection:
|
||||
return device
|
||||
|
||||
def disable_uiautomator2_auto_quit(self, port=7912, expire=300000):
|
||||
self.adb_command(['forward', 'tcp:%s' % port, 'tcp:%s' % port], serial=self.serial)
|
||||
self.adb_forward(['tcp:%s' % port, 'tcp:%s' % port])
|
||||
requests.post('http://127.0.0.1:%s/newCommandTimeout' % port, data=str(expire))
|
||||
|
@ -70,7 +70,7 @@ class Control(MiniTouch):
|
||||
|
||||
@retry()
|
||||
def _click_adb(self, x, y):
|
||||
self.adb_shell(['input', 'tap', str(x), str(y)], serial=self.serial)
|
||||
self.adb_shell(['input', 'tap', str(x), str(y)])
|
||||
|
||||
def multi_click(self, button, n, interval=(0.1, 0.2)):
|
||||
self.click_record_check(button)
|
||||
|
@ -176,11 +176,11 @@ class MiniTouch(Connection):
|
||||
self._minitouch_port = get_port()
|
||||
logger.info(f"Minitouch bind to port {self._minitouch_port}")
|
||||
|
||||
self.adb_forward([f"tcp:{self._minitouch_port}", "localabstract:minitouch"], serial=self.serial)
|
||||
self.adb_forward([f"tcp:{self._minitouch_port}", "localabstract:minitouch"])
|
||||
logger.info(f"Minitouch forward port {self._minitouch_port}")
|
||||
|
||||
# No need, minitouch already started by uiautomator2
|
||||
# self.adb_shell([self.config.MINITOUCH_FILEPATH_REMOTE], serial=self.serial)
|
||||
# self.adb_shell([self.config.MINITOUCH_FILEPATH_REMOTE])
|
||||
|
||||
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
client.connect(('127.0.0.1', self._minitouch_port))
|
||||
|
@ -46,7 +46,7 @@ class Screenshot(AScreenCap):
|
||||
return screenshot
|
||||
|
||||
def _screenshot_adb(self):
|
||||
screenshot = self.adb_shell(['screencap', '-p'], serial=self.serial)
|
||||
screenshot = self.adb_shell(['screencap', '-p'])
|
||||
return self._process_screenshot(screenshot)
|
||||
|
||||
@retry(wait_fixed=5000, stop_max_attempt_number=10)
|
||||
|
Loading…
Reference in New Issue
Block a user