Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(117)

Side by Side Diff: build/android/pylib/device/device_utils.py

Issue 292313015: [Android] Switch to DeviceUtils versions of Reboot and Install. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 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 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """ 5 """
6 Provides a variety of device interactions based on adb. 6 Provides a variety of device interactions based on adb.
7 7
8 Eventually, this will be based on adb_wrapper. 8 Eventually, this will be based on adb_wrapper.
9 """ 9 """
10 # pylint: disable=W0613 10 # pylint: disable=W0613
11 11
12 import time 12 import time
13 13
14 import pylib.android_commands 14 import pylib.android_commands
15 from pylib.device import adb_wrapper 15 from pylib.device import adb_wrapper
16 from pylib.device import decorators 16 from pylib.device import decorators
17 from pylib.device import device_errors 17 from pylib.device import device_errors
18 from pylib.utils import apk_helper
18 from pylib.utils import parallelizer 19 from pylib.utils import parallelizer
19 20
20 _DEFAULT_TIMEOUT = 30 21 _DEFAULT_TIMEOUT = 30
21 _DEFAULT_RETRIES = 3 22 _DEFAULT_RETRIES = 3
22 23
23 24
24 @decorators.WithExplicitTimeoutAndRetries( 25 @decorators.WithExplicitTimeoutAndRetries(
25 _DEFAULT_TIMEOUT, _DEFAULT_RETRIES) 26 _DEFAULT_TIMEOUT, _DEFAULT_RETRIES)
26 def GetAVDs(): 27 def GetAVDs():
27 """ Returns a list of Android Virtual Devices. 28 """ Returns a list of Android Virtual Devices.
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 DeviceUnreachableError if the device becomes unresponsive. 148 DeviceUnreachableError if the device becomes unresponsive.
148 """ 149 """
149 self.old_interface.WaitForSystemBootCompleted(timeout) 150 self.old_interface.WaitForSystemBootCompleted(timeout)
150 self.old_interface.WaitForDevicePm() 151 self.old_interface.WaitForDevicePm()
151 self.old_interface.WaitForSdCardReady(timeout) 152 self.old_interface.WaitForSdCardReady(timeout)
152 if wifi: 153 if wifi:
153 while not 'Wi-Fi is enabled' in ( 154 while not 'Wi-Fi is enabled' in (
154 self.old_interface.RunShellCommand('dumpsys wifi')): 155 self.old_interface.RunShellCommand('dumpsys wifi')):
155 time.sleep(0.1) 156 time.sleep(0.1)
156 157
158 @decorators.WithTimeoutAndRetriesFromInstance()
159 def Reboot(self, block=True, timeout=None, retries=None):
160 """ Reboot the device.
frankf 2014/05/24 00:22:39 no space after quotation mark. Also you didn't fix
jbudorick 2014/05/27 20:58:35 Done wrt no space. There's only one one liner docs
frankf 2014/05/27 21:12:10 Multi-line: """Line One. Line2. """ Single line
jbudorick 2014/05/27 21:44:14 Right, my point was that all of the docstrings in
161
162 Args:
163 block: A boolean indicating if we should wait for the reboot to complete.
164 timeout: Same as for |IsOnline|.
165 retries: Same as for |IsOnline|.
166 """
167 self.old_interface.Reboot()
168 if block:
169 self.WaitUntilFullyBooted()
170
171 @decorators.WithTimeoutAndRetriesDefaults(
172 4 * _DEFAULT_TIMEOUT,
173 _DEFAULT_RETRIES)
174 def Install(self, apk_path, timeout=None, retries=None):
175 """ Install an APK. Noop if an identical APK is already installed.
176
177 Args:
178 apk_path: A string containing the path to the APK to install.
179 timeout: Same as for |IsOnline|.
180 retries: Same as for |IsOnline|.
181 Raises:
182 CommandFailedError if the installation fails.
183 CommandTimeoutError if the installation times out.
184 """
185 package_name = apk_helper.GetPackageName(apk_path)
186 device_path = self.old_interface.GetApplicationPath(package_name)
187 if not device_path or len(self.old_interface.GetFilesChanged(
188 apk_path, device_path, ignore_filenames=True) > 0):
frankf 2014/05/24 00:22:39 I'd create a variable to hold len(...) to make thi
jbudorick 2014/05/27 20:58:35 Done.
189 try:
190 if device_path:
191 self.old_interface.Uninstall(package_name)
192 out = self.old_interface.Install(apk_path, reinstall=bool(device_path))
193 for line in out.split('\n'):
194 if 'Failure' in line:
195 raise device_errors.CommandFailedError(
196 ['adb' ,'install', apk_path], line.strip())
197 except AssertionError as e:
198 raise device_errors.CommandFailedError(str(e))
199
157 def __str__(self): 200 def __str__(self):
158 """Returns the device serial.""" 201 """Returns the device serial."""
159 return self.old_interface.GetDevice() 202 return self.old_interface.GetDevice()
160 203
161 @staticmethod 204 @staticmethod
162 def parallel(devices=None, async=False): 205 def parallel(devices=None, async=False):
163 """ Creates a Parallelizer to operate over the provided list of devices. 206 """ Creates a Parallelizer to operate over the provided list of devices.
164 207
165 If |devices| is either |None| or an empty list, the Parallelizer will 208 If |devices| is either |None| or an empty list, the Parallelizer will
166 operate over all attached devices. 209 operate over all attached devices.
167 210
168 Args: 211 Args:
169 devices: A list of either DeviceUtils instances or objects from 212 devices: A list of either DeviceUtils instances or objects from
170 from which DeviceUtils instances can be constructed. If None, 213 from which DeviceUtils instances can be constructed. If None,
171 all attached devices will be used. 214 all attached devices will be used.
172 async: If true, returns a Parallelizer that runs operations 215 async: If true, returns a Parallelizer that runs operations
173 asynchronously. 216 asynchronously.
174 Returns: 217 Returns:
175 A Parallelizer operating over |devices|. 218 A Parallelizer operating over |devices|.
176 """ 219 """
177 if not devices or len(devices) == 0: 220 if not devices or len(devices) == 0:
178 devices = pylib.android_commands.GetAttachedDevices() 221 devices = pylib.android_commands.GetAttachedDevices()
179 parallelizer_type = (parallelizer.Parallelizer if async 222 parallelizer_type = (parallelizer.Parallelizer if async
180 else parallelizer.SyncParallelizer) 223 else parallelizer.SyncParallelizer)
181 return parallelizer_type([ 224 return parallelizer_type([
182 d if isinstance(d, DeviceUtils) else DeviceUtils(d) 225 d if isinstance(d, DeviceUtils) else DeviceUtils(d)
183 for d in devices]) 226 for d in devices])
184 227
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698