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=unused-argument | 9 # pylint: disable=unused-argument |
10 | 10 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 'enable_command': ( | 65 'enable_command': ( |
66 'echo 0x4A > /sys/kernel/debug/bq24192/INPUT_SRC_CONT && ' | 66 'echo 0x4A > /sys/kernel/debug/bq24192/INPUT_SRC_CONT && ' |
67 'echo 1 > /sys/class/power_supply/usb/online'), | 67 'echo 1 > /sys/class/power_supply/usb/online'), |
68 'disable_command': ( | 68 'disable_command': ( |
69 'echo 0xCA > /sys/kernel/debug/bq24192/INPUT_SRC_CONT && ' | 69 'echo 0xCA > /sys/kernel/debug/bq24192/INPUT_SRC_CONT && ' |
70 'chmod 644 /sys/class/power_supply/usb/online && ' | 70 'chmod 644 /sys/class/power_supply/usb/online && ' |
71 'echo 0 > /sys/class/power_supply/usb/online'), | 71 'echo 0 > /sys/class/power_supply/usb/online'), |
72 }, | 72 }, |
73 ] | 73 ] |
74 | 74 |
| 75 # This must be done in a single shell command. |
| 76 _RESTART_ADBD_SCRIPT = """ |
| 77 function restart() { |
| 78 stop adbd |
| 79 start adbd |
| 80 } |
| 81 |
| 82 restart & |
| 83 """ |
| 84 |
| 85 |
75 @decorators.WithExplicitTimeoutAndRetries( | 86 @decorators.WithExplicitTimeoutAndRetries( |
76 _DEFAULT_TIMEOUT, _DEFAULT_RETRIES) | 87 _DEFAULT_TIMEOUT, _DEFAULT_RETRIES) |
77 def GetAVDs(): | 88 def GetAVDs(): |
78 """Returns a list of Android Virtual Devices. | 89 """Returns a list of Android Virtual Devices. |
79 | 90 |
80 Returns: | 91 Returns: |
81 A list containing the configured AVDs. | 92 A list containing the configured AVDs. |
82 """ | 93 """ |
83 lines = cmd_helper.GetCmdOutput([ | 94 lines = cmd_helper.GetCmdOutput([ |
84 os.path.join(constants.ANDROID_SDK_ROOT, 'tools', 'android'), | 95 os.path.join(constants.ANDROID_SDK_ROOT, 'tools', 'android'), |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 return 'Wi-Fi is enabled' in self.RunShellCommand(['dumpsys', 'wifi'], | 386 return 'Wi-Fi is enabled' in self.RunShellCommand(['dumpsys', 'wifi'], |
376 check_return=False) | 387 check_return=False) |
377 | 388 |
378 self.adb.WaitForDevice() | 389 self.adb.WaitForDevice() |
379 timeout_retry.WaitFor(sd_card_ready) | 390 timeout_retry.WaitFor(sd_card_ready) |
380 timeout_retry.WaitFor(pm_ready) | 391 timeout_retry.WaitFor(pm_ready) |
381 timeout_retry.WaitFor(boot_completed) | 392 timeout_retry.WaitFor(boot_completed) |
382 if wifi: | 393 if wifi: |
383 timeout_retry.WaitFor(wifi_enabled) | 394 timeout_retry.WaitFor(wifi_enabled) |
384 | 395 |
| 396 @decorators.WithTimeoutAndRetriesFromInstance() |
| 397 def RestartAdbd(self, timeout=None, retries=None): |
| 398 self.RunShellCommand(['sh', '-c', _RESTART_ADBD_SCRIPT], |
| 399 as_root=True, check_return=True) |
| 400 self.adb.WaitForDevice() |
| 401 |
385 REBOOT_DEFAULT_TIMEOUT = 10 * _DEFAULT_TIMEOUT | 402 REBOOT_DEFAULT_TIMEOUT = 10 * _DEFAULT_TIMEOUT |
386 REBOOT_DEFAULT_RETRIES = _DEFAULT_RETRIES | 403 REBOOT_DEFAULT_RETRIES = _DEFAULT_RETRIES |
387 | 404 |
388 @decorators.WithTimeoutAndRetriesDefaults( | 405 @decorators.WithTimeoutAndRetriesDefaults( |
389 REBOOT_DEFAULT_TIMEOUT, | 406 REBOOT_DEFAULT_TIMEOUT, |
390 REBOOT_DEFAULT_RETRIES) | 407 REBOOT_DEFAULT_RETRIES) |
391 def Reboot(self, block=True, wifi=False, timeout=None, retries=None): | 408 def Reboot(self, block=True, wifi=False, timeout=None, retries=None): |
392 """Reboot the device. | 409 """Reboot the device. |
393 | 410 |
394 Args: | 411 Args: |
(...skipping 1246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1641 """ | 1658 """ |
1642 if not devices: | 1659 if not devices: |
1643 devices = adb_wrapper.AdbWrapper.GetDevices() | 1660 devices = adb_wrapper.AdbWrapper.GetDevices() |
1644 if not devices: | 1661 if not devices: |
1645 raise device_errors.NoDevicesError() | 1662 raise device_errors.NoDevicesError() |
1646 devices = [d if isinstance(d, cls) else cls(d) for d in devices] | 1663 devices = [d if isinstance(d, cls) else cls(d) for d in devices] |
1647 if async: | 1664 if async: |
1648 return parallelizer.Parallelizer(devices) | 1665 return parallelizer.Parallelizer(devices) |
1649 else: | 1666 else: |
1650 return parallelizer.SyncParallelizer(devices) | 1667 return parallelizer.SyncParallelizer(devices) |
OLD | NEW |