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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 else: | 168 else: |
169 raise ValueError('Unsupported device value: %r' % device) | 169 raise ValueError('Unsupported device value: %r' % device) |
170 self._commands_installed = None | 170 self._commands_installed = None |
171 self._default_timeout = default_timeout | 171 self._default_timeout = default_timeout |
172 self._default_retries = default_retries | 172 self._default_retries = default_retries |
173 self._cache = {} | 173 self._cache = {} |
174 self._client_caches = {} | 174 self._client_caches = {} |
175 assert hasattr(self, decorators.DEFAULT_TIMEOUT_ATTR) | 175 assert hasattr(self, decorators.DEFAULT_TIMEOUT_ATTR) |
176 assert hasattr(self, decorators.DEFAULT_RETRIES_ATTR) | 176 assert hasattr(self, decorators.DEFAULT_RETRIES_ATTR) |
177 | 177 |
| 178 def __eq__(self, other): |
| 179 """Checks whether |other| refers to the same device as |self|. |
| 180 |
| 181 Args: |
| 182 other: The object to compare to. This can be a basestring, an instance |
| 183 of adb_wrapper.AdbWrapper, or an instance of DeviceUtils. |
| 184 Returns: |
| 185 Whether |other| refers to the same device as |self|. |
| 186 """ |
| 187 return self.adb.GetDeviceSerial() == str(other) |
| 188 |
| 189 def __lt__(self, other): |
| 190 """Compares two instances of DeviceUtils. |
| 191 |
| 192 This merely compares their serial numbers. |
| 193 |
| 194 Args: |
| 195 other: The instance of DeviceUtils to compare to. |
| 196 Returns: |
| 197 Whether |self| is less than |other|. |
| 198 """ |
| 199 return self.adb.GetDeviceSerial() < other.adb.GetDeviceSerial() |
| 200 |
178 def __str__(self): | 201 def __str__(self): |
179 """Returns the device serial.""" | 202 """Returns the device serial.""" |
180 return self.adb.GetDeviceSerial() | 203 return self.adb.GetDeviceSerial() |
181 | 204 |
182 @decorators.WithTimeoutAndRetriesFromInstance() | 205 @decorators.WithTimeoutAndRetriesFromInstance() |
183 def IsOnline(self, timeout=None, retries=None): | 206 def IsOnline(self, timeout=None, retries=None): |
184 """Checks whether the device is online. | 207 """Checks whether the device is online. |
185 | 208 |
186 Args: | 209 Args: |
187 timeout: timeout in seconds | 210 timeout: timeout in seconds |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 self._WriteFileWithPush(script.name, cmd) | 551 self._WriteFileWithPush(script.name, cmd) |
529 logging.info('Large shell command will be run from file: %s ...', | 552 logging.info('Large shell command will be run from file: %s ...', |
530 cmd[:100]) | 553 cmd[:100]) |
531 return handle_check_return('sh %s' % script.name_quoted) | 554 return handle_check_return('sh %s' % script.name_quoted) |
532 | 555 |
533 def handle_large_output(cmd, large_output_mode): | 556 def handle_large_output(cmd, large_output_mode): |
534 if large_output_mode: | 557 if large_output_mode: |
535 with device_temp_file.DeviceTempFile(self.adb) as large_output_file: | 558 with device_temp_file.DeviceTempFile(self.adb) as large_output_file: |
536 cmd = '%s > %s' % (cmd, large_output_file.name) | 559 cmd = '%s > %s' % (cmd, large_output_file.name) |
537 logging.info('Large output mode enabled. Will write output to device ' | 560 logging.info('Large output mode enabled. Will write output to device ' |
538 ' and read results from file.') | 561 'and read results from file.') |
539 handle_large_command(cmd) | 562 handle_large_command(cmd) |
540 return self.ReadFile(large_output_file.name) | 563 return self.ReadFile(large_output_file.name) |
541 else: | 564 else: |
542 try: | 565 try: |
543 return handle_large_command(cmd) | 566 return handle_large_command(cmd) |
544 except device_errors.AdbCommandFailedError as exc: | 567 except device_errors.AdbCommandFailedError as exc: |
545 if exc.status is None: | 568 if exc.status is None: |
546 logging.exception('No output found for %s', cmd) | 569 logging.exception('No output found for %s', cmd) |
547 logging.warning('Attempting to run in large_output mode.') | 570 logging.warning('Attempting to run in large_output mode.') |
548 logging.warning('Use RunShellCommand(..., large_output=True) for ' | 571 logging.warning('Use RunShellCommand(..., large_output=True) for ' |
(...skipping 1035 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1584 blacklist = device_blacklist.ReadBlacklist() | 1607 blacklist = device_blacklist.ReadBlacklist() |
1585 def blacklisted(adb): | 1608 def blacklisted(adb): |
1586 if adb.GetDeviceSerial() in blacklist: | 1609 if adb.GetDeviceSerial() in blacklist: |
1587 logging.warning('Device %s is blacklisted.', adb.GetDeviceSerial()) | 1610 logging.warning('Device %s is blacklisted.', adb.GetDeviceSerial()) |
1588 return True | 1611 return True |
1589 return False | 1612 return False |
1590 | 1613 |
1591 return [cls(adb) for adb in adb_wrapper.AdbWrapper.Devices() | 1614 return [cls(adb) for adb in adb_wrapper.AdbWrapper.Devices() |
1592 if not blacklisted(adb)] | 1615 if not blacklisted(adb)] |
1593 | 1616 |
OLD | NEW |