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
3 # found in the LICENSE file.
6 from telemetry.core import util
7 from telemetry.core.backends import adb_commands
8 from telemetry.core.platform import device
9 from telemetry.core.platform.profiler import monsoon
12 class AndroidDevice(device.Device):
13 """ Class represents information for connecting to an android device.
16 device_id: the device's serial string created by adb to uniquely
17 identify an emulator/device instance. This string can be found by running
19 enable_performance_mode: when this is set to True, android platform will be
20 set to high performance mode after browser is started.
22 def __init__(self, device_id, enable_performance_mode=False):
23 super(AndroidDevice, self).__init__(
24 name='Android device %s' % device_id, guid=device_id)
25 self._device_id = device_id
26 self._enable_performance_mode = enable_performance_mode
29 def GetAllConnectedDevices(cls):
30 device_serials = adb_commands.GetAttachedDevices()
31 # The monsoon provides power for the device, so for devices with no
32 # real battery, we need to turn them on after the monsoon enables voltage
33 # output to the device.
34 if not device_serials:
36 m = monsoon.Monsoon(wait=False)
37 m.SetUsbPassthrough(1)
41 Monsoon power monitor detected, but no Android devices.
43 The Monsoon's power output has been enabled. Please now ensure that:
45 1. The Monsoon's front and back USB are connected to the host.
46 2. The device is connected to the Monsoon's main and USB channels.
47 3. The device is turned on.
51 util.WaitFor(adb_commands.GetAttachedDevices, 600)
52 device_serials = adb_commands.GetAttachedDevices()
55 return [AndroidDevice(s) for s in device_serials]
59 return self._device_id
62 def enable_performance_mode(self):
63 return self._enable_performance_mode