1# Copyright 2015 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 5from devil.android import device_blacklist 6from devil.android import device_errors 7from devil.android import device_utils 8 9 10def GetDevices(requested_devices, blacklist_file): 11 if not isinstance(blacklist_file, device_blacklist.Blacklist): 12 blacklist = (device_blacklist.Blacklist(blacklist_file) 13 if blacklist_file 14 else None) 15 16 devices = device_utils.DeviceUtils.HealthyDevices(blacklist) 17 if not devices: 18 raise device_errors.NoDevicesError() 19 elif requested_devices: 20 requested = set(requested_devices) 21 available = set(str(d) for d in devices) 22 missing = requested.difference(available) 23 if missing: 24 raise device_errors.DeviceUnreachableError(next(iter(missing))) 25 return sorted(device_utils.DeviceUtils(d) 26 for d in available.intersection(requested)) 27 else: 28 return devices 29 30