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

Prefer physical Android device if connected #58

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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;

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