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.
8 from devil
.android
import device_blacklist
9 from devil
.android
import device_errors
10 from devil
.android
import device_utils
11 from devil
.utils
import parallelizer
12 from pylib
.base
import environment
15 class LocalDeviceEnvironment(environment
.Environment
):
17 def __init__(self
, args
, _error_func
):
18 super(LocalDeviceEnvironment
, self
).__init
__()
19 self
._blacklist
= (device_blacklist
.Blacklist(args
.blacklist_file
)
20 if args
.blacklist_file
22 self
._device
_serial
= args
.test_device
23 self
._devices
_lock
= threading
.Lock()
25 self
._max
_tries
= 1 + args
.num_retries
26 self
._tool
_name
= args
.tool
30 available_devices
= device_utils
.DeviceUtils
.HealthyDevices(
32 if not available_devices
:
33 raise device_errors
.NoDevicesError
34 if self
._device
_serial
:
35 self
._devices
= [d
for d
in available_devices
36 if d
.adb
.GetDeviceSerial() == self
._device
_serial
]
38 raise device_errors
.DeviceUnreachableError(
39 'Could not find device %r' % self
._device
_serial
)
41 self
._devices
= available_devices
46 raise device_errors
.NoDevicesError()
50 def parallel_devices(self
):
51 return parallelizer
.SyncParallelizer(self
.devices
)
55 return self
._max
_tries
59 return self
._tool
_name
65 def BlacklistDevice(self
, device
):
66 if not self
._blacklist
:
68 'Attempted to blacklist %s, but no blacklist was provided.',
72 device_serial
= device
.adb
.GetDeviceSerial()
73 self
._blacklist
.Extend([device_serial
])
74 with self
._devices
_lock
:
75 self
._devices
= [d
for d
in self
._devices
if str(d
) != device_serial
]