| 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 19 matching lines...) Expand all Loading... |
| 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 # argument to pass to adb, to direct command to specific device |
| 38 _target_arg = "" | 38 _target_arg = "" |
| 39 | 39 |
| 40 # argument used to specify adb binary. Defaults to adb in the |
| 41 # environment path. |
| 42 _adb_path = 'adb' |
| 43 |
| 40 DEVICE_TRACE_DIR = "/data/test_results/" | 44 DEVICE_TRACE_DIR = "/data/test_results/" |
| 41 | 45 |
| 46 def SetAdbPath(self, adb_path): |
| 47 """Set the path to the adb binary. |
| 48 |
| 49 Args: |
| 50 adb_path: absolute path to the adb binary that should be used. |
| 51 """ |
| 52 self._adb_path = adb_path |
| 53 |
| 42 def SetEmulatorTarget(self): | 54 def SetEmulatorTarget(self): |
| 43 """Direct all future commands to the only running emulator.""" | 55 """Direct all future commands to the only running emulator.""" |
| 44 self._target_arg = "-e" | 56 self._target_arg = "-e" |
| 45 | 57 |
| 46 def SetDeviceTarget(self): | 58 def SetDeviceTarget(self): |
| 47 """Direct all future commands to the only connected USB device.""" | 59 """Direct all future commands to the only connected USB device.""" |
| 48 self._target_arg = "-d" | 60 self._target_arg = "-d" |
| 49 | 61 |
| 50 def SetTargetSerial(self, serial): | 62 def SetTargetSerial(self, serial): |
| 51 """Direct all future commands to Android target with the given serial.""" | 63 """Direct all future commands to Android target with the given serial.""" |
| 52 self._target_arg = "-s %s" % serial | 64 self._target_arg = "-s %s" % serial |
| 53 | 65 |
| 54 def SendCommand(self, command_string, timeout_time=20, retry_count=3): | 66 def SendCommand(self, command_string, timeout_time=20, retry_count=3): |
| 55 """Send a command via adb. | 67 """Send a command via adb. |
| 56 | 68 |
| 57 Args: | 69 Args: |
| 58 command_string: adb command to run | 70 command_string: adb command to run |
| 59 timeout_time: number of seconds to wait for command to respond before | 71 timeout_time: number of seconds to wait for command to respond before |
| 60 retrying | 72 retrying |
| 61 retry_count: number of times to retry command before raising | 73 retry_count: number of times to retry command before raising |
| 62 WaitForResponseTimedOutError | 74 WaitForResponseTimedOutError |
| 63 Returns: | 75 Returns: |
| 64 string output of command | 76 string output of command |
| 65 | 77 |
| 66 Raises: | 78 Raises: |
| 67 WaitForResponseTimedOutError if device does not respond to command within
time | 79 WaitForResponseTimedOutError if device does not respond to command within
time |
| 68 """ | 80 """ |
| 69 adb_cmd = "adb %s %s" % (self._target_arg, command_string) | 81 adb_cmd = "%s %s %s" % (self._adb_path, self._target_arg, command_string) |
| 70 logger.SilentLog("about to run %s" % adb_cmd) | 82 logger.SilentLog("about to run %s" % adb_cmd) |
| 71 return run_command.RunCommand(adb_cmd, timeout_time=timeout_time, | 83 return run_command.RunCommand(adb_cmd, timeout_time=timeout_time, |
| 72 retry_count=retry_count) | 84 retry_count=retry_count) |
| 73 | 85 |
| 74 def SendShellCommand(self, cmd, timeout_time=20, retry_count=3): | 86 def SendShellCommand(self, cmd, timeout_time=20, retry_count=3): |
| 75 """Send a adb shell command. | 87 """Send a adb shell command. |
| 76 | 88 |
| 77 Args: | 89 Args: |
| 78 cmd: adb shell command to run | 90 cmd: adb shell command to run |
| 79 timeout_time: number of seconds to wait for command to respond before | 91 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 | 517 # press the MENU key, this will disable key guard if runtime is started |
| 506 # with ro.monkey set to 1 | 518 # with ro.monkey set to 1 |
| 507 self.SendShellCommand("input keyevent 82", retry_count=retry_count) | 519 self.SendShellCommand("input keyevent 82", retry_count=retry_count) |
| 508 else: | 520 else: |
| 509 self.WaitForDevicePm() | 521 self.WaitForDevicePm() |
| 510 return output | 522 return output |
| 511 | 523 |
| 512 def GetSerialNumber(self): | 524 def GetSerialNumber(self): |
| 513 """Returns the serial number of the targeted device.""" | 525 """Returns the serial number of the targeted device.""" |
| 514 return self.SendCommand("get-serialno").strip() | 526 return self.SendCommand("get-serialno").strip() |
| OLD | NEW |