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=W0613 | 9 # pylint: disable=W0613 |
10 | 10 |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 retries: Same as for |IsOnline|. | 383 retries: Same as for |IsOnline|. |
384 """ | 384 """ |
385 package, old_intent = intent.action.rsplit('.', 1) | 385 package, old_intent = intent.action.rsplit('.', 1) |
386 if intent.extras is None: | 386 if intent.extras is None: |
387 args = [] | 387 args = [] |
388 else: | 388 else: |
389 args = ['-e %s%s' % (k, ' "%s"' % v if v else '') | 389 args = ['-e %s%s' % (k, ' "%s"' % v if v else '') |
390 for k, v in intent.extras.items() if len(k) > 0] | 390 for k, v in intent.extras.items() if len(k) > 0] |
391 self.old_interface.BroadcastIntent(package, old_intent, *args) | 391 self.old_interface.BroadcastIntent(package, old_intent, *args) |
392 | 392 |
| 393 @decorators.WithTimeoutAndRetriesFromInstance() |
| 394 def GoHome(self, timeout=None, retries=None): |
| 395 """Return to the home screen. |
| 396 |
| 397 Args: |
| 398 timeout: Same as for |IsOnline|. |
| 399 retries: Same as for |IsOnline|. |
| 400 """ |
| 401 self.old_interface.GoHome() |
| 402 |
| 403 @decorators.WithTimeoutAndRetriesFromInstance() |
| 404 def ForceStop(self, package, timeout=None, retries=None): |
| 405 """Close the application. |
| 406 |
| 407 Args: |
| 408 package: A string containing the name of the package to stop. |
| 409 timeout: Same as for |IsOnline|. |
| 410 retries: Same as for |IsOnline|. |
| 411 """ |
| 412 self.old_interface.CloseApplication(package) |
| 413 |
| 414 @decorators.WithTimeoutAndRetriesFromInstance() |
| 415 def ClearApplicationState(self, package, timeout=None, retries=None): |
| 416 """Clear all state for the given package. |
| 417 |
| 418 Args: |
| 419 package: A string containing the name of the package to stop. |
| 420 timeout: Same as for |IsOnline|. |
| 421 retries: Same as for |IsOnline|. |
| 422 """ |
| 423 self.old_interface.ClearApplicationState(package) |
| 424 |
| 425 @decorators.WithTimeoutAndRetriesFromInstance() |
| 426 def SendKeyEvent(self, keycode, timeout=None, retries=None): |
| 427 """Sends a keycode to the device. |
| 428 |
| 429 See: http://developer.android.com/reference/android/view/KeyEvent.html |
| 430 |
| 431 Args: |
| 432 keycode: A integer keycode to send to the device. |
| 433 timeout: Same as for |IsOnline|. |
| 434 retries: Same as for |IsOnline|. |
| 435 """ |
| 436 self.old_interface.SendKeyEvent(keycode) |
| 437 |
393 def __str__(self): | 438 def __str__(self): |
394 """Returns the device serial.""" | 439 """Returns the device serial.""" |
395 return self.old_interface.GetDevice() | 440 return self.old_interface.GetDevice() |
396 | 441 |
397 @staticmethod | 442 @staticmethod |
398 def parallel(devices=None, async=False): | 443 def parallel(devices=None, async=False): |
399 """Creates a Parallelizer to operate over the provided list of devices. | 444 """Creates a Parallelizer to operate over the provided list of devices. |
400 | 445 |
401 If |devices| is either |None| or an empty list, the Parallelizer will | 446 If |devices| is either |None| or an empty list, the Parallelizer will |
402 operate over all attached devices. | 447 operate over all attached devices. |
403 | 448 |
404 Args: | 449 Args: |
405 devices: A list of either DeviceUtils instances or objects from | 450 devices: A list of either DeviceUtils instances or objects from |
406 from which DeviceUtils instances can be constructed. If None, | 451 from which DeviceUtils instances can be constructed. If None, |
407 all attached devices will be used. | 452 all attached devices will be used. |
408 async: If true, returns a Parallelizer that runs operations | 453 async: If true, returns a Parallelizer that runs operations |
409 asynchronously. | 454 asynchronously. |
410 Returns: | 455 Returns: |
411 A Parallelizer operating over |devices|. | 456 A Parallelizer operating over |devices|. |
412 """ | 457 """ |
413 if not devices or len(devices) == 0: | 458 if not devices or len(devices) == 0: |
414 devices = pylib.android_commands.GetAttachedDevices() | 459 devices = pylib.android_commands.GetAttachedDevices() |
415 parallelizer_type = (parallelizer.Parallelizer if async | 460 parallelizer_type = (parallelizer.Parallelizer if async |
416 else parallelizer.SyncParallelizer) | 461 else parallelizer.SyncParallelizer) |
417 return parallelizer_type([ | 462 return parallelizer_type([ |
418 d if isinstance(d, DeviceUtils) else DeviceUtils(d) | 463 d if isinstance(d, DeviceUtils) else DeviceUtils(d) |
419 for d in devices]) | 464 for d in devices]) |
420 | 465 |
OLD | NEW |