| 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 logging | 5 import logging |
| 6 import os | 6 import os |
| 7 import subprocess |
| 7 | 8 |
| 8 from telemetry.core import util | 9 from telemetry.core import util |
| 9 from telemetry.internal.platform import cros_device | 10 from telemetry.internal.platform import cros_device |
| 10 from telemetry.internal.platform import device | 11 from telemetry.internal.platform import device |
| 11 from telemetry.internal.platform.profiler import monsoon | 12 from telemetry.internal.platform.profiler import monsoon |
| 12 | 13 |
| 13 from devil.android import device_blacklist | 14 from devil.android import device_blacklist |
| 14 from devil.android import device_errors | 15 from devil.android import device_errors |
| 15 from devil.android import device_utils | 16 from devil.android import device_utils |
| 16 from devil.android.sdk import adb_wrapper | 17 from devil.android.sdk import adb_wrapper |
| 17 | 18 |
| 18 | 19 |
| 20 def _KillStrayADBProcesses(): |
| 21 p = subprocess.Popen(['killall', 'adb']) |
| 22 p.communicate() |
| 23 if p.returncode: |
| 24 logging.info('No adb process was killed') |
| 25 else: |
| 26 logging.info('Some adb process was killed') |
| 27 |
| 28 |
| 29 |
| 19 class AndroidDevice(device.Device): | 30 class AndroidDevice(device.Device): |
| 20 """ Class represents information for connecting to an android device. | 31 """ Class represents information for connecting to an android device. |
| 21 | 32 |
| 22 Attributes: | 33 Attributes: |
| 23 device_id: the device's serial string created by adb to uniquely | 34 device_id: the device's serial string created by adb to uniquely |
| 24 identify an emulator/device instance. This string can be found by running | 35 identify an emulator/device instance. This string can be found by running |
| 25 'adb devices' command | 36 'adb devices' command |
| 26 enable_performance_mode: when this is set to True, android platform will be | 37 enable_performance_mode: when this is set to True, android platform will be |
| 27 set to high performance mode after browser is started. | 38 set to high performance mode after browser is started. |
| 28 """ | 39 """ |
| (...skipping 23 matching lines...) Expand all Loading... |
| 52 if d.IsOnline()] | 63 if d.IsOnline()] |
| 53 | 64 |
| 54 | 65 |
| 55 def GetDeviceSerials(blacklist): | 66 def GetDeviceSerials(blacklist): |
| 56 """Return the list of device serials of healthy devices. | 67 """Return the list of device serials of healthy devices. |
| 57 | 68 |
| 58 If a preferred device has been set with ANDROID_SERIAL, it will be first in | 69 If a preferred device has been set with ANDROID_SERIAL, it will be first in |
| 59 the returned list. The arguments specify what devices to include in the list. | 70 the returned list. The arguments specify what devices to include in the list. |
| 60 """ | 71 """ |
| 61 | 72 |
| 62 device_serials = _ListSerialsOfHealthyOnlineDevices(blacklist) | 73 try: |
| 74 device_serials = _ListSerialsOfHealthyOnlineDevices(blacklist) |
| 75 # Sometimes stray adb processes can interfere with using adb. |
| 76 except device_errors.AdbCommandFailedError: |
| 77 _KillStrayADBProcesses() |
| 78 device_serials = _ListSerialsOfHealthyOnlineDevices(blacklist) |
| 63 | 79 |
| 64 # The monsoon provides power for the device, so for devices with no | 80 # The monsoon provides power for the device, so for devices with no |
| 65 # real battery, we need to turn them on after the monsoon enables voltage | 81 # real battery, we need to turn them on after the monsoon enables voltage |
| 66 # output to the device. | 82 # output to the device. |
| 67 if not device_serials: | 83 if not device_serials: |
| 68 try: | 84 try: |
| 69 m = monsoon.Monsoon(wait=False) | 85 m = monsoon.Monsoon(wait=False) |
| 70 m.SetUsbPassthrough(1) | 86 m.SetUsbPassthrough(1) |
| 71 m.SetVoltage(3.8) | 87 m.SetVoltage(3.8) |
| 72 m.SetMaxCurrent(8) | 88 m.SetMaxCurrent(8) |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 devices = AndroidDevice.GetAllConnectedDevices(blacklist) | 195 devices = AndroidDevice.GetAllConnectedDevices(blacklist) |
| 180 finally: | 196 finally: |
| 181 if not devices and _HasValidAdb(): | 197 if not devices and _HasValidAdb(): |
| 182 try: | 198 try: |
| 183 adb_wrapper.AdbWrapper.KillServer() | 199 adb_wrapper.AdbWrapper.KillServer() |
| 184 except device_errors.NoAdbError as e: | 200 except device_errors.NoAdbError as e: |
| 185 logging.warning( | 201 logging.warning( |
| 186 'adb reported as present, but NoAdbError thrown: %s', str(e)) | 202 'adb reported as present, but NoAdbError thrown: %s', str(e)) |
| 187 | 203 |
| 188 return devices | 204 return devices |
| OLD | NEW |