| 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 import atexit | 5 import atexit |
| 6 import hashlib | 6 import hashlib |
| 7 import json | 7 import json |
| 8 import logging | 8 import logging |
| 9 import os | 9 import os |
| 10 import os.path | 10 import os.path |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 self.adb_running_as_root = False | 192 self.adb_running_as_root = False |
| 193 | 193 |
| 194 return self.adb_running_as_root | 194 return self.adb_running_as_root |
| 195 | 195 |
| 196 def _is_shell_package_installed(self): | 196 def _is_shell_package_installed(self): |
| 197 # Adb should print one line if the package is installed and return empty | 197 # Adb should print one line if the package is installed and return empty |
| 198 # string otherwise. | 198 # string otherwise. |
| 199 return len(subprocess.check_output(self._adb_command([ | 199 return len(subprocess.check_output(self._adb_command([ |
| 200 'shell', 'pm', 'list', 'packages', _MOJO_SHELL_PACKAGE_NAME]))) > 0 | 200 'shell', 'pm', 'list', 'packages', _MOJO_SHELL_PACKAGE_NAME]))) > 0 |
| 201 | 201 |
| 202 def check_device(self): | 202 def check_device(self, require_root=False): |
| 203 """Verifies if the device configuration allows adb to run. | 203 """Verifies if the device configuration allows adb to run. |
| 204 | 204 |
| 205 If a target device was indicated in the constructor, it checks that the | 205 If a target device was indicated in the constructor, it checks that the |
| 206 device is available. Otherwise, it checks that there is exactly one | 206 device is available. Otherwise, it checks that there is exactly one |
| 207 available device. | 207 available device. |
| 208 | 208 |
| 209 Returns: | 209 Returns: |
| 210 A tuple of (result, msg). |result| is True iff if the device is correctly | 210 A tuple of (result, msg). |result| is True iff if the device is correctly |
| 211 configured and False otherwise. |msg| is the reason for failure if | 211 configured and False otherwise. |msg| is the reason for failure if |
| 212 |result| is False and None otherwise. | 212 |result| is False and None otherwise. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 227 if len(device_list) > 1: | 227 if len(device_list) > 1: |
| 228 return False, ('More than one device connected and target device not ' | 228 return False, ('More than one device connected and target device not ' |
| 229 'specified.') | 229 'specified.') |
| 230 | 230 |
| 231 if not len(device_list): | 231 if not len(device_list): |
| 232 return False, 'No devices connected.' | 232 return False, 'No devices connected.' |
| 233 | 233 |
| 234 if not device_list[0].endswith('device'): | 234 if not device_list[0].endswith('device'): |
| 235 return False, 'Connected device is not available.' | 235 return False, 'Connected device is not available.' |
| 236 | 236 |
| 237 if require_root and not self._run_adb_as_root(): |
| 238 return False, 'Cannot run on an unrooted device.' |
| 239 |
| 237 return True, None | 240 return True, None |
| 238 | 241 |
| 239 def install_apk(self, shell_apk_path): | 242 def install_apk(self, shell_apk_path): |
| 240 """Installs the apk on the device. | 243 """Installs the apk on the device. |
| 241 | 244 |
| 242 This method computes checksum of the APK and skips the installation if the | 245 This method computes checksum of the APK and skips the installation if the |
| 243 fingerprint matches the one saved on the device upon the previous | 246 fingerprint matches the one saved on the device upon the previous |
| 244 installation. | 247 installation. |
| 245 | 248 |
| 246 Args: | 249 Args: |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 Results.output = rf.read() | 421 Results.output = rf.read() |
| 419 | 422 |
| 420 run_thread = threading.Thread(target=do_run) | 423 run_thread = threading.Thread(target=do_run) |
| 421 run_thread.start() | 424 run_thread.start() |
| 422 run_thread.join(timeout) | 425 run_thread.join(timeout) |
| 423 | 426 |
| 424 if run_thread.is_alive(): | 427 if run_thread.is_alive(): |
| 425 self.stop_shell() | 428 self.stop_shell() |
| 426 return None, Results.output, True | 429 return None, Results.output, True |
| 427 return None, Results.output, False | 430 return None, Results.output, False |
| OLD | NEW |