1
0
mirror of https://github.com/ARM-software/devlib.git synced 2025-01-31 02:00:45 +00:00

AndroidTarget: Add force_new parameter to open_url

When True, this will force whatever application Android deems best
for viewing that url to be relaunched.

This can be useful when trying to open e.g. Google Maps search URLs,
as the actual search result can be influenced by the location being
currently displayed. Forcing the app the be relaunched allows us to
have reproducible behaviours.
This commit is contained in:
Valentin Schneider 2018-06-20 17:49:20 +01:00 committed by Marc Bonnici
parent 56a7394d58
commit 38037850b6

View File

@ -16,7 +16,7 @@ from devlib.module import get_module
from devlib.platform import Platform
from devlib.exception import TargetError, TargetNotRespondingError, TimeoutError
from devlib.utils.ssh import SshConnection
from devlib.utils.android import AdbConnection, AndroidProperties, LogcatMonitor, adb_command, adb_disconnect
from devlib.utils.android import AdbConnection, AndroidProperties, LogcatMonitor, adb_command, adb_disconnect, INTENT_FLAGS
from devlib.utils.misc import memoized, isiterable, convert_new_lines
from devlib.utils.misc import commonprefix, escape_double_quotes, merge_lists
from devlib.utils.misc import ABI_MAP, get_cpu_name, ranges_to_list
@ -1423,8 +1423,23 @@ class AndroidTarget(Target):
cmd = 'settings put system user_rotation {}'
self.execute(cmd.format(rotation))
def open_url(self, url):
def open_url(self, url, force_new=False):
"""
Start a view activity by specifying an URL
:param url: URL of the item to display
:type url: str
:param force_new: Force the viewing application to be relaunched
if it is already running
:type force_new: bool
"""
cmd = 'am start -a android.intent.action.VIEW -d "{}"'
if force_new:
cmd = cmd + ' -f {}'.format(INTENT_FLAGS['ACTIVITY_NEW_TASK'] |
INTENT_FLAGS['ACTIVITY_CLEAR_TASK'])
self.execute(cmd.format(escape_double_quotes(url)))
def homescreen(self):