summaryrefslogtreecommitdiff
path: root/StoneIsland/platforms/android/cordova/lib/device.js
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2017-02-16 01:24:12 +0100
committerJules Laplace <jules@okfoc.us>2017-02-16 01:24:12 +0100
commit30c49550c89c1b69c680170d2dc247eac76bd463 (patch)
tree8732652298b630b9ba15def97e59738f1c9bf7b6 /StoneIsland/platforms/android/cordova/lib/device.js
parent8f1f626384e6ba75f4fb24c27e0973260a74421b (diff)
push plugin
Diffstat (limited to 'StoneIsland/platforms/android/cordova/lib/device.js')
-rw-r--r--[-rwxr-xr-x]StoneIsland/platforms/android/cordova/lib/device.js81
1 files changed, 40 insertions, 41 deletions
diff --git a/StoneIsland/platforms/android/cordova/lib/device.js b/StoneIsland/platforms/android/cordova/lib/device.js
index c13fdc40..4b171db6 100755..100644
--- a/StoneIsland/platforms/android/cordova/lib/device.js
+++ b/StoneIsland/platforms/android/cordova/lib/device.js
@@ -19,40 +19,30 @@
under the License.
*/
-var exec = require('./exec'),
- Q = require('q'),
- os = require('os'),
- build = require('./build'),
- appinfo = require('./appinfo');
+var Q = require('q'),
+ build = require('./build');
+var path = require('path');
+var Adb = require('./Adb');
+var AndroidManifest = require('./AndroidManifest');
+var spawn = require('cordova-common').superspawn.spawn;
+var CordovaError = require('cordova-common').CordovaError;
+var events = require('cordova-common').events;
/**
* Returns a promise for the list of the device ID's found
* @param lookHarder When true, try restarting adb if no devices are found.
*/
module.exports.list = function(lookHarder) {
- function helper() {
- return exec('adb devices', os.tmpdir())
- .then(function(output) {
- var response = output.split('\n');
- var device_list = [];
- for (var i = 1; i < response.length; i++) {
- if (response[i].match(/\w+\tdevice/) && !response[i].match(/emulator/)) {
- device_list.push(response[i].replace(/\tdevice/, '').replace('\r', ''));
- }
- }
- return device_list;
- });
- }
- return helper()
+ return Adb.devices()
.then(function(list) {
if (list.length === 0 && lookHarder) {
// adb kill-server doesn't seem to do the trick.
// Could probably find a x-platform version of killall, but I'm not actually
// sure that this scenario even happens on non-OSX machines.
- return exec('killall adb')
+ return spawn('killall', ['adb'])
.then(function() {
- console.log('Restarting adb to see if more devices are detected.');
- return helper();
+ events.emit('verbose', 'Restarting adb to see if more devices are detected.');
+ return Adb.devices();
}, function() {
// For non-killall OS's.
return list;
@@ -66,7 +56,7 @@ module.exports.resolveTarget = function(target) {
return this.list(true)
.then(function(device_list) {
if (!device_list || !device_list.length) {
- return Q.reject('ERROR: Failed to deploy to device, no devices found.');
+ return Q.reject(new CordovaError('Failed to deploy to device, no devices found.'));
}
// default device
target = target || device_list[0];
@@ -95,27 +85,36 @@ module.exports.install = function(target, buildResults) {
return module.exports.resolveTarget(target);
}).then(function(resolvedTarget) {
var apk_path = build.findBestApkForArchitecture(buildResults, resolvedTarget.arch);
- var launchName = appinfo.getActivityName();
- console.log('Using apk: ' + apk_path);
- console.log('Installing app on device...');
- var cmd = 'adb -s ' + resolvedTarget.target + ' install -r "' + apk_path + '"';
- return exec(cmd, os.tmpdir())
- .then(function(output) {
- if (output.match(/Failure/)) return Q.reject('ERROR: Failed to install apk to device: ' + output);
+ var manifest = new AndroidManifest(path.join(__dirname, '../../AndroidManifest.xml'));
+ var pkgName = manifest.getPackageId();
+ var launchName = pkgName + '/.' + manifest.getActivity().getName();
+ events.emit('log', 'Using apk: ' + apk_path);
+ events.emit('log', 'Package name: ' + pkgName);
- //unlock screen
- var cmd = 'adb -s ' + resolvedTarget.target + ' shell input keyevent 82';
- return exec(cmd, os.tmpdir());
- }, function(err) { return Q.reject('ERROR: Failed to install apk to device: ' + err); })
+ return Adb.install(resolvedTarget.target, apk_path, {replace: true})
+ .catch(function (error) {
+ // CB-9557 CB-10157 only uninstall and reinstall app if the one that
+ // is already installed on device was signed w/different certificate
+ if (!/INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES/.test(error.toString()))
+ throw error;
+
+ events.emit('warn', 'Uninstalling app from device and reinstalling it again because the ' +
+ 'installed app already signed with different key');
+
+ // This promise is always resolved, even if 'adb uninstall' fails to uninstall app
+ // or the app doesn't installed at all, so no error catching needed.
+ return Adb.uninstall(resolvedTarget.target, pkgName)
+ .then(function() {
+ return Adb.install(resolvedTarget.target, apk_path, {replace: true});
+ });
+ })
.then(function() {
- // launch the application
- console.log('Launching application...');
- var cmd = 'adb -s ' + resolvedTarget.target + ' shell am start -W -a android.intent.action.MAIN -n ' + launchName;
- return exec(cmd, os.tmpdir());
+ //unlock screen
+ return Adb.shell(resolvedTarget.target, 'input keyevent 82');
+ }).then(function() {
+ return Adb.start(resolvedTarget.target, launchName);
}).then(function() {
- console.log('LAUNCH SUCCESS');
- }, function(err) {
- return Q.reject('ERROR: Failed to launch application on device: ' + err);
+ events.emit('log', 'LAUNCH SUCCESS');
});
});
};