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 with device_temp_file.DeviceTempFile(self.adb) as tmp: | |
399 self.WriteFile(tmp.name, _RESTART_ADBD_SCRIPT) | |
400 self.RunShellCommand(['sh', tmp.name], as_root=True, check_return=True) | |
perezju
2015/03/30 16:01:16
wouldn't RunShellCommand(_RESTART_ADBD_SCRIPT, ...
jbudorick
2015/03/30 16:42:14
Not quite (which is probably what I tried before t
| |
401 self.adb.WaitForDevice() | |
402 | |
385 REBOOT_DEFAULT_TIMEOUT = 10 * _DEFAULT_TIMEOUT | 403 REBOOT_DEFAULT_TIMEOUT = 10 * _DEFAULT_TIMEOUT |
386 REBOOT_DEFAULT_RETRIES = _DEFAULT_RETRIES | 404 REBOOT_DEFAULT_RETRIES = _DEFAULT_RETRIES |
387 | 405 |
388 @decorators.WithTimeoutAndRetriesDefaults( | 406 @decorators.WithTimeoutAndRetriesDefaults( |
389 REBOOT_DEFAULT_TIMEOUT, | 407 REBOOT_DEFAULT_TIMEOUT, |
390 REBOOT_DEFAULT_RETRIES) | 408 REBOOT_DEFAULT_RETRIES) |
391 def Reboot(self, block=True, wifi=False, timeout=None, retries=None): | 409 def Reboot(self, block=True, wifi=False, timeout=None, retries=None): |
392 """Reboot the device. | 410 """Reboot the device. |
393 | 411 |
394 Args: | 412 Args: |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
505 def do_run(cmd): | 523 def do_run(cmd): |
506 try: | 524 try: |
507 return self.adb.Shell(cmd) | 525 return self.adb.Shell(cmd) |
508 except device_errors.AdbCommandFailedError as exc: | 526 except device_errors.AdbCommandFailedError as exc: |
509 if check_return: | 527 if check_return: |
510 raise | 528 raise |
511 else: | 529 else: |
512 return exc.output | 530 return exc.output |
513 | 531 |
514 if not isinstance(cmd, basestring): | 532 if not isinstance(cmd, basestring): |
515 cmd = ' '.join(cmd_helper.SingleQuote(s) for s in cmd) | 533 cmd = ' '.join(cmd_helper.SingleQuote(s) for s in cmd if s) |
perezju
2015/03/30 16:01:16
Not sure if we want to do this. A client may have
jbudorick
2015/03/30 16:42:14
I was trying to think of cases where a client woul
| |
516 if env: | 534 if env: |
517 env = ' '.join(env_quote(k, v) for k, v in env.iteritems()) | 535 env = ' '.join(env_quote(k, v) for k, v in env.iteritems()) |
518 cmd = '%s %s' % (env, cmd) | 536 cmd = '%s %s' % (env, cmd) |
519 if cwd: | 537 if cwd: |
520 cmd = 'cd %s && %s' % (cmd_helper.SingleQuote(cwd), cmd) | 538 cmd = 'cd %s && %s' % (cmd_helper.SingleQuote(cwd), cmd) |
521 if as_root and self.NeedsSU(): | 539 if as_root and self.NeedsSU(): |
522 # "su -c sh -c" allows using shell features in |cmd| | 540 # "su -c sh -c" allows using shell features in |cmd| |
523 cmd = 'su -c sh -c %s' % cmd_helper.SingleQuote(cmd) | 541 cmd = 'su -c sh -c %s' % cmd_helper.SingleQuote(cmd) |
524 if timeout is None: | 542 if timeout is None: |
525 timeout = self._default_timeout | 543 timeout = self._default_timeout |
(...skipping 1115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1641 """ | 1659 """ |
1642 if not devices: | 1660 if not devices: |
1643 devices = adb_wrapper.AdbWrapper.GetDevices() | 1661 devices = adb_wrapper.AdbWrapper.GetDevices() |
1644 if not devices: | 1662 if not devices: |
1645 raise device_errors.NoDevicesError() | 1663 raise device_errors.NoDevicesError() |
1646 devices = [d if isinstance(d, cls) else cls(d) for d in devices] | 1664 devices = [d if isinstance(d, cls) else cls(d) for d in devices] |
1647 if async: | 1665 if async: |
1648 return parallelizer.Parallelizer(devices) | 1666 return parallelizer.Parallelizer(devices) |
1649 else: | 1667 else: |
1650 return parallelizer.SyncParallelizer(devices) | 1668 return parallelizer.SyncParallelizer(devices) |
OLD | NEW |