| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Provides a variety of device interactions based on adb. | 5 """Provides a variety of device interactions based on adb. |
| 6 | 6 |
| 7 Eventually, this will be based on adb_wrapper. | 7 Eventually, this will be based on adb_wrapper. |
| 8 """ | 8 """ |
| 9 # pylint: disable=W0613 | 9 # pylint: disable=W0613 |
| 10 | 10 |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 Same as for |WaitUntilFullyBooted|. | 176 Same as for |WaitUntilFullyBooted|. |
| 177 """ | 177 """ |
| 178 if timeout is None: | 178 if timeout is None: |
| 179 timeout = self._default_timeout | 179 timeout = self._default_timeout |
| 180 self.old_interface.WaitForSystemBootCompleted(timeout) | 180 self.old_interface.WaitForSystemBootCompleted(timeout) |
| 181 self.old_interface.WaitForDevicePm() | 181 self.old_interface.WaitForDevicePm() |
| 182 self.old_interface.WaitForSdCardReady(timeout) | 182 self.old_interface.WaitForSdCardReady(timeout) |
| 183 if wifi: | 183 if wifi: |
| 184 while not 'Wi-Fi is enabled' in ( | 184 while not 'Wi-Fi is enabled' in ( |
| 185 self._RunShellCommandImpl('dumpsys wifi')): | 185 self._RunShellCommandImpl('dumpsys wifi')): |
| 186 time.sleep(0.1) | 186 time.sleep(1) |
| 187 |
| 188 REBOOT_DEFAULT_TIMEOUT = 10 * _DEFAULT_TIMEOUT |
| 189 REBOOT_DEFAULT_RETRIES = _DEFAULT_RETRIES |
| 187 | 190 |
| 188 @decorators.WithTimeoutAndRetriesDefaults( | 191 @decorators.WithTimeoutAndRetriesDefaults( |
| 189 10 * _DEFAULT_TIMEOUT, _DEFAULT_RETRIES) | 192 REBOOT_DEFAULT_TIMEOUT, |
| 193 REBOOT_DEFAULT_RETRIES) |
| 190 def Reboot(self, block=True, timeout=None, retries=None): | 194 def Reboot(self, block=True, timeout=None, retries=None): |
| 191 """Reboot the device. | 195 """Reboot the device. |
| 192 | 196 |
| 193 Args: | 197 Args: |
| 194 block: A boolean indicating if we should wait for the reboot to complete. | 198 block: A boolean indicating if we should wait for the reboot to complete. |
| 195 timeout: Same as for |IsOnline|. | 199 timeout: Same as for |IsOnline|. |
| 196 retries: Same as for |IsOnline|. | 200 retries: Same as for |IsOnline|. |
| 197 """ | 201 """ |
| 198 self.old_interface.Reboot() | 202 self.old_interface.Reboot() |
| 199 if block: | 203 if block: |
| 200 self._WaitUntilFullyBootedImpl(timeout=timeout) | 204 self._WaitUntilFullyBootedImpl(timeout=timeout) |
| 201 | 205 |
| 206 INSTALL_DEFAULT_TIMEOUT = 4 * _DEFAULT_TIMEOUT |
| 207 INSTALL_DEFAULT_RETRIES = _DEFAULT_RETRIES |
| 208 |
| 202 @decorators.WithTimeoutAndRetriesDefaults( | 209 @decorators.WithTimeoutAndRetriesDefaults( |
| 203 4 * _DEFAULT_TIMEOUT, _DEFAULT_RETRIES) | 210 INSTALL_DEFAULT_TIMEOUT, |
| 211 INSTALL_DEFAULT_RETRIES) |
| 204 def Install(self, apk_path, reinstall=False, timeout=None, retries=None): | 212 def Install(self, apk_path, reinstall=False, timeout=None, retries=None): |
| 205 """Install an APK. | 213 """Install an APK. |
| 206 | 214 |
| 207 Noop if an identical APK is already installed. | 215 Noop if an identical APK is already installed. |
| 208 | 216 |
| 209 Args: | 217 Args: |
| 210 apk_path: A string containing the path to the APK to install. | 218 apk_path: A string containing the path to the APK to install. |
| 211 reinstall: A boolean indicating if we should keep any existing app data. | 219 reinstall: A boolean indicating if we should keep any existing app data. |
| 212 timeout: Same as for |IsOnline|. | 220 timeout: Same as for |IsOnline|. |
| 213 retries: Same as for |IsOnline|. | 221 retries: Same as for |IsOnline|. |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 """ | 294 """ |
| 287 if isinstance(cmd, list): | 295 if isinstance(cmd, list): |
| 288 cmd = ' '.join(cmd) | 296 cmd = ' '.join(cmd) |
| 289 if root and not self.HasRoot(): | 297 if root and not self.HasRoot(): |
| 290 cmd = 'su -c %s' % cmd | 298 cmd = 'su -c %s' % cmd |
| 291 if check_return: | 299 if check_return: |
| 292 code, output = self.old_interface.GetShellCommandStatusAndOutput( | 300 code, output = self.old_interface.GetShellCommandStatusAndOutput( |
| 293 cmd, timeout_time=timeout) | 301 cmd, timeout_time=timeout) |
| 294 if int(code) != 0: | 302 if int(code) != 0: |
| 295 raise device_errors.CommandFailedError( | 303 raise device_errors.CommandFailedError( |
| 296 cmd, 'Nonzero exit code (%d)' % code) | 304 cmd.split(), 'Nonzero exit code (%d)' % code) |
| 297 else: | 305 else: |
| 298 output = self.old_interface.RunShellCommand(cmd, timeout_time=timeout) | 306 output = self.old_interface.RunShellCommand(cmd, timeout_time=timeout) |
| 299 return output | 307 return output |
| 300 | 308 |
| 301 def __str__(self): | 309 def __str__(self): |
| 302 """Returns the device serial.""" | 310 """Returns the device serial.""" |
| 303 return self.old_interface.GetDevice() | 311 return self.old_interface.GetDevice() |
| 304 | 312 |
| 305 @staticmethod | 313 @staticmethod |
| 306 def parallel(devices=None, async=False): | 314 def parallel(devices=None, async=False): |
| (...skipping 12 matching lines...) Expand all Loading... |
| 319 A Parallelizer operating over |devices|. | 327 A Parallelizer operating over |devices|. |
| 320 """ | 328 """ |
| 321 if not devices or len(devices) == 0: | 329 if not devices or len(devices) == 0: |
| 322 devices = pylib.android_commands.GetAttachedDevices() | 330 devices = pylib.android_commands.GetAttachedDevices() |
| 323 parallelizer_type = (parallelizer.Parallelizer if async | 331 parallelizer_type = (parallelizer.Parallelizer if async |
| 324 else parallelizer.SyncParallelizer) | 332 else parallelizer.SyncParallelizer) |
| 325 return parallelizer_type([ | 333 return parallelizer_type([ |
| 326 d if isinstance(d, DeviceUtils) else DeviceUtils(d) | 334 d if isinstance(d, DeviceUtils) else DeviceUtils(d) |
| 327 for d in devices]) | 335 for d in devices]) |
| 328 | 336 |
| OLD | NEW |