cordova-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dblotsky <...@git.apache.org>
Subject [GitHub] cordova-android pull request: CB-9119 Fixing intermittent 'adb ins...
Date Tue, 09 Jun 2015 02:04:31 GMT
Github user dblotsky commented on a diff in the pull request:

    https://github.com/apache/cordova-android/pull/180#discussion_r31977783
  
    --- Diff: bin/templates/cordova/lib/emulator.js ---
    @@ -298,37 +306,67 @@ module.exports.resolveTarget = function(target) {
      * If no started emulators are found, error out.
      * Returns a promise.
      */
    -module.exports.install = function(target, buildResults) {
    -    return Q().then(function() {
    -        if (target && typeof target == 'object') {
    -            return target;
    +module.exports.install = function(givenTarget, buildResults) {
    +
    +    var target;
    +
    +    // resolve the target emulator
    +    return Q().then(function () {
    +        if (givenTarget && typeof givenTarget == 'object') {
    +            return givenTarget;
    +        } else {
    +            return module.exports.resolveTarget(givenTarget);
             }
    -        return module.exports.resolveTarget(target);
    -    }).then(function(resolvedTarget) {
    -        var apk_path = build.findBestApkForArchitecture(buildResults, resolvedTarget.arch);
    +
    +    // set the resolved target
    +    }).then(function (resolvedTarget) {
    +        target = resolvedTarget;
    +
    +    // install the app
    +    }).then(function () {
    +
    +        var apk_path    = build.findBestApkForArchitecture(buildResults, target.arch);
    +        var execOptions = {
    +            timeout:    INSTALL_COMMAND_TIMEOUT, // in milliseconds
    +            killSignal: EXEC_KILL_SIGNAL
    +        };
    +
             console.log('Installing app on emulator...');
             console.log('Using apk: ' + apk_path);
    -        return exec('adb -s ' + resolvedTarget.target + ' install -r -d "' + apk_path
+ '"', os.tmpdir())
    -        .then(function(output) {
    +
    +        var retriedInstall = retry.retryPromise(
    +            NUM_INSTALL_RETRIES,
    +            exec, 'adb -s ' + target.target + ' install -r -d "' + apk_path + '"', os.tmpdir(),
execOptions
    +        );
    +
    +        return retriedInstall.then(function (output) {
                 if (output.match(/Failure/)) {
                     return Q.reject('Failed to install apk to emulator: ' + output);
    +            } else {
    +                console.log('INSTALL SUCCESS');
                 }
    -            return Q();
    -        }, function(err) {
    +        }, function (err) {
                 return Q.reject('Failed to install apk to emulator: ' + err);
    -        }).then(function() {
    -            //unlock screen
    -            return exec('adb -s ' + resolvedTarget.target + ' shell input keyevent 82',
os.tmpdir());
    -        }).then(function() {
    -            // launch the application
    -            console.log('Launching application...');
    -            var launchName = appinfo.getActivityName();
    -            var cmd = 'adb -s ' + resolvedTarget.target + ' shell am start -W -a android.intent.action.MAIN
-n ' + launchName;
    -            return exec(cmd, os.tmpdir());
    -        }).then(function(output) {
    -            console.log('LAUNCH SUCCESS');
    -        }, function(err) {
    -            return Q.reject('Failed to launch app on emulator: ' + err);
             });
    +
    +    // unlock screen
    +    }).then(function () {
    +
    +        console.log('Unlocking screen...');
    +        return exec('adb -s ' + target.target + ' shell input keyevent 82', os.tmpdir());
    +
    +    // launch the application
    --- End diff --
    
    If the console logs get removed (for example, to make the function less verbose), the
comments will remain.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


Mime
View raw message