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 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 return 'Wi-Fi is enabled' in self.RunShellCommand(['dumpsys', 'wifi'], | 387 return 'Wi-Fi is enabled' in self.RunShellCommand(['dumpsys', 'wifi'], |
377 check_return=False) | 388 check_return=False) |
378 | 389 |
379 self.adb.WaitForDevice() | 390 self.adb.WaitForDevice() |
380 timeout_retry.WaitFor(sd_card_ready) | 391 timeout_retry.WaitFor(sd_card_ready) |
381 timeout_retry.WaitFor(pm_ready) | 392 timeout_retry.WaitFor(pm_ready) |
382 timeout_retry.WaitFor(boot_completed) | 393 timeout_retry.WaitFor(boot_completed) |
383 if wifi: | 394 if wifi: |
384 timeout_retry.WaitFor(wifi_enabled) | 395 timeout_retry.WaitFor(wifi_enabled) |
385 | 396 |
| 397 @decorators.WithTimeoutAndRetriesFromInstance() |
| 398 def RestartAdbd(self, timeout=None, retries=None): |
| 399 with device_temp_file.DeviceTempFile(self.adb) as tmp: |
| 400 self.WriteFile(tmp.name, _RESTART_ADBD_SCRIPT) |
| 401 self.RunShellCommand(['sh', tmp.name], as_root=True, check_return=True) |
| 402 self.adb.WaitForDevice() |
| 403 |
386 REBOOT_DEFAULT_TIMEOUT = 10 * _DEFAULT_TIMEOUT | 404 REBOOT_DEFAULT_TIMEOUT = 10 * _DEFAULT_TIMEOUT |
387 REBOOT_DEFAULT_RETRIES = _DEFAULT_RETRIES | 405 REBOOT_DEFAULT_RETRIES = _DEFAULT_RETRIES |
388 | 406 |
389 @decorators.WithTimeoutAndRetriesDefaults( | 407 @decorators.WithTimeoutAndRetriesDefaults( |
390 REBOOT_DEFAULT_TIMEOUT, | 408 REBOOT_DEFAULT_TIMEOUT, |
391 REBOOT_DEFAULT_RETRIES) | 409 REBOOT_DEFAULT_RETRIES) |
392 def Reboot(self, block=True, wifi=False, timeout=None, retries=None): | 410 def Reboot(self, block=True, wifi=False, timeout=None, retries=None): |
393 """Reboot the device. | 411 """Reboot the device. |
394 | 412 |
395 Args: | 413 Args: |
(...skipping 1262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1658 """Returns client cache.""" | 1676 """Returns client cache.""" |
1659 if client_name not in self._client_caches: | 1677 if client_name not in self._client_caches: |
1660 self._client_caches[client_name] = {} | 1678 self._client_caches[client_name] = {} |
1661 return self._client_caches[client_name] | 1679 return self._client_caches[client_name] |
1662 | 1680 |
1663 def _ClearCache(self): | 1681 def _ClearCache(self): |
1664 """Clears all caches.""" | 1682 """Clears all caches.""" |
1665 for client in self._client_caches: | 1683 for client in self._client_caches: |
1666 self._client_caches[client].clear() | 1684 self._client_caches[client].clear() |
1667 self._cache.clear() | 1685 self._cache.clear() |
OLD | NEW |