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

Various changes #46

11 changes: 10 additions & 1 deletion lib/ParamedicConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 () {
Expand Down
10 changes: 9 additions & 1 deletion lib/ParamedicTargetChooser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down
28 changes: 26 additions & 2 deletions lib/paramedic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -332,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;
});
})
Expand Down
20 changes: 20 additions & 0 deletions lib/utils/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = /(^(?!.*(emulator)).*device.*$)/m;
janpio marked this conversation as resolved.
Show resolved Hide resolved

var KILL_SIGNAL = 'SIGINT';

Expand All @@ -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);
}
Expand Down Expand Up @@ -218,6 +237,7 @@ module.exports = {
secToMin: secToMin,
isWindows: isWindows,
countAndroidDevices: countAndroidDevices,
getAndroidPhysicalDevice: getAndroidPhysicalDevice,
getSimulatorsFolder: getSimulatorsFolder,
doesFileExist: doesFileExist,
getSqlite3InsertionCommand: getSqlite3InsertionCommand,
Expand Down