Permalink
Browse files

[FIXED JENKINS-30849] Use dedicated screen unlock command on Android 6+.

  • Loading branch information...
orrc committed Mar 28, 2016
1 parent 983c962 commit bfabc6714f0d83a01e39a6951adb445d8d3854e0
Showing with 12 additions and 5 deletions.
  1. +12 −5 src/main/java/hudson/plugins/android_emulator/AndroidEmulator.java
@@ -431,16 +431,23 @@ else if (!emulatorAlreadyExists || emuConfig.shouldWipeData() || snapshotState =

log(logger, Messages.UNLOCKING_SCREEN());
final long adbTimeout = BOOT_COMPLETE_TIMEOUT_MS / 16;
final String keyEventArgs = String.format("-s %s shell input keyevent %%d", emu.serial());
final String menuArgs = String.format(keyEventArgs, 82);
ArgumentListBuilder menuCmd = emu.getToolCommand(Tool.ADB, menuArgs);
final String keyEventTemplate = String.format("-s %s shell input keyevent %%d", emu.serial());
final String unlockArgs;
if (emuConfig.getOsVersion().getSdkLevel() < 23) {
unlockArgs = String.format(keyEventTemplate, 82);
} else {
// Android 6.0 introduced a command to dismiss the keyguard on unsecured devices
unlockArgs = String.format("-s %s shell wm dismiss-keyguard", emu.serial());
}
ArgumentListBuilder menuCmd = emu.getToolCommand(Tool.ADB, unlockArgs);
Proc proc = emu.getProcStarter(menuCmd).start();
proc.joinWithTimeout(adbTimeout, TimeUnit.MILLISECONDS, emu.launcher().getListener());

// If a named emulator already existed, it may not have been booted yet, so the screen
// wouldn't be locked. Similarly, an non-named emulator may have already booted the
// first time without us knowing. In both cases, we press Back after Menu to compensate
final String backArgs = String.format(keyEventArgs, 4);
// first time without us knowing. In both cases, we press Back after attempting to
// unlock the screen to compensate
final String backArgs = String.format(keyEventTemplate, 4);
ArgumentListBuilder backCmd = emu.getToolCommand(Tool.ADB, backArgs);
proc = emu.getProcStarter(backCmd).start();
proc.joinWithTimeout(adbTimeout, TimeUnit.MILLISECONDS, emu.launcher().getListener());

0 comments on commit bfabc67

Please sign in to comment.