From 1d6eff5dff9c262292cecf776d80e295ad7a6e33 Mon Sep 17 00:00:00 2001 From: LmeSzinc <37934724+LmeSzinc@users.noreply.github.com> Date: Fri, 7 Jun 2024 16:21:14 +0800 Subject: [PATCH] Pref: Try nc command on android phones first --- module/device/connection.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/module/device/connection.py b/module/device/connection.py index 1fd5eb911..2e19fd286 100644 --- a/module/device/connection.py +++ b/module/device/connection.py @@ -385,15 +385,21 @@ class Connection(ConnectionAttr): Returns: list[str]: ['nc'] or ['busybox', 'nc'] """ - sdk = self.sdk_ver - logger.info(f'sdk_ver: {sdk}') - if sdk >= 28: - # Android 9 emulators does not have `nc`, try `busybox nc` - # BlueStacks Pie (Android 9) has `nc` but cannot send data, try `busybox nc` first - trial = [ - ['busybox', 'nc'], - ['nc'], - ] + if self.is_emulator: + sdk = self.sdk_ver + logger.info(f'sdk_ver: {sdk}') + if sdk >= 28: + # LD Player 9 does not have `nc`, try `busybox nc` + # BlueStacks Pie (Android 9) has `nc` but cannot send data, try `busybox nc` first + trial = [ + ['busybox', 'nc'], + ['nc'], + ] + else: + trial = [ + ['nc'], + ['busybox', 'nc'], + ] else: trial = [ ['nc'], @@ -401,8 +407,9 @@ class Connection(ConnectionAttr): ] for command in trial: # About 3ms - result = self.adb_shell(command) # Result should be command help if success + # nc: bad argument count (see "nc --help") + result = self.adb_shell(command) # `/system/bin/sh: nc: not found` if 'not found' in result: continue