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 5"""Finds devices that can be controlled by telemetry.""" 6 7from telemetry.internal.platform import android_device 8from telemetry.internal.platform import cros_device 9from telemetry.internal.platform import desktop_device 10from telemetry.internal.platform import ios_device 11 12DEVICES = [ 13 android_device, 14 cros_device, 15 desktop_device, 16 ios_device, 17] 18 19 20def _GetAllAvailableDevices(options): 21 """Returns a list of all available devices.""" 22 devices = [] 23 for device in DEVICES: 24 devices.extend(device.FindAllAvailableDevices(options)) 25 return devices 26 27 28def GetDevicesMatchingOptions(options): 29 """Returns a list of devices matching the options.""" 30 devices = [] 31 remote_platform_options = options.remote_platform_options 32 if (not remote_platform_options.device or 33 remote_platform_options.device == 'list'): 34 devices = _GetAllAvailableDevices(options) 35 elif remote_platform_options.device == 'android': 36 devices = android_device.FindAllAvailableDevices(options) 37 else: 38 devices = _GetAllAvailableDevices(options) 39 devices = [d for d in devices if d.guid == 40 options.remote_platform_options.device] 41 42 devices.sort(key=lambda device: device.name) 43 return devices 44