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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
44 self._target_arg = "-e" | 44 self._target_arg = "-e" |
45 | 45 |
46 def SetDeviceTarget(self): | 46 def SetDeviceTarget(self): |
47 """Direct all future commands to the only connected USB device.""" | 47 """Direct all future commands to the only connected USB device.""" |
48 self._target_arg = "-d" | 48 self._target_arg = "-d" |
49 | 49 |
50 def SetTargetSerial(self, serial): | 50 def SetTargetSerial(self, serial): |
51 """Direct all future commands to Android target with the given serial.""" | 51 """Direct all future commands to Android target with the given serial.""" |
52 self._target_arg = "-s %s" % serial | 52 self._target_arg = "-s %s" % serial |
53 | 53 |
54 def SendCommand(self, command_string, timeout_time=20, retry_count=3): | 54 def SendCommand(self, command_string, timeout_time=20, retry_count=3, |
55 cmd_logger=None): | |
55 """Send a command via adb. | 56 """Send a command via adb. |
56 | 57 |
57 Args: | 58 Args: |
58 command_string: adb command to run | 59 command_string: adb command to run |
59 timeout_time: number of seconds to wait for command to respond before | 60 timeout_time: number of seconds to wait for command to respond before |
60 retrying | 61 retrying |
61 retry_count: number of times to retry command before raising | 62 retry_count: number of times to retry command before raising |
bulach
2012/08/09 12:36:52
new param requires docstring..
| |
62 WaitForResponseTimedOutError | 63 WaitForResponseTimedOutError |
63 Returns: | 64 Returns: |
64 string output of command | 65 string output of command |
65 | 66 |
66 Raises: | 67 Raises: |
67 WaitForResponseTimedOutError if device does not respond to command within time | 68 WaitForResponseTimedOutError if device does not respond to command within time |
68 """ | 69 """ |
69 adb_cmd = "adb %s %s" % (self._target_arg, command_string) | 70 adb_cmd = "adb %s %s" % (self._target_arg, command_string) |
70 logger.SilentLog("about to run %s" % adb_cmd) | 71 logger.SilentLog("about to run %s" % adb_cmd) |
72 if cmd_logger: | |
73 cmd_logger.info('>>> $ %s' % adb_cmd) | |
71 return run_command.RunCommand(adb_cmd, timeout_time=timeout_time, | 74 return run_command.RunCommand(adb_cmd, timeout_time=timeout_time, |
72 retry_count=retry_count) | 75 retry_count=retry_count) |
73 | 76 |
74 def SendShellCommand(self, cmd, timeout_time=20, retry_count=3): | 77 def SendShellCommand(self, cmd, timeout_time=20, retry_count=3, |
78 cmd_logger=None): | |
75 """Send a adb shell command. | 79 """Send a adb shell command. |
76 | 80 |
77 Args: | 81 Args: |
78 cmd: adb shell command to run | 82 cmd: adb shell command to run |
79 timeout_time: number of seconds to wait for command to respond before | 83 timeout_time: number of seconds to wait for command to respond before |
80 retrying | 84 retrying |
81 retry_count: number of times to retry command before raising | 85 retry_count: number of times to retry command before raising |
82 WaitForResponseTimedOutError | 86 WaitForResponseTimedOutError |
83 | 87 |
84 Returns: | 88 Returns: |
85 string output of command | 89 string output of command |
86 | 90 |
87 Raises: | 91 Raises: |
88 WaitForResponseTimedOutError: if device does not respond to command | 92 WaitForResponseTimedOutError: if device does not respond to command |
89 """ | 93 """ |
90 return self.SendCommand("shell %s" % cmd, timeout_time=timeout_time, | 94 return self.SendCommand("shell %s" % cmd, timeout_time=timeout_time, |
91 retry_count=retry_count) | 95 retry_count=retry_count, cmd_logger=cmd_logger) |
92 | 96 |
93 def BugReport(self, path): | 97 def BugReport(self, path): |
94 """Dumps adb bugreport to the file specified by the path. | 98 """Dumps adb bugreport to the file specified by the path. |
95 | 99 |
96 Args: | 100 Args: |
97 path: Path of the file where adb bugreport is dumped to. | 101 path: Path of the file where adb bugreport is dumped to. |
98 """ | 102 """ |
99 bug_output = self.SendShellCommand("bugreport", timeout_time=60) | 103 bug_output = self.SendShellCommand("bugreport", timeout_time=60) |
100 bugreport_file = open(path, "w") | 104 bugreport_file = open(path, "w") |
101 bugreport_file.write(bug_output) | 105 bugreport_file.write(bug_output) |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
150 | 154 |
151 def EnableAdbRoot(self): | 155 def EnableAdbRoot(self): |
152 """Enable adb root on device.""" | 156 """Enable adb root on device.""" |
153 output = self.SendCommand("root") | 157 output = self.SendCommand("root") |
154 if "adbd is already running as root" in output: | 158 if "adbd is already running as root" in output: |
155 return True | 159 return True |
156 elif "restarting adbd as root" in output: | 160 elif "restarting adbd as root" in output: |
157 # device will disappear from adb, wait for it to come back | 161 # device will disappear from adb, wait for it to come back |
158 self.SendCommand("wait-for-device") | 162 self.SendCommand("wait-for-device") |
159 return True | 163 return True |
164 elif "adbd cannot run as root" in output: | |
165 return False | |
160 else: | 166 else: |
161 logger.Log("Unrecognized output from adb root: %s" % output) | 167 logger.Log("Unrecognized output from adb root: %s" % output) |
162 return False | 168 return False |
163 | 169 |
164 def StartInstrumentationForPackage( | 170 def StartInstrumentationForPackage( |
165 self, package_name, runner_name, timeout_time=60*10, | 171 self, package_name, runner_name, timeout_time=60*10, |
166 no_window_animation=False, instrumentation_args={}): | 172 no_window_animation=False, instrumentation_args={}): |
167 """Run instrumentation test for given package and runner. | 173 """Run instrumentation test for given package and runner. |
168 | 174 |
169 Equivalent to StartInstrumentation, except instrumentation path is | 175 Equivalent to StartInstrumentation, except instrumentation path is |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
504 # press the MENU key, this will disable key guard if runtime is started | 510 # press the MENU key, this will disable key guard if runtime is started |
505 # with ro.monkey set to 1 | 511 # with ro.monkey set to 1 |
506 self.SendShellCommand("input keyevent 82", retry_count=retry_count) | 512 self.SendShellCommand("input keyevent 82", retry_count=retry_count) |
507 else: | 513 else: |
508 self.WaitForDevicePm() | 514 self.WaitForDevicePm() |
509 return output | 515 return output |
510 | 516 |
511 def GetSerialNumber(self): | 517 def GetSerialNumber(self): |
512 """Returns the serial number of the targeted device.""" | 518 """Returns the serial number of the targeted device.""" |
513 return self.SendCommand("get-serialno").strip() | 519 return self.SendCommand("get-serialno").strip() |
OLD | NEW |