mirror of
https://github.com/ARM-software/devlib.git
synced 2025-02-07 13:40:48 +00:00
AndroidTarget: Add guards / workarounds for adb specific functionality
A `Target` should be independent of the connection type used however we do have some adb specific functionality as part of the `Target` for speed/compatibility reasons. For the cases that we can perform the operation in a connection agnostic method add alternative implementation and for those raise a error to inform the user of the issue.
This commit is contained in:
parent
9982f810e1
commit
5d4315c5d2
@ -1412,7 +1412,14 @@ class AndroidTarget(Target):
|
|||||||
if self.get_sdk_version() >= 23:
|
if self.get_sdk_version() >= 23:
|
||||||
flags.append('-g') # Grant all runtime permissions
|
flags.append('-g') # Grant all runtime permissions
|
||||||
self.logger.debug("Replace APK = {}, ADB flags = '{}'".format(replace, ' '.join(flags)))
|
self.logger.debug("Replace APK = {}, ADB flags = '{}'".format(replace, ' '.join(flags)))
|
||||||
|
if isinstance(self.conn, AdbConnection):
|
||||||
return adb_command(self.adb_name, "install {} {}".format(' '.join(flags), quote(filepath)), timeout=timeout)
|
return adb_command(self.adb_name, "install {} {}".format(' '.join(flags), quote(filepath)), timeout=timeout)
|
||||||
|
else:
|
||||||
|
dev_path = self.get_workpath(filepath.rsplit(os.path.sep, 1)[-1])
|
||||||
|
self.push(quote(filepath), dev_path, timeout=timeout)
|
||||||
|
result = self.execute("pm install {} {}".format(' '.join(flags), quote(dev_path)), timeout=timeout)
|
||||||
|
self.remove(dev_path)
|
||||||
|
return result
|
||||||
else:
|
else:
|
||||||
raise TargetStableError('Can\'t install {}: unsupported format.'.format(filepath))
|
raise TargetStableError('Can\'t install {}: unsupported format.'.format(filepath))
|
||||||
|
|
||||||
@ -1473,7 +1480,10 @@ class AndroidTarget(Target):
|
|||||||
return on_device_executable
|
return on_device_executable
|
||||||
|
|
||||||
def uninstall_package(self, package):
|
def uninstall_package(self, package):
|
||||||
|
if isinstance(self.conn, AdbConnection):
|
||||||
adb_command(self.adb_name, "uninstall {}".format(quote(package)), timeout=30)
|
adb_command(self.adb_name, "uninstall {}".format(quote(package)), timeout=30)
|
||||||
|
else:
|
||||||
|
self.execute("pm uninstall {}".format(quote(package)), timeout=30)
|
||||||
|
|
||||||
def uninstall_executable(self, executable_name):
|
def uninstall_executable(self, executable_name):
|
||||||
on_device_executable = self.path.join(self.executables_directory, executable_name)
|
on_device_executable = self.path.join(self.executables_directory, executable_name)
|
||||||
@ -1483,23 +1493,39 @@ class AndroidTarget(Target):
|
|||||||
def dump_logcat(self, filepath, filter=None, append=False, timeout=30): # pylint: disable=redefined-builtin
|
def dump_logcat(self, filepath, filter=None, append=False, timeout=30): # pylint: disable=redefined-builtin
|
||||||
op = '>>' if append else '>'
|
op = '>>' if append else '>'
|
||||||
filtstr = ' -s {}'.format(quote(filter)) if filter else ''
|
filtstr = ' -s {}'.format(quote(filter)) if filter else ''
|
||||||
|
if isinstance(self.conn, AdbConnection):
|
||||||
command = 'logcat -d{} {} {}'.format(filtstr, op, quote(filepath))
|
command = 'logcat -d{} {} {}'.format(filtstr, op, quote(filepath))
|
||||||
adb_command(self.adb_name, command, timeout=timeout)
|
adb_command(self.adb_name, command, timeout=timeout)
|
||||||
|
else:
|
||||||
|
dev_path = self.get_workpath('logcat')
|
||||||
|
command = 'logcat -d{} {} {}'.format(filtstr, op, quote(dev_path))
|
||||||
|
self.execute(command, timeout=timeout)
|
||||||
|
self.pull(dev_path, filepath)
|
||||||
|
self.remove(dev_path)
|
||||||
|
|
||||||
def clear_logcat(self):
|
def clear_logcat(self):
|
||||||
with self.clear_logcat_lock:
|
with self.clear_logcat_lock:
|
||||||
|
if isinstance(self.conn, AdbConnection):
|
||||||
adb_command(self.adb_name, 'logcat -c', timeout=30)
|
adb_command(self.adb_name, 'logcat -c', timeout=30)
|
||||||
|
else:
|
||||||
|
self.execute('logcat -c', timeout=30)
|
||||||
|
|
||||||
def get_logcat_monitor(self, regexps=None):
|
def get_logcat_monitor(self, regexps=None):
|
||||||
return LogcatMonitor(self, regexps)
|
return LogcatMonitor(self, regexps)
|
||||||
|
|
||||||
def adb_kill_server(self, timeout=30):
|
def adb_kill_server(self, timeout=30):
|
||||||
|
if not isinstance(self.conn, AdbConnection):
|
||||||
|
raise TargetStableError('Cannot issues adb command without adb connection')
|
||||||
adb_command(self.adb_name, 'kill-server', timeout)
|
adb_command(self.adb_name, 'kill-server', timeout)
|
||||||
|
|
||||||
def adb_wait_for_device(self, timeout=30):
|
def adb_wait_for_device(self, timeout=30):
|
||||||
|
if not isinstance(self.conn, AdbConnection):
|
||||||
|
raise TargetStableError('Cannot issues adb command without adb connection')
|
||||||
adb_command(self.adb_name, 'wait-for-device', timeout)
|
adb_command(self.adb_name, 'wait-for-device', timeout)
|
||||||
|
|
||||||
def adb_reboot_bootloader(self, timeout=30):
|
def adb_reboot_bootloader(self, timeout=30):
|
||||||
|
if not isinstance(self.conn, AdbConnection):
|
||||||
|
raise TargetStableError('Cannot issues adb command without adb connection')
|
||||||
adb_command(self.adb_name, 'reboot-bootloader', timeout)
|
adb_command(self.adb_name, 'reboot-bootloader', timeout)
|
||||||
|
|
||||||
def adb_root(self, enable=True, force=False):
|
def adb_root(self, enable=True, force=False):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user