From 8c6548b7f1373ea788e8da5c6c6a781251abdeca Mon Sep 17 00:00:00 2001 From: Johan Lantz Date: Tue, 12 Jun 2018 17:17:31 +0200 Subject: [PATCH 1/6] Support Android devices --- lib/ParamedicTargetChooser.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/ParamedicTargetChooser.js b/lib/ParamedicTargetChooser.js index c3544db9..6b162ad3 100644 --- a/lib/ParamedicTargetChooser.js +++ b/lib/ParamedicTargetChooser.js @@ -53,6 +53,14 @@ ParamedicTargetChooser.prototype.chooseTarget = function (emulator, target) { ParamedicTargetChooser.prototype.chooseTargetForAndroid = function (emulator, target) { logger.info('cordova-paramedic: Choosing Target for Android'); + + if (target) { + logger.info('cordova-paramedic: Target defined as: ' + target); + var obj = {}; + obj.target = target; + return obj; + } + return this.startAnAndroidEmulator(target).then(function(emulatorId) { var obj = {}; obj.target = emulatorId; From 5cf6d0039e4a1a6decd0e468496aacf79f0ee7b5 Mon Sep 17 00:00:00 2001 From: johanlantz Date: Wed, 13 Jun 2018 17:17:37 +0200 Subject: [PATCH 2/6] Prefer physical dev (#2) --- lib/ParamedicTargetChooser.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/ParamedicTargetChooser.js b/lib/ParamedicTargetChooser.js index 6b162ad3..edc913fa 100644 --- a/lib/ParamedicTargetChooser.js +++ b/lib/ParamedicTargetChooser.js @@ -59,7 +59,15 @@ ParamedicTargetChooser.prototype.chooseTargetForAndroid = function (emulator, ta var obj = {}; obj.target = target; return obj; - } + } + + var connectedPhysicalDevice = util.getAndroidPhysicalDevice(); + if (connectedPhysicalDevice) { + logger.info('cordova-paramedic: Physical device connected, use: ' + connectedPhysicalDevice); + var obj = {}; + obj.target = connectedPhysicalDevice; + return obj; + } return this.startAnAndroidEmulator(target).then(function(emulatorId) { var obj = {}; From d792d053203373149a7ed84e550832219d541a79 Mon Sep 17 00:00:00 2001 From: johanlantz Date: Wed, 13 Jun 2018 18:07:12 +0200 Subject: [PATCH 3/6] get server ip automatically (#3) --- lib/ParamedicConfig.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/ParamedicConfig.js b/lib/ParamedicConfig.js index cdb955a8..6de77049 100644 --- a/lib/ParamedicConfig.js +++ b/lib/ParamedicConfig.js @@ -30,6 +30,8 @@ var BROWSERIFY_ARG = '--browserify '; var DEFAULT_CLI = 'cordova'; // use globally installed cordova by default var util = require('./utils').utilities; +var ip = require('ip'); +var logger = require('./utils').logger; function ParamedicConfig(json) { this._config = json; @@ -152,7 +154,14 @@ ParamedicConfig.prototype.setPlugins = function (plugins) { }; ParamedicConfig.prototype.getExternalServerUrl = function () { - return this._config.externalServerUrl; + if (this._config.externalServerUrl) { + return this._config.externalServerUrl; + } else { + // Android emulator defaults to 10.0.0.2 for some reason. If that is needed, it must be passed using the externalServerUrl parameter + var serverIp = "http://" + ip.address(); + logger.info("Using local server address = " + serverIp); + return serverIp; + } }; ParamedicConfig.prototype.isVerbose = function () { From 4ef56f30f4c1f66328d94bc398b29e3d8dfbccb5 Mon Sep 17 00:00:00 2001 From: johanlantz Date: Wed, 20 Jun 2018 14:56:51 +0200 Subject: [PATCH 4/6] manage android permissions (#4) --- lib/paramedic.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/paramedic.js b/lib/paramedic.js index a4947190..325ba569 100644 --- a/lib/paramedic.js +++ b/lib/paramedic.js @@ -244,6 +244,20 @@ ParamedicRunner.prototype.setPermissions = function () { paramediciOSPermissions.updatePermissions(applicationsToGrantPermission); } } + + if(this.config.getPlatformId() === util.ANDROID) { + var self = this; + self.server.on('jasmineStarted', function (data) { + logger.info('cordova-paramedic: Jasmine started'); + logger.warn('Requesting permissions'); + cp.exec("adb shell pm grant " + util.PARAMEDIC_DEFAULT_APP_NAME + " android.permission.READ_PHONE_STATE"); + cp.exec("adb shell pm grant " + util.PARAMEDIC_DEFAULT_APP_NAME + " android.permission.READ_SMS"); + cp.exec("adb shell pm grant " + util.PARAMEDIC_DEFAULT_APP_NAME + " android.permission.READ_CALL_LOG"); + cp.exec("adb shell pm grant " + util.PARAMEDIC_DEFAULT_APP_NAME + " android.permission.ACCESS_FINE_LOCATION"); + cp.exec("adb shell pm grant " + util.PARAMEDIC_DEFAULT_APP_NAME + " android.permission.ACCESS_COARSE_LOCATION"); + cp.exec("adb shell pm grant " + util.PARAMEDIC_DEFAULT_APP_NAME + " android.permission.RECORD_AUDIO"); + }); + } }; ParamedicRunner.prototype.injectReporters = function () { From 66b6b278dbe5484ce35f5c7e0f6c286c2eef87e7 Mon Sep 17 00:00:00 2001 From: Johan Lantz Date: Wed, 20 Jun 2018 16:46:15 +0200 Subject: [PATCH 5/6] add missing physical device function --- lib/utils/utilities.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/utils/utilities.js b/lib/utils/utilities.js index a2c7fbb1..5970c33b 100644 --- a/lib/utils/utilities.js +++ b/lib/utils/utilities.js @@ -29,6 +29,7 @@ var kill = require('tree-kill'); var HEADING_LINE_PATTERN = /List of devices/m; var DEVICE_ROW_PATTERN = /(emulator|device|host)/m; +var DEVICE_ONLY_ROW_PATTERN = /(device)/m; var KILL_SIGNAL = 'SIGINT'; @@ -52,6 +53,24 @@ function countAndroidDevices() { return numDevices; } +function getAndroidPhysicalDevice() { + var listCommand = 'adb devices'; + + logger.info('running:'); + logger.info(' ' + listCommand); + + var numDevices = 0; + var result = shelljs.exec(listCommand, {silent: false, async: false}); + var deviceId = null; + result.output.split('\n').forEach(function (line) { + if (!HEADING_LINE_PATTERN.test(line) && DEVICE_ONLY_ROW_PATTERN.test(line)) { + deviceId = line.split('\t')[0]; + logger.info("Identified deviceId as: " + deviceId); + } + }); + return deviceId; +} + function secToMin(seconds) { return Math.ceil(seconds / 60); } @@ -218,6 +237,7 @@ module.exports = { secToMin: secToMin, isWindows: isWindows, countAndroidDevices: countAndroidDevices, + getAndroidPhysicalDevice: getAndroidPhysicalDevice, getSimulatorsFolder: getSimulatorsFolder, doesFileExist: doesFileExist, getSqlite3InsertionCommand: getSqlite3InsertionCommand, From 99931a313647c9251426248e758a3e734ba1f6f3 Mon Sep 17 00:00:00 2001 From: Johan Lantz Date: Fri, 22 Jun 2018 10:34:04 +0200 Subject: [PATCH 6/6] Ensure output is posted to console after child process finishes --- lib/paramedic.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/paramedic.js b/lib/paramedic.js index 325ba569..937340af 100644 --- a/lib/paramedic.js +++ b/lib/paramedic.js @@ -346,8 +346,18 @@ ParamedicRunner.prototype.runLocalTests = function () { if (!self.config.getPlatformId() === util.BROWSER) { return execPromise(command); } - runProcess = cp.exec(command, function () { - // a precaution not to try to kill some other process + // We do not wait for the child process to finish, server connects when deployed and ready. + runProcess = cp.exec(command, (error, stdout, stderr) => { + if (error) { + // This won't show up until the process completes: + console.log('[ERROR]: Running cordova run failed'); + + console.log(stdout); + console.log(stderr); + reject(error); + } + console.log(stdout); + console.log(stderr); runProcess = null; }); })