| OLD | NEW |
| 1 #!/usr/bin/python2.4 | 1 #!/usr/bin/python2.4 |
| 2 # | 2 # |
| 3 # | 3 # |
| 4 # Copyright 2008, The Android Open Source Project | 4 # Copyright 2008, The Android Open Source Project |
| 5 # | 5 # |
| 6 # Licensed under the Apache License, Version 2.0 (the "License"); | 6 # Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 # you may not use this file except in compliance with the License. | 7 # you may not use this file except in compliance with the License. |
| 8 # You may obtain a copy of the License at | 8 # You may obtain a copy of the License at |
| 9 # | 9 # |
| 10 # http://www.apache.org/licenses/LICENSE-2.0 | 10 # http://www.apache.org/licenses/LICENSE-2.0 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 # local imports | 27 # local imports |
| 28 import am_instrument_parser | 28 import am_instrument_parser |
| 29 import errors | 29 import errors |
| 30 import logger | 30 import logger |
| 31 import run_command | 31 import run_command |
| 32 | 32 |
| 33 | 33 |
| 34 class AdbInterface: | 34 class AdbInterface: |
| 35 """Helper class for communicating with Android device via adb.""" | 35 """Helper class for communicating with Android device via adb.""" |
| 36 | 36 |
| 37 # argument to pass to adb, to direct command to specific device | 37 DEVICE_TRACE_DIR = "/data/test_results/" |
| 38 _target_arg = "" | |
| 39 | 38 |
| 40 DEVICE_TRACE_DIR = "/data/test_results/" | 39 def __init__(self, adb_path='adb'): |
| 40 """Constructor. |
| 41 |
| 42 Args: |
| 43 adb_path: Absolute path to the adb binary that should be used. Defaults |
| 44 to the adb in the environment path. |
| 45 """ |
| 46 self._adb_path = adb_path |
| 47 # argument to pass to adb, to direct command to specific device |
| 48 self._target_arg = "" |
| 41 | 49 |
| 42 def SetEmulatorTarget(self): | 50 def SetEmulatorTarget(self): |
| 43 """Direct all future commands to the only running emulator.""" | 51 """Direct all future commands to the only running emulator.""" |
| 44 self._target_arg = "-e" | 52 self._target_arg = "-e" |
| 45 | 53 |
| 46 def SetDeviceTarget(self): | 54 def SetDeviceTarget(self): |
| 47 """Direct all future commands to the only connected USB device.""" | 55 """Direct all future commands to the only connected USB device.""" |
| 48 self._target_arg = "-d" | 56 self._target_arg = "-d" |
| 49 | 57 |
| 50 def SetTargetSerial(self, serial): | 58 def SetTargetSerial(self, serial): |
| 51 """Direct all future commands to Android target with the given serial.""" | 59 """Direct all future commands to Android target with the given serial.""" |
| 52 self._target_arg = "-s %s" % serial | 60 self._target_arg = "-s %s" % serial |
| 53 | 61 |
| 54 def SendCommand(self, command_string, timeout_time=20, retry_count=3): | 62 def SendCommand(self, command_string, timeout_time=20, retry_count=3): |
| 55 """Send a command via adb. | 63 """Send a command via adb. |
| 56 | 64 |
| 57 Args: | 65 Args: |
| 58 command_string: adb command to run | 66 command_string: adb command to run |
| 59 timeout_time: number of seconds to wait for command to respond before | 67 timeout_time: number of seconds to wait for command to respond before |
| 60 retrying | 68 retrying |
| 61 retry_count: number of times to retry command before raising | 69 retry_count: number of times to retry command before raising |
| 62 WaitForResponseTimedOutError | 70 WaitForResponseTimedOutError |
| 63 Returns: | 71 Returns: |
| 64 string output of command | 72 string output of command |
| 65 | 73 |
| 66 Raises: | 74 Raises: |
| 67 WaitForResponseTimedOutError if device does not respond to command within
time | 75 WaitForResponseTimedOutError if device does not respond to command within
time |
| 68 """ | 76 """ |
| 69 adb_cmd = "adb %s %s" % (self._target_arg, command_string) | 77 adb_cmd = "%s %s %s" % (self._adb_path, self._target_arg, command_string) |
| 70 logger.SilentLog("about to run %s" % adb_cmd) | 78 logger.SilentLog("about to run %s" % adb_cmd) |
| 71 return run_command.RunCommand(adb_cmd, timeout_time=timeout_time, | 79 return run_command.RunCommand(adb_cmd, timeout_time=timeout_time, |
| 72 retry_count=retry_count) | 80 retry_count=retry_count) |
| 73 | 81 |
| 74 def SendShellCommand(self, cmd, timeout_time=20, retry_count=3): | 82 def SendShellCommand(self, cmd, timeout_time=20, retry_count=3): |
| 75 """Send a adb shell command. | 83 """Send a adb shell command. |
| 76 | 84 |
| 77 Args: | 85 Args: |
| 78 cmd: adb shell command to run | 86 cmd: adb shell command to run |
| 79 timeout_time: number of seconds to wait for command to respond before | 87 timeout_time: number of seconds to wait for command to respond before |
| (...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 # press the MENU key, this will disable key guard if runtime is started | 513 # press the MENU key, this will disable key guard if runtime is started |
| 506 # with ro.monkey set to 1 | 514 # with ro.monkey set to 1 |
| 507 self.SendShellCommand("input keyevent 82", retry_count=retry_count) | 515 self.SendShellCommand("input keyevent 82", retry_count=retry_count) |
| 508 else: | 516 else: |
| 509 self.WaitForDevicePm() | 517 self.WaitForDevicePm() |
| 510 return output | 518 return output |
| 511 | 519 |
| 512 def GetSerialNumber(self): | 520 def GetSerialNumber(self): |
| 513 """Returns the serial number of the targeted device.""" | 521 """Returns the serial number of the targeted device.""" |
| 514 return self.SendCommand("get-serialno").strip() | 522 return self.SendCommand("get-serialno").strip() |
| OLD | NEW |