diff options
Diffstat (limited to 'catapult/devil/devil/android/tools/webview_app.py')
-rwxr-xr-x | catapult/devil/devil/android/tools/webview_app.py | 45 |
1 files changed, 24 insertions, 21 deletions
diff --git a/catapult/devil/devil/android/tools/webview_app.py b/catapult/devil/devil/android/tools/webview_app.py index 36b70391..406de1cb 100755 --- a/catapult/devil/devil/android/tools/webview_app.py +++ b/catapult/devil/devil/android/tools/webview_app.py @@ -2,7 +2,6 @@ # Copyright 2019 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. - """A script to use a package as the WebView provider while running a command.""" import argparse @@ -12,14 +11,15 @@ import os import re import sys - if __name__ == '__main__': sys.path.append( - os.path.abspath(os.path.join(os.path.dirname(__file__), - '..', '..', '..'))) - sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), - '..', '..', '..', '..', 'common', 'py_utils'))) - + os.path.abspath( + os.path.join(os.path.dirname(__file__), '..', '..', '..'))) + sys.path.append( + os.path.abspath( + os.path.join( + os.path.dirname(__file__), '..', '..', '..', '..', 'common', + 'py_utils'))) from devil.android import apk_helper from devil.android import device_errors @@ -33,9 +33,10 @@ from py_utils import tempfile_ext logger = logging.getLogger(__name__) -_SYSTEM_PATH_RE = re.compile(r'^\s*\/system\/') +_SYSTEM_PATH_RE = re.compile(r'^\s*\/(system|product)\/') _WEBVIEW_INSTALL_TIMEOUT = 300 + @contextlib.contextmanager def UseWebViewProvider(device, apk, expected_package=''): """A context manager that uses the apk as the webview provider while in scope. @@ -55,8 +56,9 @@ def UseWebViewProvider(device, apk, expected_package=''): 'WebView Provider package %s does not match expected %s' % (package_name, expected_package), str(device)) - if (device.build_version_sdk in - [version_codes.NOUGAT, version_codes.NOUGAT_MR1]): + if (device.build_version_sdk in [ + version_codes.NOUGAT, version_codes.NOUGAT_MR1 + ]): logger.warning('Due to webviewupdate bug in Nougat, WebView Fallback Logic ' 'will be disabled and WebView provider may be changed after ' 'exit of UseWebViewProvider context manager scope.') @@ -84,9 +86,7 @@ def UseWebViewProvider(device, apk, expected_package=''): elif system_paths: # app is system app, use ReplaceSystemApp to install with system_app.ReplaceSystemApp( - device, - package_name, - apk, + device, package_name, apk, install_timeout=_WEBVIEW_INSTALL_TIMEOUT): _SetWebViewProvider(device, package_name) yield @@ -138,15 +138,15 @@ def _UninstallNonSystemApp(device, package_name): for user_path in user_paths: host_path = _RebasePath(temp_dir, user_path) # PullFile takes care of host_path creation if needed. - device.PullFile(user_path, host_path) + device.PullFile(user_path, host_path, timeout=_WEBVIEW_INSTALL_TIMEOUT) host_paths.append(host_path) device.Uninstall(package_name) try: yield finally: for host_path in reversed(host_paths): - device.Install(host_path, reinstall=True, - timeout=_WEBVIEW_INSTALL_TIMEOUT) + device.Install( + host_path, reinstall=True, timeout=_WEBVIEW_INSTALL_TIMEOUT) else: yield @@ -169,7 +169,10 @@ def main(raw_args): script_common.AddDeviceArguments(p) script_common.AddEnvironmentArguments(p) p.add_argument( - '-v', '--verbose', action='count', default=0, + '-v', + '--verbose', + action='count', + default=0, help='Print more information.') p.add_argument('command', nargs='*') @@ -179,10 +182,10 @@ def main(raw_args): yield parser.add_argument( - '--apk', required=True, - help='The apk to use as the provider.') + '--apk', required=True, help='The apk to use as the provider.') parser.add_argument( - '--expected-package', default='', + '--expected-package', + default='', help="Verify apk's package name matches value, disabled by default.") add_common_arguments(parser) parser.set_defaults(func=use_webview_provider) @@ -192,7 +195,7 @@ def main(raw_args): run_tests_helper.SetLogLevel(args.verbose) script_common.InitializeEnvironment(args) - devices = script_common.GetDevices(args.devices, args.blacklist_file) + devices = script_common.GetDevices(args.devices, args.denylist_file) parallel_devices = parallelizer.SyncParallelizer( [args.func(d, args) for d in devices]) with parallel_devices: |