Skip to content

Commit

Permalink
Fix: Retry unlock command when it times out
Browse files Browse the repository at this point in the history
The command passed to the Android emulator's shell to unlock the device can
  be killed by ADB if the device takes too long to accept the command.
  To fix, we retry the command until it succeeds.
  • Loading branch information
eromba committed Oct 16, 2011
1 parent 713cec7 commit 7d19f49
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions jtd-android-init.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,23 @@ def AndroidBrowserIsCaptured():
# the screen by pressing the Menu button.
subprocess.call([ADB_PATH, "shell", "input", "keyevent", "3"])


#
# Unlock the Android emulator's screen
# Unfortunately, there is no way to detect whether the screen is locked from
# the command line. In any event, we unlock the screen by sending the
# keyevent corresponding to the Menu button once the emulator is initialized.
subprocess.call([ADB_PATH, "wait-for-device", "shell", "input", "keyevent", "82"])
#


# There is no way to detect whether the screen is locked from the command line,
# but if it is, we can unlock it by sending the keyevent corresponding to the
# Menu button once the emulator is initialized. This command may timeout if
# the emulator takes too long to load, so we retry until it succeeds.
print("\nUnlocking Android device...")
while 1:
unlockProc = subprocess.Popen([ADB_PATH, "wait-for-device", "shell", "input", "keyevent", "82"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
result = unlockProc.communicate()[0].decode("utf-8")
if result.find("Killed") == -1:
print("Device unlocked\n")
break


#
Expand Down

0 comments on commit 7d19f49

Please sign in to comment.