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 import logging | 4 import logging |
5 import os | 5 import os |
6 import re | 6 import re |
7 import subprocess | 7 import subprocess |
8 import sys | 8 import sys |
9 | 9 |
10 from telemetry.core import util | 10 from telemetry.core import util |
(...skipping 13 matching lines...) Expand all Loading... |
24 set to high performance mode after browser is started. | 24 set to high performance mode after browser is started. |
25 """ | 25 """ |
26 def __init__(self, device_id, enable_performance_mode=True): | 26 def __init__(self, device_id, enable_performance_mode=True): |
27 super(AndroidDevice, self).__init__( | 27 super(AndroidDevice, self).__init__( |
28 name='Android device %s' % device_id, guid=device_id) | 28 name='Android device %s' % device_id, guid=device_id) |
29 self._device_id = device_id | 29 self._device_id = device_id |
30 self._enable_performance_mode = enable_performance_mode | 30 self._enable_performance_mode = enable_performance_mode |
31 | 31 |
32 @classmethod | 32 @classmethod |
33 def GetAllConnectedDevices(cls): | 33 def GetAllConnectedDevices(cls): |
34 device_serials = adb_commands.GetAttachedDevices() | 34 device_serials = GetDeviceSerials() |
35 # The monsoon provides power for the device, so for devices with no | 35 return [cls(s) for s in device_serials] |
36 # real battery, we need to turn them on after the monsoon enables voltage | 36 |
37 # output to the device. | 37 @property |
38 if not device_serials: | 38 def device_id(self): |
39 try: | 39 return self._device_id |
40 m = monsoon.Monsoon(wait=False) | 40 |
41 m.SetUsbPassthrough(1) | 41 @property |
42 m.SetVoltage(3.8) | 42 def enable_performance_mode(self): |
43 m.SetMaxCurrent(8) | 43 return self._enable_performance_mode |
44 logging.warn(""" | 44 |
| 45 |
| 46 def GetDeviceSerials(): |
| 47 device_serials = adb_commands.GetAttachedDevices() |
| 48 # The monsoon provides power for the device, so for devices with no |
| 49 # real battery, we need to turn them on after the monsoon enables voltage |
| 50 # output to the device. |
| 51 if not device_serials: |
| 52 try: |
| 53 m = monsoon.Monsoon(wait=False) |
| 54 m.SetUsbPassthrough(1) |
| 55 m.SetVoltage(3.8) |
| 56 m.SetMaxCurrent(8) |
| 57 logging.warn(""" |
45 Monsoon power monitor detected, but no Android devices. | 58 Monsoon power monitor detected, but no Android devices. |
46 | 59 |
47 The Monsoon's power output has been enabled. Please now ensure that: | 60 The Monsoon's power output has been enabled. Please now ensure that: |
48 | 61 |
49 1. The Monsoon's front and back USB are connected to the host. | 62 1. The Monsoon's front and back USB are connected to the host. |
50 2. The device is connected to the Monsoon's main and USB channels. | 63 2. The device is connected to the Monsoon's main and USB channels. |
51 3. The device is turned on. | 64 3. The device is turned on. |
52 | 65 |
53 Waiting for device... | 66 Waiting for device... |
54 """) | 67 """) |
55 util.WaitFor(adb_commands.GetAttachedDevices, 600) | 68 util.WaitFor(adb_commands.GetAttachedDevices, 600) |
56 device_serials = adb_commands.GetAttachedDevices() | 69 device_serials = adb_commands.GetAttachedDevices() |
57 except IOError: | 70 except IOError: |
58 return [] | 71 return [] |
59 return [cls(s) for s in device_serials] | 72 return device_serials |
60 | |
61 @property | |
62 def device_id(self): | |
63 return self._device_id | |
64 | |
65 @property | |
66 def enable_performance_mode(self): | |
67 return self._enable_performance_mode | |
68 | 73 |
69 | 74 |
70 def GetDevice(finder_options): | 75 def GetDevice(finder_options): |
71 """Return a Platform instance for the device specified by |finder_options|.""" | 76 """Return a Platform instance for the device specified by |finder_options|.""" |
72 if not CanDiscoverDevices(): | 77 if not CanDiscoverDevices(): |
73 logging.info( | 78 logging.info( |
74 'No adb command found. Will not try searching for Android browsers.') | 79 'No adb command found. Will not try searching for Android browsers.') |
75 return None | 80 return None |
76 | 81 |
77 if finder_options.android_device: | 82 if finder_options.device and finder_options.device in GetDeviceSerials(): |
78 return AndroidDevice( | 83 return AndroidDevice( |
79 finder_options.android_device, | 84 finder_options.device, |
80 enable_performance_mode=not finder_options.no_performance_mode) | 85 enable_performance_mode=not finder_options.no_performance_mode) |
81 | 86 |
82 devices = AndroidDevice.GetAllConnectedDevices() | 87 devices = AndroidDevice.GetAllConnectedDevices() |
83 if len(devices) == 0: | 88 if len(devices) == 0: |
84 logging.info('No android devices found.') | 89 logging.info('No android devices found.') |
85 return None | 90 return None |
86 if len(devices) > 1: | 91 if len(devices) > 1: |
87 logging.warn( | 92 logging.warn( |
88 'Multiple devices attached. Please specify one of the following:\n' + | 93 'Multiple devices attached. Please specify one of the following:\n' + |
89 '\n'.join([' --device=%s' % d.device_id for d in devices])) | 94 '\n'.join([' --device=%s' % d.device_id for d in devices])) |
(...skipping 24 matching lines...) Expand all Loading... |
114 pass | 119 pass |
115 chromium_adb_path = os.path.join( | 120 chromium_adb_path = os.path.join( |
116 util.GetChromiumSrcDir(), 'third_party', 'android_tools', 'sdk', | 121 util.GetChromiumSrcDir(), 'third_party', 'android_tools', 'sdk', |
117 'platform-tools', 'adb') | 122 'platform-tools', 'adb') |
118 if sys.platform.startswith('linux') and os.path.exists(chromium_adb_path): | 123 if sys.platform.startswith('linux') and os.path.exists(chromium_adb_path): |
119 os.environ['PATH'] = os.pathsep.join( | 124 os.environ['PATH'] = os.pathsep.join( |
120 [os.path.dirname(chromium_adb_path), os.environ['PATH']]) | 125 [os.path.dirname(chromium_adb_path), os.environ['PATH']]) |
121 return True | 126 return True |
122 return False | 127 return False |
123 | 128 |
| 129 |
| 130 def FindAllAvailableDevices(_): |
| 131 """Returns a list of available devices. |
| 132 """ |
| 133 if not CanDiscoverDevices(): |
| 134 return [] |
| 135 else: |
| 136 return AndroidDevice.GetAllConnectedDevices() |
OLD | NEW |