OLD | NEW |
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 """Provides a variety of device interactions based on adb. | 5 """Provides a variety of device interactions based on adb. |
6 | 6 |
7 Eventually, this will be based on adb_wrapper. | 7 Eventually, this will be based on adb_wrapper. |
8 """ | 8 """ |
9 # pylint: disable=unused-argument | 9 # pylint: disable=unused-argument |
10 | 10 |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 should_install = bool(self._GetChangedFilesImpl(apk_path, device_path)) | 405 should_install = bool(self._GetChangedFilesImpl(apk_path, device_path)) |
406 if should_install and not reinstall: | 406 if should_install and not reinstall: |
407 self.adb.Uninstall(package_name) | 407 self.adb.Uninstall(package_name) |
408 else: | 408 else: |
409 should_install = True | 409 should_install = True |
410 if should_install: | 410 if should_install: |
411 self.adb.Install(apk_path, reinstall=reinstall) | 411 self.adb.Install(apk_path, reinstall=reinstall) |
412 | 412 |
413 @decorators.WithTimeoutAndRetriesFromInstance() | 413 @decorators.WithTimeoutAndRetriesFromInstance() |
414 def RunShellCommand(self, cmd, check_return=False, cwd=None, env=None, | 414 def RunShellCommand(self, cmd, check_return=False, cwd=None, env=None, |
415 as_root=False, single_line=False, | 415 as_root=False, single_line=False, timeout=None, |
416 timeout=None, retries=None): | 416 retries=None): |
417 """Run an ADB shell command. | 417 """Run an ADB shell command. |
418 | 418 |
419 The command to run |cmd| should be a sequence of program arguments or else | 419 The command to run |cmd| should be a sequence of program arguments or else |
420 a single string. | 420 a single string. |
421 | 421 |
422 When |cmd| is a sequence, it is assumed to contain the name of the command | 422 When |cmd| is a sequence, it is assumed to contain the name of the command |
423 to run followed by its arguments. In this case, arguments are passed to the | 423 to run followed by its arguments. In this case, arguments are passed to the |
424 command exactly as given, without any further processing by the shell. This | 424 command exactly as given, without any further processing by the shell. This |
425 allows to easily pass arguments containing spaces or special characters | 425 allows to easily pass arguments containing spaces or special characters |
426 without having to worry about getting quoting right. Whenever possible, it | 426 without having to worry about getting quoting right. Whenever possible, it |
(...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1325 Args: | 1325 Args: |
1326 timeout: timeout in seconds | 1326 timeout: timeout in seconds |
1327 retries: number of retries | 1327 retries: number of retries |
1328 """ | 1328 """ |
1329 return logcat_monitor.LogcatMonitor(self.adb, *args, **kwargs) | 1329 return logcat_monitor.LogcatMonitor(self.adb, *args, **kwargs) |
1330 | 1330 |
1331 def __str__(self): | 1331 def __str__(self): |
1332 """Returns the device serial.""" | 1332 """Returns the device serial.""" |
1333 return self.adb.GetDeviceSerial() | 1333 return self.adb.GetDeviceSerial() |
1334 | 1334 |
| 1335 @decorators.WithTimeoutAndRetriesFromInstance() |
| 1336 def GetDevicePieWrapper(self, timeout=None, retries=None): |
| 1337 """Gets the absolute path to the run_pie wrapper on the device. |
| 1338 |
| 1339 We have to build our device executables to be PIE, but they need to be able |
| 1340 to run on versions of android that don't support PIE (i.e. ICS and below). |
| 1341 To do so, we push a wrapper to the device that lets older android versions |
| 1342 run PIE executables. This method pushes that wrapper to the device if |
| 1343 necessary and returns the path to it. |
| 1344 |
| 1345 This is exposed publicly to allow clients to write scripts using run_pie |
| 1346 (e.g. md5sum.CalculateDeviceMd5Sum). |
| 1347 |
| 1348 Args: |
| 1349 timeout: timeout in seconds |
| 1350 retries: number of retries |
| 1351 |
| 1352 Returns: |
| 1353 The path to the PIE wrapper on the device, or an empty string if the |
| 1354 device does not require the wrapper. |
| 1355 """ |
| 1356 if 'run_pie' not in self._cache: |
| 1357 pie = '' |
| 1358 if (self.build_version_sdk < |
| 1359 constants.ANDROID_SDK_VERSION_CODES.JELLY_BEAN): |
| 1360 host_pie_path = os.path.join(constants.GetOutDirectory(), 'run_pie') |
| 1361 if not os.path.exists(host_pie_path): |
| 1362 raise device_errors.CommandFailedError('Please build run_pie') |
| 1363 pie = '%s/run_pie' % constants.TEST_EXECUTABLE_DIR |
| 1364 self.adb.Push(host_pie_path, pie) |
| 1365 |
| 1366 self._cache['run_pie'] = pie |
| 1367 |
| 1368 return self._cache['run_pie'] |
| 1369 |
1335 @classmethod | 1370 @classmethod |
1336 def parallel(cls, devices=None, async=False): | 1371 def parallel(cls, devices=None, async=False): |
1337 """Creates a Parallelizer to operate over the provided list of devices. | 1372 """Creates a Parallelizer to operate over the provided list of devices. |
1338 | 1373 |
1339 If |devices| is either |None| or an empty list, the Parallelizer will | 1374 If |devices| is either |None| or an empty list, the Parallelizer will |
1340 operate over all attached devices. | 1375 operate over all attached devices. |
1341 | 1376 |
1342 Args: | 1377 Args: |
1343 devices: A list of either DeviceUtils instances or objects from | 1378 devices: A list of either DeviceUtils instances or objects from |
1344 from which DeviceUtils instances can be constructed. If None, | 1379 from which DeviceUtils instances can be constructed. If None, |
1345 all attached devices will be used. | 1380 all attached devices will be used. |
1346 async: If true, returns a Parallelizer that runs operations | 1381 async: If true, returns a Parallelizer that runs operations |
1347 asynchronously. | 1382 asynchronously. |
1348 | 1383 |
1349 Returns: | 1384 Returns: |
1350 A Parallelizer operating over |devices|. | 1385 A Parallelizer operating over |devices|. |
1351 """ | 1386 """ |
1352 if not devices: | 1387 if not devices: |
1353 devices = adb_wrapper.AdbWrapper.GetDevices() | 1388 devices = adb_wrapper.AdbWrapper.GetDevices() |
1354 devices = [d if isinstance(d, cls) else cls(d) for d in devices] | 1389 devices = [d if isinstance(d, cls) else cls(d) for d in devices] |
1355 if async: | 1390 if async: |
1356 return parallelizer.Parallelizer(devices) | 1391 return parallelizer.Parallelizer(devices) |
1357 else: | 1392 else: |
1358 return parallelizer.SyncParallelizer(devices) | 1393 return parallelizer.SyncParallelizer(devices) |
OLD | NEW |