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 |
54 def SendCommand(self, command_string, timeout_time=20, retry_count=3): | 69 def SendCommand(self, command_string, timeout_time=20, retry_count=3): |
55 """Send a command via adb. | 70 """Send a command via adb. |
56 | 71 |
57 Args: | 72 Args: |
58 command_string: adb command to run | 73 command_string: adb command to run |
59 timeout_time: number of seconds to wait for command to respond before | 74 timeout_time: number of seconds to wait for command to respond before |
60 retrying | 75 retrying |
61 retry_count: number of times to retry command before raising | 76 retry_count: number of times to retry command before raising |
62 WaitForResponseTimedOutError | 77 WaitForResponseTimedOutError |
63 Returns: | 78 Returns: |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 raise | 427 raise |
413 # ignore otherwise | 428 # ignore otherwise |
414 | 429 |
415 if not success: | 430 if not success: |
416 time.sleep(wait_period) | 431 time.sleep(wait_period) |
417 attempts += 1 | 432 attempts += 1 |
418 | 433 |
419 if not success: | 434 if not success: |
420 raise errors.WaitForResponseTimedOutError() | 435 raise errors.WaitForResponseTimedOutError() |
421 | 436 |
| 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 |
422 def WaitForBootComplete(self, wait_time=120): | 470 def WaitForBootComplete(self, wait_time=120): |
423 """Waits for targeted device's bootcomplete flag to be set. | 471 """Waits for targeted device's bootcomplete flag to be set. |
424 | 472 |
425 Args: | 473 Args: |
426 wait_time: time in seconds to wait | 474 wait_time: time in seconds to wait |
427 | 475 |
428 Raises: | 476 Raises: |
429 WaitForResponseTimedOutError if wait_time elapses and pm still does not | 477 WaitForResponseTimedOutError if wait_time elapses and pm still does not |
430 respond. | 478 respond. |
431 """ | 479 """ |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 # press the MENU key, this will disable key guard if runtime is started | 546 # press the MENU key, this will disable key guard if runtime is started |
499 # with ro.monkey set to 1 | 547 # with ro.monkey set to 1 |
500 self.SendShellCommand("input keyevent 82", retry_count=retry_count) | 548 self.SendShellCommand("input keyevent 82", retry_count=retry_count) |
501 else: | 549 else: |
502 self.WaitForDevicePm() | 550 self.WaitForDevicePm() |
503 return output | 551 return output |
504 | 552 |
505 def GetSerialNumber(self): | 553 def GetSerialNumber(self): |
506 """Returns the serial number of the targeted device.""" | 554 """Returns the serial number of the targeted device.""" |
507 return self.SendCommand("get-serialno").strip() | 555 return self.SendCommand("get-serialno").strip() |
OLD | NEW |