mirror of
https://github.com/ARM-software/devlib.git
synced 2025-01-31 02:00:45 +00:00
utils/android: Ensure that adb_server is propergated to helper functions
Ensure that we use the correct `adb_server` in the adb helper functions.
This commit is contained in:
parent
17374cf2b4
commit
696dec9b91
@ -271,7 +271,7 @@ class AdbConnection(object):
|
|||||||
self.adb_as_root = adb_as_root
|
self.adb_as_root = adb_as_root
|
||||||
if self.adb_as_root:
|
if self.adb_as_root:
|
||||||
self.adb_root(enable=True)
|
self.adb_root(enable=True)
|
||||||
adb_connect(self.device)
|
adb_connect(self.device, adb_server=self.adb_server)
|
||||||
AdbConnection.active_connections[self.device] += 1
|
AdbConnection.active_connections[self.device] += 1
|
||||||
self._setup_ls()
|
self._setup_ls()
|
||||||
self._setup_su()
|
self._setup_su()
|
||||||
@ -319,7 +319,7 @@ class AdbConnection(object):
|
|||||||
if AdbConnection.active_connections[self.device] <= 0:
|
if AdbConnection.active_connections[self.device] <= 0:
|
||||||
if self.adb_as_root:
|
if self.adb_as_root:
|
||||||
self.adb_root(self.device, enable=False)
|
self.adb_root(self.device, enable=False)
|
||||||
adb_disconnect(self.device)
|
adb_disconnect(self.device, self.adb_server)
|
||||||
del AdbConnection.active_connections[self.device]
|
del AdbConnection.active_connections[self.device]
|
||||||
|
|
||||||
def cancel_running_command(self):
|
def cancel_running_command(self):
|
||||||
@ -330,16 +330,16 @@ class AdbConnection(object):
|
|||||||
|
|
||||||
def adb_root(self, enable=True):
|
def adb_root(self, enable=True):
|
||||||
cmd = 'root' if enable else 'unroot'
|
cmd = 'root' if enable else 'unroot'
|
||||||
output = adb_command(self.device, cmd, timeout=30)
|
output = adb_command(self.device, cmd, timeout=30, adb_server=self.adb_server)
|
||||||
if 'cannot run as root in production builds' in output:
|
if 'cannot run as root in production builds' in output:
|
||||||
raise TargetStableError(output)
|
raise TargetStableError(output)
|
||||||
AdbConnection._connected_as_root[self.device] = enable
|
AdbConnection._connected_as_root[self.device] = enable
|
||||||
|
|
||||||
def wait_for_device(self, timeout=30):
|
def wait_for_device(self, timeout=30):
|
||||||
adb_command(self.device, 'wait-for-device', timeout)
|
adb_command(self.device, 'wait-for-device', timeout, self.adb_server)
|
||||||
|
|
||||||
def reboot_bootloader(self, timeout=30):
|
def reboot_bootloader(self, timeout=30):
|
||||||
adb_command(self.device, 'reboot-bootloader', timeout)
|
adb_command(self.device, 'reboot-bootloader', timeout, self.adb_server)
|
||||||
|
|
||||||
# Again, we need to handle boards where the default output format from ls is
|
# Again, we need to handle boards where the default output format from ls is
|
||||||
# single column *and* boards where the default output is multi-column.
|
# single column *and* boards where the default output is multi-column.
|
||||||
@ -423,7 +423,7 @@ def adb_get_device(timeout=None, adb_server=None):
|
|||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
|
|
||||||
def adb_connect(device, timeout=None, attempts=MAX_ATTEMPTS):
|
def adb_connect(device, timeout=None, attempts=MAX_ATTEMPTS, adb_server=None):
|
||||||
_check_env()
|
_check_env()
|
||||||
tries = 0
|
tries = 0
|
||||||
output = None
|
output = None
|
||||||
@ -436,11 +436,12 @@ def adb_connect(device, timeout=None, attempts=MAX_ATTEMPTS):
|
|||||||
# adb connection may have gone "stale", resulting in adb blocking
|
# adb connection may have gone "stale", resulting in adb blocking
|
||||||
# indefinitely when making calls to the device. To avoid this,
|
# indefinitely when making calls to the device. To avoid this,
|
||||||
# always disconnect first.
|
# always disconnect first.
|
||||||
adb_disconnect(device)
|
adb_disconnect(device, adb_server)
|
||||||
command = 'adb connect {}'.format(quote(device))
|
adb_cmd = get_adb_command(None, 'connect', adb_server)
|
||||||
|
command = '{} {}'.format(adb_cmd, quote(device))
|
||||||
logger.debug(command)
|
logger.debug(command)
|
||||||
output, _ = check_output(command, shell=True, timeout=timeout)
|
output, _ = check_output(command, shell=True, timeout=timeout)
|
||||||
if _ping(device):
|
if _ping(device, adb_server):
|
||||||
break
|
break
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
else: # did not connect to the device
|
else: # did not connect to the device
|
||||||
@ -450,22 +451,23 @@ def adb_connect(device, timeout=None, attempts=MAX_ATTEMPTS):
|
|||||||
raise HostError(message)
|
raise HostError(message)
|
||||||
|
|
||||||
|
|
||||||
def adb_disconnect(device):
|
def adb_disconnect(device, adb_server=None):
|
||||||
_check_env()
|
_check_env()
|
||||||
if not device:
|
if not device:
|
||||||
return
|
return
|
||||||
if ":" in device and device in adb_list_devices():
|
if ":" in device and device in adb_list_devices(adb_server):
|
||||||
command = "adb disconnect " + device
|
adb_cmd = get_adb_command(None, 'disconnect', adb_server)
|
||||||
|
command = "{} {}".format(adb_cmd, device)
|
||||||
logger.debug(command)
|
logger.debug(command)
|
||||||
retval = subprocess.call(command, stdout=open(os.devnull, 'wb'), shell=True)
|
retval = subprocess.call(command, stdout=open(os.devnull, 'wb'), shell=True)
|
||||||
if retval:
|
if retval:
|
||||||
raise TargetTransientError('"{}" returned {}'.format(command, retval))
|
raise TargetTransientError('"{}" returned {}'.format(command, retval))
|
||||||
|
|
||||||
|
|
||||||
def _ping(device):
|
def _ping(device, adb_server=None):
|
||||||
_check_env()
|
_check_env()
|
||||||
device_string = ' -s {}'.format(quote(device)) if device else ''
|
adb_cmd = get_adb_command(device, 'shell', adb_server)
|
||||||
command = "adb{} shell \"ls /data/local/tmp > /dev/null\"".format(device_string)
|
command = "{} {}".format(adb_cmd, quote('ls /data/local/tmp > /dev/null'))
|
||||||
logger.debug(command)
|
logger.debug(command)
|
||||||
result = subprocess.call(command, stderr=subprocess.PIPE, shell=True)
|
result = subprocess.call(command, stderr=subprocess.PIPE, shell=True)
|
||||||
if not result: # pylint: disable=simplifiable-if-statement
|
if not result: # pylint: disable=simplifiable-if-statement
|
||||||
@ -544,14 +546,13 @@ def adb_background_shell(device, command,
|
|||||||
if as_root:
|
if as_root:
|
||||||
command = 'echo {} | su'.format(quote(command))
|
command = 'echo {} | su'.format(quote(command))
|
||||||
|
|
||||||
device_string = ' -H {}'.format(adb_server) if adb_server else ''
|
adb_cmd = get_adb_command(None, 'shell', adb_server)
|
||||||
device_string += ' -s {}'.format(device) if device else ''
|
full_command = '{} {}'.format(adb_cmd, quote(command))
|
||||||
full_command = 'adb{} shell {}'.format(device_string, quote(command))
|
|
||||||
logger.debug(full_command)
|
logger.debug(full_command)
|
||||||
return subprocess.Popen(full_command, stdout=stdout, stderr=stderr, shell=True)
|
return subprocess.Popen(full_command, stdout=stdout, stderr=stderr, shell=True)
|
||||||
|
|
||||||
def adb_kill_server(self, timeout=30):
|
def adb_kill_server(self, timeout=30, adb_server=None):
|
||||||
adb_command(None, 'kill-server', timeout)
|
adb_command(None, 'kill-server', timeout, adb_server)
|
||||||
|
|
||||||
def adb_list_devices(adb_server=None):
|
def adb_list_devices(adb_server=None):
|
||||||
output = adb_command(None, 'devices', adb_server=adb_server)
|
output = adb_command(None, 'devices', adb_server=adb_server)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user