| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright 2015 The Chromium Authors. All rights reserved. | 3 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 """Install *_incremental.apk targets as well as their dependent files.""" | 7 """Install *_incremental.apk targets as well as their dependent files.""" |
| 8 | 8 |
| 9 import argparse | 9 import argparse |
| 10 import glob | 10 import glob |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 cache_path = _DeviceCachePath(device) | 79 cache_path = _DeviceCachePath(device) |
| 80 if os.path.exists(cache_path): | 80 if os.path.exists(cache_path): |
| 81 os.unlink(cache_path) | 81 os.unlink(cache_path) |
| 82 device.RunShellCommand(['rm', '-rf', _GetDeviceIncrementalDir(package)], | 82 device.RunShellCommand(['rm', '-rf', _GetDeviceIncrementalDir(package)], |
| 83 check_return=True) | 83 check_return=True) |
| 84 logging.info('Uninstall took %s seconds.', main_timer.GetDelta()) | 84 logging.info('Uninstall took %s seconds.', main_timer.GetDelta()) |
| 85 | 85 |
| 86 | 86 |
| 87 def Install(device, apk, split_globs=None, native_libs=None, dex_files=None, | 87 def Install(device, apk, split_globs=None, native_libs=None, dex_files=None, |
| 88 enable_device_cache=False, use_concurrency=True, | 88 enable_device_cache=False, use_concurrency=True, |
| 89 show_proguard_warning=False, permissions=()): | 89 show_proguard_warning=False, permissions=(), |
| 90 allow_downgrade=True): |
| 90 """Installs the given incremental apk and all required supporting files. | 91 """Installs the given incremental apk and all required supporting files. |
| 91 | 92 |
| 92 Args: | 93 Args: |
| 93 device: A DeviceUtils instance. | 94 device: A DeviceUtils instance. |
| 94 apk: The path to the apk, or an ApkHelper instance. | 95 apk: The path to the apk, or an ApkHelper instance. |
| 95 split_globs: Glob patterns for any required apk splits (optional). | 96 split_globs: Glob patterns for any required apk splits (optional). |
| 96 native_libs: List of app's native libraries (optional). | 97 native_libs: List of app's native libraries (optional). |
| 97 dex_files: List of .dex.jar files that comprise the app's Dalvik code. | 98 dex_files: List of .dex.jar files that comprise the app's Dalvik code. |
| 98 enable_device_cache: Whether to enable on-device caching of checksums. | 99 enable_device_cache: Whether to enable on-device caching of checksums. |
| 99 use_concurrency: Whether to speed things up using multiple threads. | 100 use_concurrency: Whether to speed things up using multiple threads. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 112 device_incremental_dir = _GetDeviceIncrementalDir(apk_package) | 113 device_incremental_dir = _GetDeviceIncrementalDir(apk_package) |
| 113 | 114 |
| 114 # Install .apk(s) if any of them have changed. | 115 # Install .apk(s) if any of them have changed. |
| 115 def do_install(): | 116 def do_install(): |
| 116 install_timer.Start() | 117 install_timer.Start() |
| 117 if split_globs: | 118 if split_globs: |
| 118 splits = [] | 119 splits = [] |
| 119 for split_glob in split_globs: | 120 for split_glob in split_globs: |
| 120 splits.extend((f for f in glob.glob(split_glob))) | 121 splits.extend((f for f in glob.glob(split_glob))) |
| 121 device.InstallSplitApk(apk, splits, reinstall=True, | 122 device.InstallSplitApk(apk, splits, reinstall=True, |
| 122 allow_cached_props=True, permissions=permissions) | 123 allow_cached_props=True, permissions=permissions, |
| 124 allow_downgrade=allow_downgrade) |
| 123 else: | 125 else: |
| 124 device.Install(apk, reinstall=True, permissions=permissions) | 126 device.Install(apk, reinstall=True, permissions=permissions, |
| 127 allow_downgrade=allow_downgrade) |
| 125 install_timer.Stop(log=False) | 128 install_timer.Stop(log=False) |
| 126 | 129 |
| 127 # Push .so and .dex files to the device (if they have changed). | 130 # Push .so and .dex files to the device (if they have changed). |
| 128 def do_push_files(): | 131 def do_push_files(): |
| 129 if native_libs: | 132 if native_libs: |
| 130 push_native_timer.Start() | 133 push_native_timer.Start() |
| 131 with build_utils.TempDir() as temp_dir: | 134 with build_utils.TempDir() as temp_dir: |
| 132 device_lib_dir = posixpath.join(device_incremental_dir, 'lib') | 135 device_lib_dir = posixpath.join(device_incremental_dir, 'lib') |
| 133 for path in native_libs: | 136 for path in native_libs: |
| 134 # Note: Can't use symlinks as they don't work when | 137 # Note: Can't use symlinks as they don't work when |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 default=False, | 268 default=False, |
| 266 help='Print a warning about proguard being disabled') | 269 help='Print a warning about proguard being disabled') |
| 267 parser.add_argument('--dont-even-try', | 270 parser.add_argument('--dont-even-try', |
| 268 help='Prints this message and exits.') | 271 help='Prints this message and exits.') |
| 269 parser.add_argument('-v', | 272 parser.add_argument('-v', |
| 270 '--verbose', | 273 '--verbose', |
| 271 dest='verbose_count', | 274 dest='verbose_count', |
| 272 default=0, | 275 default=0, |
| 273 action='count', | 276 action='count', |
| 274 help='Verbose level (multiple times for more)') | 277 help='Verbose level (multiple times for more)') |
| 278 parser.add_argument('--disable-downgrade', |
| 279 action='store_false', |
| 280 default=True, |
| 281 dest='allow_downgrade', |
| 282 help='Disable install of apk with lower version number' |
| 283 'than the version already on the device.') |
| 275 | 284 |
| 276 args = parser.parse_args() | 285 args = parser.parse_args() |
| 277 | 286 |
| 278 run_tests_helper.SetLogLevel(args.verbose_count) | 287 run_tests_helper.SetLogLevel(args.verbose_count) |
| 279 constants.SetBuildType('Debug') | 288 constants.SetBuildType('Debug') |
| 280 if args.output_directory: | 289 if args.output_directory: |
| 281 constants.SetOutputDirectory(args.output_directory) | 290 constants.SetOutputDirectory(args.output_directory) |
| 282 | 291 |
| 283 devil_chromium.Initialize(output_directory=constants.GetOutDirectory()) | 292 devil_chromium.Initialize(output_directory=constants.GetOutDirectory()) |
| 284 | 293 |
| 285 if args.dont_even_try: | 294 if args.dont_even_try: |
| 286 logging.fatal(args.dont_even_try) | 295 logging.fatal(args.dont_even_try) |
| 287 return 1 | 296 return 1 |
| 288 | 297 |
| 289 # Retries are annoying when commands fail for legitimate reasons. Might want | 298 # Retries are annoying when commands fail for legitimate reasons. Might want |
| 290 # to enable them if this is ever used on bots though. | 299 # to enable them if this is ever used on bots though. |
| 291 device = device_utils.DeviceUtils.HealthyDevices( | 300 device = device_utils.DeviceUtils.HealthyDevices( |
| 292 device_arg=args.device, | 301 device_arg=args.device, |
| 293 default_retries=0, | 302 default_retries=0, |
| 294 enable_device_files_cache=True)[0] | 303 enable_device_files_cache=True)[0] |
| 295 | 304 |
| 296 apk = apk_helper.ToHelper(args.apk_path) | 305 apk = apk_helper.ToHelper(args.apk_path) |
| 297 if args.uninstall: | 306 if args.uninstall: |
| 298 Uninstall(device, apk.GetPackageName(), enable_device_cache=args.cache) | 307 Uninstall(device, apk.GetPackageName(), enable_device_cache=args.cache) |
| 299 else: | 308 else: |
| 300 Install(device, apk, split_globs=args.splits, native_libs=args.native_libs, | 309 Install(device, apk, split_globs=args.splits, native_libs=args.native_libs, |
| 301 dex_files=args.dex_files, enable_device_cache=args.cache, | 310 dex_files=args.dex_files, enable_device_cache=args.cache, |
| 302 use_concurrency=args.threading, | 311 use_concurrency=args.threading, |
| 303 show_proguard_warning=args.show_proguard_warning) | 312 show_proguard_warning=args.show_proguard_warning, |
| 313 allow_downgrade=args.allow_downgrade) |
| 304 | 314 |
| 305 | 315 |
| 306 if __name__ == '__main__': | 316 if __name__ == '__main__': |
| 307 sys.exit(main()) | 317 sys.exit(main()) |
| OLD | NEW |