Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(261)

Side by Side Diff: build/android/pylib/android_commands.py

Issue 228253003: Update usb charging command to wait for it to succeed. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Follow review Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tools/telemetry/telemetry/core/platform/power_monitor/android_ds2784_power_monitor.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 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 an interface to communicate with the device via the adb command. 5 """Provides an interface to communicate with the device via the adb command.
6 6
7 Assumes adb binary is currently on system path. 7 Assumes adb binary is currently on system path.
8 """ 8 """
9 # pylint: disable-all 9 # pylint: disable-all
10 10
(...skipping 1852 matching lines...) Expand 10 before | Expand all | Expand 10 after
1863 return None 1863 return None
1864 1864
1865 def CanControlUsbCharging(self): 1865 def CanControlUsbCharging(self):
1866 return self._GetControlUsbChargingCommand() is not None 1866 return self._GetControlUsbChargingCommand() is not None
1867 1867
1868 def DisableUsbCharging(self): 1868 def DisableUsbCharging(self):
1869 command = self._GetControlUsbChargingCommand() 1869 command = self._GetControlUsbChargingCommand()
1870 if not command: 1870 if not command:
1871 raise Exception('Unable to act on usb charging.') 1871 raise Exception('Unable to act on usb charging.')
1872 disable_command = command['disable_command'] 1872 disable_command = command['disable_command']
1873 self.RunShellCommand(disable_command) 1873 # Do not loop directly on self.IsDeviceCharging to cut the number of calls
1874 # to the device.
1875 while True:
1876 self.RunShellCommand(disable_command)
1877 if not self.IsDeviceCharging():
1878 break
1874 1879
1875 def EnableUsbCharging(self): 1880 def EnableUsbCharging(self):
1876 command = self._GetControlUsbChargingCommand() 1881 command = self._GetControlUsbChargingCommand()
1877 if not command: 1882 if not command:
1878 raise Exception('Unable to act on usb charging.') 1883 raise Exception('Unable to act on usb charging.')
1879 disable_command = command['enable_command'] 1884 disable_command = command['enable_command']
1880 self.RunShellCommand(disable_command) 1885 # Do not loop directly on self.IsDeviceCharging to cut the number of calls
1886 # to the device.
1887 while True:
1888 self.RunShellCommand(disable_command)
1889 if self.IsDeviceCharging():
1890 break
1891
1892 def IsDeviceCharging(self):
1893 for line in self.RunShellCommand('dumpsys battery'):
1894 if 'powered: ' in line:
1895 if line.split('powered: ')[1] == 'true':
1896 return True
1881 1897
1882 1898
1883 class NewLineNormalizer(object): 1899 class NewLineNormalizer(object):
1884 """A file-like object to normalize EOLs to '\n'. 1900 """A file-like object to normalize EOLs to '\n'.
1885 1901
1886 Pexpect runs adb within a pseudo-tty device (see 1902 Pexpect runs adb within a pseudo-tty device (see
1887 http://www.noah.org/wiki/pexpect), so any '\n' printed by adb is written 1903 http://www.noah.org/wiki/pexpect), so any '\n' printed by adb is written
1888 as '\r\n' to the logfile. Since adb already uses '\r\n' to terminate 1904 as '\r\n' to the logfile. Since adb already uses '\r\n' to terminate
1889 lines, the log ends up having '\r\r\n' at the end of each line. This 1905 lines, the log ends up having '\r\r\n' at the end of each line. This
1890 filter replaces the above with a single '\n' in the data stream. 1906 filter replaces the above with a single '\n' in the data stream.
1891 """ 1907 """
1892 def __init__(self, output): 1908 def __init__(self, output):
1893 self._output = output 1909 self._output = output
1894 1910
1895 def write(self, data): 1911 def write(self, data):
1896 data = data.replace('\r\r\n', '\n') 1912 data = data.replace('\r\r\n', '\n')
1897 self._output.write(data) 1913 self._output.write(data)
1898 1914
1899 def flush(self): 1915 def flush(self):
1900 self._output.flush() 1916 self._output.flush()
OLDNEW
« no previous file with comments | « no previous file | tools/telemetry/telemetry/core/platform/power_monitor/android_ds2784_power_monitor.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698