Chromium Code Reviews| 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. | |
|
frankf
2014/06/25 19:19:30
remove space here and below
jbudorick
2014/06/25 21:04:28
Done.
| |
| 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|. | |
|
Victor Starodub
2014/06/25 19:35:45
Maybe expand these? IsOnline is 300 lines away and
| |
| 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 Args: | |
| 430 keycode: A integer keycode to send to the device. | |
|
frankf
2014/06/25 19:19:30
should this be an enum of some sort?
jbudorick
2014/06/25 21:04:28
It could be, although I'm reluctant to include it
| |
| 431 timeout: Same as for |IsOnline|. | |
| 432 retries: Same as for |IsOnline|. | |
| 433 """ | |
| 434 self.old_interface.SendKeyEvent(keycode) | |
| 435 | |
| 393 def __str__(self): | 436 def __str__(self): |
| 394 """Returns the device serial.""" | 437 """Returns the device serial.""" |
| 395 return self.old_interface.GetDevice() | 438 return self.old_interface.GetDevice() |
| 396 | 439 |
| 397 @staticmethod | 440 @staticmethod |
| 398 def parallel(devices=None, async=False): | 441 def parallel(devices=None, async=False): |
| 399 """Creates a Parallelizer to operate over the provided list of devices. | 442 """Creates a Parallelizer to operate over the provided list of devices. |
| 400 | 443 |
| 401 If |devices| is either |None| or an empty list, the Parallelizer will | 444 If |devices| is either |None| or an empty list, the Parallelizer will |
| 402 operate over all attached devices. | 445 operate over all attached devices. |
| 403 | 446 |
| 404 Args: | 447 Args: |
| 405 devices: A list of either DeviceUtils instances or objects from | 448 devices: A list of either DeviceUtils instances or objects from |
| 406 from which DeviceUtils instances can be constructed. If None, | 449 from which DeviceUtils instances can be constructed. If None, |
| 407 all attached devices will be used. | 450 all attached devices will be used. |
| 408 async: If true, returns a Parallelizer that runs operations | 451 async: If true, returns a Parallelizer that runs operations |
| 409 asynchronously. | 452 asynchronously. |
| 410 Returns: | 453 Returns: |
| 411 A Parallelizer operating over |devices|. | 454 A Parallelizer operating over |devices|. |
| 412 """ | 455 """ |
| 413 if not devices or len(devices) == 0: | 456 if not devices or len(devices) == 0: |
| 414 devices = pylib.android_commands.GetAttachedDevices() | 457 devices = pylib.android_commands.GetAttachedDevices() |
| 415 parallelizer_type = (parallelizer.Parallelizer if async | 458 parallelizer_type = (parallelizer.Parallelizer if async |
| 416 else parallelizer.SyncParallelizer) | 459 else parallelizer.SyncParallelizer) |
| 417 return parallelizer_type([ | 460 return parallelizer_type([ |
| 418 d if isinstance(d, DeviceUtils) else DeviceUtils(d) | 461 d if isinstance(d, DeviceUtils) else DeviceUtils(d) |
| 419 for d in devices]) | 462 for d in devices]) |
| 420 | 463 |
| OLD | NEW |