| 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 RestartAdbServer(self): | |
| 55 """Restart the adb server.""" | |
| 56 self.KillAdbServer() | |
| 57 self.StartAdbServer() | |
| 58 | |
| 59 def KillAdbServer(self): | |
| 60 """Kill adb server.""" | |
| 61 adb_cmd = "adb kill-server" | |
| 62 return run_command.RunCommand(adb_cmd) | |
| 63 | |
| 64 def StartAdbServer(self): | |
| 65 """Start adb server.""" | |
| 66 adb_cmd = "adb start-server" | |
| 67 return run_command.RunCommand(adb_cmd) | |
| 68 | |
| 69 def SendCommand(self, command_string, timeout_time=20, retry_count=3): | 54 def SendCommand(self, command_string, timeout_time=20, retry_count=3): |
| 70 """Send a command via adb. | 55 """Send a command via adb. |
| 71 | 56 |
| 72 Args: | 57 Args: |
| 73 command_string: adb command to run | 58 command_string: adb command to run |
| 74 timeout_time: number of seconds to wait for command to respond before | 59 timeout_time: number of seconds to wait for command to respond before |
| 75 retrying | 60 retrying |
| 76 retry_count: number of times to retry command before raising | 61 retry_count: number of times to retry command before raising |
| 77 WaitForResponseTimedOutError | 62 WaitForResponseTimedOutError |
| 78 Returns: | 63 Returns: |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 raise | 412 raise |
| 428 # ignore otherwise | 413 # ignore otherwise |
| 429 | 414 |
| 430 if not success: | 415 if not success: |
| 431 time.sleep(wait_period) | 416 time.sleep(wait_period) |
| 432 attempts += 1 | 417 attempts += 1 |
| 433 | 418 |
| 434 if not success: | 419 if not success: |
| 435 raise errors.WaitForResponseTimedOutError() | 420 raise errors.WaitForResponseTimedOutError() |
| 436 | 421 |
| 437 def WaitForSystemBootCompleted(self, wait_time=120): | |
| 438 """Waits for targeted system's boot_completed flag to be set. | |
| 439 | |
| 440 Args: | |
| 441 wait_time: time in seconds to wait | |
| 442 | |
| 443 Raises: | |
| 444 WaitForResponseTimedOutError if wait_time elapses and flag still not | |
| 445 set. | |
| 446 """ | |
| 447 logger.Log("Waiting for system boot completed...") | |
| 448 self.SendCommand("wait-for-device") | |
| 449 # Now the device is there, but system not boot completed. | |
| 450 # Query the sys.boot_completed flag with a basic command | |
| 451 boot_completed = False | |
| 452 attempts = 0 | |
| 453 wait_period = 5 | |
| 454 while not boot_completed and (attempts*wait_period) < wait_time: | |
| 455 output = self.SendShellCommand("getprop sys.boot_completed", retry_count=1
) | |
| 456 output = output.strip() | |
| 457 if output == "1": | |
| 458 boot_completed = True | |
| 459 else: | |
| 460 # If 'error: xxx' returned when querying the flag, it means | |
| 461 # adb server lost the connection to the emulator, so restart the adb ser
ver. | |
| 462 if "error:" in output: | |
| 463 self.RestartAdbServer() | |
| 464 time.sleep(wait_period) | |
| 465 attempts += 1 | |
| 466 if not boot_completed: | |
| 467 raise errors.WaitForResponseTimedOutError( | |
| 468 "sys.boot_completed flag was not set after %s seconds" % wait_time) | |
| 469 | |
| 470 def WaitForBootComplete(self, wait_time=120): | 422 def WaitForBootComplete(self, wait_time=120): |
| 471 """Waits for targeted device's bootcomplete flag to be set. | 423 """Waits for targeted device's bootcomplete flag to be set. |
| 472 | 424 |
| 473 Args: | 425 Args: |
| 474 wait_time: time in seconds to wait | 426 wait_time: time in seconds to wait |
| 475 | 427 |
| 476 Raises: | 428 Raises: |
| 477 WaitForResponseTimedOutError if wait_time elapses and pm still does not | 429 WaitForResponseTimedOutError if wait_time elapses and pm still does not |
| 478 respond. | 430 respond. |
| 479 """ | 431 """ |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 # press the MENU key, this will disable key guard if runtime is started | 498 # press the MENU key, this will disable key guard if runtime is started |
| 547 # with ro.monkey set to 1 | 499 # with ro.monkey set to 1 |
| 548 self.SendShellCommand("input keyevent 82", retry_count=retry_count) | 500 self.SendShellCommand("input keyevent 82", retry_count=retry_count) |
| 549 else: | 501 else: |
| 550 self.WaitForDevicePm() | 502 self.WaitForDevicePm() |
| 551 return output | 503 return output |
| 552 | 504 |
| 553 def GetSerialNumber(self): | 505 def GetSerialNumber(self): |
| 554 """Returns the serial number of the targeted device.""" | 506 """Returns the serial number of the targeted device.""" |
| 555 return self.SendCommand("get-serialno").strip() | 507 return self.SendCommand("get-serialno").strip() |
| OLD | NEW |