Chromium Code Reviews| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 'enable_command': ( | 62 'enable_command': ( |
| 63 'echo 0x4A > /sys/kernel/debug/bq24192/INPUT_SRC_CONT && ' | 63 'echo 0x4A > /sys/kernel/debug/bq24192/INPUT_SRC_CONT && ' |
| 64 'echo 1 > /sys/class/power_supply/usb/online'), | 64 'echo 1 > /sys/class/power_supply/usb/online'), |
| 65 'disable_command': ( | 65 'disable_command': ( |
| 66 'echo 0xCA > /sys/kernel/debug/bq24192/INPUT_SRC_CONT && ' | 66 'echo 0xCA > /sys/kernel/debug/bq24192/INPUT_SRC_CONT && ' |
| 67 'chmod 644 /sys/class/power_supply/usb/online && ' | 67 'chmod 644 /sys/class/power_supply/usb/online && ' |
| 68 'echo 0 > /sys/class/power_supply/usb/online'), | 68 'echo 0 > /sys/class/power_supply/usb/online'), |
| 69 }, | 69 }, |
| 70 ] | 70 ] |
| 71 | 71 |
| 72 _DUMPSYS_BATTERY_DISABLED = ' (UPDATES STOPPED -- use \'reset\' to restart)' | |
| 72 | 73 |
| 73 @decorators.WithExplicitTimeoutAndRetries( | 74 @decorators.WithExplicitTimeoutAndRetries( |
| 74 _DEFAULT_TIMEOUT, _DEFAULT_RETRIES) | 75 _DEFAULT_TIMEOUT, _DEFAULT_RETRIES) |
| 75 def GetAVDs(): | 76 def GetAVDs(): |
| 76 """Returns a list of Android Virtual Devices. | 77 """Returns a list of Android Virtual Devices. |
| 77 | 78 |
| 78 Returns: | 79 Returns: |
| 79 A list containing the configured AVDs. | 80 A list containing the configured AVDs. |
| 80 """ | 81 """ |
| 81 lines = cmd_helper.GetCmdOutput([ | 82 lines = cmd_helper.GetCmdOutput([ |
| (...skipping 1325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1407 timeout: timeout in seconds | 1408 timeout: timeout in seconds |
| 1408 retries: number of retries | 1409 retries: number of retries |
| 1409 Returns: | 1410 Returns: |
| 1410 A dict containing various battery information as reported by dumpsys | 1411 A dict containing various battery information as reported by dumpsys |
| 1411 battery. | 1412 battery. |
| 1412 """ | 1413 """ |
| 1413 result = {} | 1414 result = {} |
| 1414 # Skip the first line, which is just a header. | 1415 # Skip the first line, which is just a header. |
| 1415 for line in self.RunShellCommand( | 1416 for line in self.RunShellCommand( |
| 1416 ['dumpsys', 'battery'], check_return=True)[1:]: | 1417 ['dumpsys', 'battery'], check_return=True)[1:]: |
| 1417 k, v = line.split(': ', 1) | 1418 # If usb charging has been disabled, an extra line of header exists. |
| 1418 result[k.strip()] = v.strip() | 1419 if line != _DUMPSYS_BATTERY_DISABLED: |
|
jbudorick
2015/03/09 21:49:55
If this line appears, is it the only thing printed
rnephew (Wrong account)
2015/03/09 23:58:09
The output looks like this:
Current Battery Servic
jbudorick
2015/03/10 00:04:43
Interesting, that's not what I expected.
I don't
rnephew (Wrong account)
2015/03/10 14:56:35
Done.
| |
| 1420 k, v = line.split(': ', 1) | |
| 1421 result[k.strip()] = v.strip() | |
| 1422 else: | |
| 1423 logging.warning('Dumpsys battery not recieving updates. ' | |
| 1424 'Run dumpsys battery reset if this is in error') | |
| 1419 return result | 1425 return result |
| 1420 | 1426 |
| 1421 @decorators.WithTimeoutAndRetriesFromInstance() | 1427 @decorators.WithTimeoutAndRetriesFromInstance() |
| 1422 def GetCharging(self, timeout=None, retries=None): | 1428 def GetCharging(self, timeout=None, retries=None): |
| 1423 """Gets the charging state of the device. | 1429 """Gets the charging state of the device. |
| 1424 | 1430 |
| 1425 Args: | 1431 Args: |
| 1426 timeout: timeout in seconds | 1432 timeout: timeout in seconds |
| 1427 retries: number of retries | 1433 retries: number of retries |
| 1428 Returns: | 1434 Returns: |
| 1429 True if the device is charging, false otherwise. | 1435 True if the device is charging, false otherwise. |
| 1430 """ | 1436 """ |
| 1431 battery_info = self.GetBatteryInfo() | 1437 battery_info = self.GetBatteryInfo() |
| 1432 for k in ('AC powered', 'USB powered', 'Wireless powered'): | 1438 for k in ('AC powered', 'USB powered', 'Wireless powered'): |
| 1433 if (k in battery_info and | 1439 if (k in battery_info and |
| 1434 battery_info[k].lower() in ('true', '1', 'yes')): | 1440 battery_info[k].lower() in ('true', '1', 'yes')): |
| 1435 return True | 1441 return True |
| 1436 return False | 1442 return False |
| 1437 | 1443 |
| 1438 @decorators.WithTimeoutAndRetriesFromInstance() | 1444 @decorators.WithTimeoutAndRetriesFromInstance() |
| 1445 def SoftSetCharging(self, enabled, timeout=None, retries=None): | |
|
jbudorick
2015/03/09 21:49:55
I don't think this should be separate from SetChar
rnephew (Wrong account)
2015/03/09 23:58:09
Done.
| |
| 1446 """Enables or disables charging for dumpsys. Device still will | |
| 1447 silently be charging. Allows for power data collection through dumpsys. | |
| 1448 | |
| 1449 Args: | |
| 1450 enabled: A boolean indicating whether charging should be enabled or | |
| 1451 disabled. | |
| 1452 timeout: timeout in seconds | |
| 1453 retries: number of retries | |
| 1454 """ | |
| 1455 if enabled: | |
| 1456 command = 'dumpsys battery reset' | |
| 1457 else: | |
| 1458 command = 'dumpsys battery set usb 0' | |
| 1459 | |
| 1460 def set_and_verify_charging(): | |
| 1461 self.RunShellCommand(command, check_return=True) | |
| 1462 return self.GetCharging() == enabled | |
| 1463 | |
| 1464 timeout_retry.WaitFor(set_and_verify_charging, wait_period=1) | |
| 1465 | |
| 1466 @decorators.WithTimeoutAndRetriesFromInstance() | |
| 1439 def SetCharging(self, enabled, timeout=None, retries=None): | 1467 def SetCharging(self, enabled, timeout=None, retries=None): |
| 1440 """Enables or disables charging on the device. | 1468 """Enables or disables charging on the device. |
| 1441 | 1469 |
| 1442 Args: | 1470 Args: |
| 1443 enabled: A boolean indicating whether charging should be enabled or | 1471 enabled: A boolean indicating whether charging should be enabled or |
| 1444 disabled. | 1472 disabled. |
| 1445 timeout: timeout in seconds | 1473 timeout: timeout in seconds |
| 1446 retries: number of retries | 1474 retries: number of retries |
| 1447 """ | 1475 """ |
| 1448 if 'charging_config' not in self._cache: | 1476 if 'charging_config' not in self._cache: |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1519 """ | 1547 """ |
| 1520 if not devices: | 1548 if not devices: |
| 1521 devices = adb_wrapper.AdbWrapper.GetDevices() | 1549 devices = adb_wrapper.AdbWrapper.GetDevices() |
| 1522 if not devices: | 1550 if not devices: |
| 1523 raise device_errors.NoDevicesError() | 1551 raise device_errors.NoDevicesError() |
| 1524 devices = [d if isinstance(d, cls) else cls(d) for d in devices] | 1552 devices = [d if isinstance(d, cls) else cls(d) for d in devices] |
| 1525 if async: | 1553 if async: |
| 1526 return parallelizer.Parallelizer(devices) | 1554 return parallelizer.Parallelizer(devices) |
| 1527 else: | 1555 else: |
| 1528 return parallelizer.SyncParallelizer(devices) | 1556 return parallelizer.SyncParallelizer(devices) |
| OLD | NEW |