Skip to content

Commit

Permalink
Merge pull request appium#1347 from jlipps/master
Browse files Browse the repository at this point in the history
fix unlock retry logic so we actually unlock
  • Loading branch information
bootstraponline committed Oct 24, 2013
2 parents 16f4254 + fe61ec8 commit 461a397
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions lib/devices/android/android-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,21 +211,27 @@ androidCommon.unlockScreen = function(cb) {
this.adb.isScreenLocked(function(err, isLocked) {
if (err) return cb(err);
if (isLocked) {
this.adb.startApp("io.appium.unlock", ".Unlock", function(err) {
if (err) return cb(err);
var intervalRepeat = 500;
var interval = function() {
var timeoutMs = 10000;
var start = Date.now();
var unlockAndCheck = function() {
logger.debug("Screen is locked, trying to unlock");
this.adb.startApp("io.appium.unlock", ".Unlock", function(err) {
if (err) return cb(err);
this.adb.isScreenLocked(function(err, isLocked) {
if (err) return cb(err);
if (isLocked) {
setTimeout(interval, intervalRepeat);
} else {
cb();
if (!isLocked) {
logger.debug("Screen is unlocked, continuing");
return cb();
}
});
}.bind(this);
setTimeout(interval, intervalRepeat);
}.bind(this));
if ((Date.now() - timeoutMs) > start) {
return cb(new Error("Screen did not unlock"));
} else {
setTimeout(unlockAndCheck, 1000);
}
}.bind(this));
}.bind(this));
}.bind(this);
unlockAndCheck();
} else {
logger.debug('Screen already unlocked, continuing.');
cb();
Expand Down

0 comments on commit 461a397

Please sign in to comment.