Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #21162 from yurenju/callscreen
Browse files Browse the repository at this point in the history
Bug 1000049 - APP=callscreen make install-gaia should give some informat... r=@cctuan
  • Loading branch information
yurenju committed Jul 31, 2014
2 parents 34df823 + 96bdbd2 commit 061e9b8
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 23 deletions.
1 change: 0 additions & 1 deletion .jshintignore
Expand Up @@ -18,7 +18,6 @@ build/jsmin.js
build/optimize-clean.js
build/post-manifest.js
build/pre-app.js
build/push-to-device.js
build/settings.js
build/test/integration/build.test.js
build/test/integration/distribution.test.js
Expand Down
39 changes: 24 additions & 15 deletions build/push-to-device.js
@@ -1,5 +1,7 @@
'use strict';

/* global require, exports */

var utils = require('./utils');
var sh = new utils.Commander('sh');
var Q = utils.Q;
Expand Down Expand Up @@ -76,6 +78,7 @@ function getRemoteInstallPath(adb) {
var tempDirName = 'pushGaia' + Math.random().toString(36).substr(2, 8);
var tempDir = utils.getTempFolder(tempDirName);
var tempFile = tempDir.clone();
var content;
tempFile.append('webapps.json');

// Use |adb shell cat| instead of |adb pull| so we don't run into
Expand All @@ -87,7 +90,7 @@ function getRemoteInstallPath(adb) {
// If there were no webapps ever installed on the device (likely purged in
// the previous step), default to /system/b2g
try {
var content = utils.getJSON(tempFile);
content = utils.getJSON(tempFile);
} catch (e) {
return '/system/b2g';
}
Expand All @@ -102,20 +105,36 @@ function getRemoteInstallPath(adb) {
}
}
return '/data/local';
};
}

function execute(options) {
const buildAppName = options.BUILD_APP_NAME;
const gaiaDir = options.GAIA_DIR;
const profileFolder = options.PROFILE_DIR;
const gaiaDomain = options.GAIA_DOMAIN;
var remotePath = options.GAIA_INSTALL_PARENT;
var pid;
var manifest;
var restartB2g = true;

var mainQ = Q.defer();
var targetFolder;

var adb = options.ADB;

if (buildAppName !== '*') {
targetFolder = utils.joinPath(
profileFolder, 'webapps',
buildAppName + '.' + gaiaDomain);
// Some app folder name is different with the process name,
// ex. sms -> Messages
manifest = utils.readZipManifest(utils.getFile(targetFolder));
pid = utils.getPid(manifest.name, gaiaDir);

// don't restart b2g process if we found pid by app name
restartB2g = (pid === -1);
}

mainQ.resolve();
return mainQ.promise.then(function() {
var profile = utils.getFile(profileFolder);
Expand All @@ -129,7 +148,7 @@ function execute(options) {
utils.log('push', 'Waiting for device ...');
return sh.run(['-c', adb + ' wait-for-device']);
}).then(function() {
if (buildAppName === '*' || buildAppName === 'system') {
if (restartB2g) {
return sh.run(['-c', adb + ' shell stop b2g']);
}
}).then(function() {
Expand All @@ -149,9 +168,6 @@ function execute(options) {
if (buildAppName === '*') {
return pushToDevice(profileFolder, remotePath, adb);
} else {
targetFolder = utils.joinPath(
profileFolder, 'webapps',
buildAppName + '.' + gaiaDomain);
return installOneApp(targetFolder, buildAppName,
remotePath, gaiaDomain, adb);
}
Expand All @@ -160,22 +176,15 @@ function execute(options) {
return installSvoperapps(profileFolder, adb);
}
}).then(function() {
if (buildAppName === '*' || buildAppName === 'system') {
if (restartB2g) {
utils.log('push', 'Restarting B2G...');
sh.run(['-c', adb + ' shell start b2g']);
} else {
var Q3 = Q.defer();
var manifest;
var appPid;
Q3.resolve();
return Q3.promise.then(function() {
// Some app folder name is different with the process name,
// ex. sms -> Messages
manifest = utils.readZipManifest(utils.getFile(
targetFolder));
}).then(function() {
utils.log('push', 'Restarting ' + manifest.name + '...');
utils.killAppByPid(manifest.name, gaiaDir);
utils.killAppByPid(pid);
});
}
});
Expand Down
5 changes: 4 additions & 1 deletion build/test/unit/push-to-device.test.js
Expand Up @@ -167,6 +167,9 @@ suite('push-to-device.js', function() {
};
return pidMap;
};
mockUtils.getPid = function(appName, gaiaDir) {
return appID;
};
var queue = app.execute(options);
queue.done(function() {
assert.deepEqual(mockUtils.hasRunCommands, {
Expand All @@ -185,7 +188,7 @@ suite('push-to-device.js', function() {
'/application.zip" /' + options.GAIA_INSTALL_PARENT +
'/webapps/' + options.BUILD_APP_NAME + '.' +
options.GAIA_DOMAIN + '/application.zip',
'-c adb shell kill testApp']});
'-c adb shell kill ' + appID]});
done();
});
});
Expand Down
29 changes: 23 additions & 6 deletions build/utils-xpc.js
Expand Up @@ -996,15 +996,17 @@ function getEnvPath() {
return paths;
}


/**
* Kill one running app by PID.
* @param appName {string} - the app name
* @param gaiaDir {string} - the absolute path to Gaia directory
* get pid from device via adb
* @param {string} appName - the app name
* @param {string} gaiaDir - the absolute path to Gaia directory
* @return {number} - process id
*/
function killAppByPid(appName, gaiaDir) {

function getPid(appName, gaiaDir) {
var sh = new Commander('sh');
sh.initPath(getEnvPath(), function() {});

var tempFileName = 'tmpFile';
var tmpFileSrc = joinPath(gaiaDir, tempFileName);
sh.run(['-c', 'touch ' + tempFileName]);
Expand All @@ -1013,13 +1015,27 @@ function killAppByPid(appName, gaiaDir) {
var content = getFileContent(tempFile);
var pidMap = utils.psParser(content);
sh.run(['-c', 'rm ' + tempFileName]);

// b2g-ps only show first 15 letters of app name
var truncatedAppName = appName.substr(0, 15);
if (pidMap[truncatedAppName] && pidMap[truncatedAppName].PID) {
sh.run(['-c', 'adb shell kill ' + pidMap[truncatedAppName].PID]);
return pidMap[truncatedAppName].PID;
} else {
return -1;
}
}


/**
* Kill one running app by PID.
* @param pid {number} - process id to kill in device
*/
function killAppByPid(pid) {
var sh = new Commander('sh');
sh.initPath(getEnvPath(), function() {});
sh.run(['-c', 'adb shell kill ' + pid]);
}

/**
* Give the stringified HTML to parse it as DOM tree.
* @param content {string} - the HTML content
Expand Down Expand Up @@ -1225,6 +1241,7 @@ exports.processEvents = processEvents;
exports.readZipManifest = readZipManifest;
exports.log = log;
exports.killAppByPid = killAppByPid;
exports.getPid = getPid;
exports.getEnv = getEnv;
exports.isExternalApp = isExternalApp;
exports.getDocument = getDocument;
Expand Down
1 change: 1 addition & 0 deletions build/utils.js
Expand Up @@ -264,6 +264,7 @@ exports.processEvents = utils.processEvents;
exports.log = utils.log;
exports.getExtension = getExtension;
exports.killAppByPid = utils.killAppByPid;
exports.getPid = utils.getPid;
exports.getEnv = utils.getEnv;
exports.isExternalApp = utils.isExternalApp;
exports.getDocument = utils.getDocument;
Expand Down

0 comments on commit 061e9b8

Please sign in to comment.