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 | |
86 @decorators.WithExplicitTimeoutAndRetries( | 75 @decorators.WithExplicitTimeoutAndRetries( |
87 _DEFAULT_TIMEOUT, _DEFAULT_RETRIES) | 76 _DEFAULT_TIMEOUT, _DEFAULT_RETRIES) |
88 def GetAVDs(): | 77 def GetAVDs(): |
89 """Returns a list of Android Virtual Devices. | 78 """Returns a list of Android Virtual Devices. |
90 | 79 |
91 Returns: | 80 Returns: |
92 A list containing the configured AVDs. | 81 A list containing the configured AVDs. |
93 """ | 82 """ |
94 lines = cmd_helper.GetCmdOutput([ | 83 lines = cmd_helper.GetCmdOutput([ |
95 os.path.join(constants.ANDROID_SDK_ROOT, 'tools', 'android'), | 84 os.path.join(constants.ANDROID_SDK_ROOT, 'tools', 'android'), |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 return 'Wi-Fi is enabled' in self.RunShellCommand(['dumpsys', 'wifi'], | 376 return 'Wi-Fi is enabled' in self.RunShellCommand(['dumpsys', 'wifi'], |
388 check_return=False) | 377 check_return=False) |
389 | 378 |
390 self.adb.WaitForDevice() | 379 self.adb.WaitForDevice() |
391 timeout_retry.WaitFor(sd_card_ready) | 380 timeout_retry.WaitFor(sd_card_ready) |
392 timeout_retry.WaitFor(pm_ready) | 381 timeout_retry.WaitFor(pm_ready) |
393 timeout_retry.WaitFor(boot_completed) | 382 timeout_retry.WaitFor(boot_completed) |
394 if wifi: | 383 if wifi: |
395 timeout_retry.WaitFor(wifi_enabled) | 384 timeout_retry.WaitFor(wifi_enabled) |
396 | 385 |
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 | |
404 REBOOT_DEFAULT_TIMEOUT = 10 * _DEFAULT_TIMEOUT | 386 REBOOT_DEFAULT_TIMEOUT = 10 * _DEFAULT_TIMEOUT |
405 REBOOT_DEFAULT_RETRIES = _DEFAULT_RETRIES | 387 REBOOT_DEFAULT_RETRIES = _DEFAULT_RETRIES |
406 | 388 |
407 @decorators.WithTimeoutAndRetriesDefaults( | 389 @decorators.WithTimeoutAndRetriesDefaults( |
408 REBOOT_DEFAULT_TIMEOUT, | 390 REBOOT_DEFAULT_TIMEOUT, |
409 REBOOT_DEFAULT_RETRIES) | 391 REBOOT_DEFAULT_RETRIES) |
410 def Reboot(self, block=True, wifi=False, timeout=None, retries=None): | 392 def Reboot(self, block=True, wifi=False, timeout=None, retries=None): |
411 """Reboot the device. | 393 """Reboot the device. |
412 | 394 |
413 Args: | 395 Args: |
(...skipping 1262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1676 """Returns client cache.""" | 1658 """Returns client cache.""" |
1677 if client_name not in self._client_caches: | 1659 if client_name not in self._client_caches: |
1678 self._client_caches[client_name] = {} | 1660 self._client_caches[client_name] = {} |
1679 return self._client_caches[client_name] | 1661 return self._client_caches[client_name] |
1680 | 1662 |
1681 def _ClearCache(self): | 1663 def _ClearCache(self): |
1682 """Clears all caches.""" | 1664 """Clears all caches.""" |
1683 for client in self._client_caches: | 1665 for client in self._client_caches: |
1684 self._client_caches[client].clear() | 1666 self._client_caches[client].clear() |
1685 self._cache.clear() | 1667 self._cache.clear() |
OLD | NEW |