Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-26382] Android: Modified "appc run" to dismiss screen-lock before running built app #10318

Merged
merged 3 commits into from
Sep 18, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
72 changes: 46 additions & 26 deletions android/cli/hooks/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,33 +352,53 @@ exports.init = function (logger, config, cli) {

(function startApp() {
logger.debug(__('Trying to start the app...'));
adb.startApp(device.id, builder.appid, builder.classname + 'Activity', function (err) { // eslint-disable-line no-unused-vars
if (watchingPid) {
return;
async.series([
function (next) {
// Power on the screen if currently off.
adb.shell(device.id, 'input keyevent KEYCODE_MENU', next);
},
function (next) {
// Remove the screen-lock and show the home screen.
adb.shell(device.id, 'input keyevent KEYCODE_MENU', next);
},
function (next) {
// If the screen-lock was never shown to begin with, then the above might show
// the home screen's page selection interface. Clear out of it with the home key.
adb.shell(device.id, 'input keyevent KEYCODE_HOME', next);
},
function (next) {
// Launch the app's main activity.
// Note: The above ensures that the activiy is onscreen. This is especially needed
// for automated testing since some UI events won't happen while backgrounded.
adb.startApp(device.id, builder.appid, builder.classname + 'Activity', function (err) { // eslint-disable-line no-unused-vars
if (watchingPid) {
return;
}
watchingPid = true;

let done = false;
async.whilst(
function () { return !done; },
function (cb2) {
adb.getPid(device.id, builder.appid, function (err, pid) {
if (err || !pid) {
setTimeout(cb2, 250);
} else {
clearTimeout(intervalTimer);
clearTimeout(abortTimer);

logger.info(__('Application pid: %s', String(pid).cyan));
device.appPidRegExp = new RegExp('\\(\\s*' + pid + '\\):'); // eslint-disable-line security/detect-non-literal-regexp
done = true;
setTimeout(cb2, 0);
}
});
},
next
);
});
}
watchingPid = true;

let done = false;
async.whilst(
function () { return !done; },
function (cb2) {
adb.getPid(device.id, builder.appid, function (err, pid) {
if (err || !pid) {
setTimeout(cb2, 250);
} else {
clearTimeout(intervalTimer);
clearTimeout(abortTimer);

logger.info(__('Application pid: %s', String(pid).cyan));
device.appPidRegExp = new RegExp('\\(\\s*' + pid + '\\):'); // eslint-disable-line security/detect-non-literal-regexp
done = true;
setTimeout(cb2, 0);
}
});
},
cb
);
});
], cb);

intervalTimer = setTimeout(function () {
logger.debug(__('App still not started, trying again'));
Expand Down