Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / tools / telemetry / telemetry / core / platform / android_device.py
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.
4 import logging
5
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
10
11
12 class AndroidDevice(device.Device):
13   """ Class represents information for connecting to an android device.
14
15   Attributes:
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
18       'adb devices' command
19     enable_performance_mode: when this is set to True, android platform will be
20     set to high performance mode after browser is started.
21   """
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
27
28   @classmethod
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:
35       try:
36         m = monsoon.Monsoon(wait=False)
37         m.SetUsbPassthrough(1)
38         m.SetVoltage(3.8)
39         m.SetMaxCurrent(8)
40         logging.warn("""
41 Monsoon power monitor detected, but no Android devices.
42
43 The Monsoon's power output has been enabled. Please now ensure that:
44
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.
48
49 Waiting for device...
50 """)
51         util.WaitFor(adb_commands.GetAttachedDevices, 600)
52         device_serials = adb_commands.GetAttachedDevices()
53       except IOError:
54         return []
55     return [AndroidDevice(s) for s in device_serials]
56
57   @property
58   def device_id(self):
59     return self._device_id
60
61   @property
62   def enable_performance_mode(self):
63     return self._enable_performance_mode