1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-04 02:09:32 +02:00

Start HTTP API on device.

This commit is contained in:
Simo Kinnunen 2014-01-29 11:44:28 +09:00
parent 2f2e4b6f31
commit 403c29c60a
2 changed files with 104 additions and 0 deletions

View file

@ -1,4 +1,8 @@
var util = require('util')
var path = require('path')
var split = require('split')
var Promise = require('bluebird')
var wire = require('../wire')
var pathutil = require('./pathutil')
@ -22,6 +26,68 @@ devutil.vendorFiles = function(identity) {
}
}
devutil.killProcsByBin = function(adb, serial, bin) {
var basename = path.basename(bin)
return adb.shellAsync(serial, ['ps', basename])
.then(function(out) {
return new Promise(function(resolve, reject) {
var header = false
, killables = []
out.pipe(split())
.on('data', function(chunk) {
if (header) {
header = false
}
else {
var cols = chunk.toString().split(/\s+/)
if (cols.pop() === bin) {
killables.push(cols[1])
}
}
})
.on('end', function() {
resolve(killables)
})
})
})
.then(function(killables) {
if (killables.length) {
return adb.shellAsync(serial, ['kill'].concat(killables))
.then(function(out) {
return new Promise(function(resolve, reject) {
out.on('end', resolve)
})
})
}
})
}
devutil.startProp = function(adb, serial, cmd) {
return adb.openTcpAsync(options.serial, port)
.then(function(conn) {
conn.end()
})
.catch(function(err) {
if (err.message === 'closed') {
var cmd = [
vendor.bin.dest
, '--lib', vendor.lib.dest
, '--listen-http', port
]
return adb.shellAsync(options.serial, cmd)
.then(function(out) {
out.on('end', function() {
log.fatal('')
})
})
}
else {
throw err
}
})
}
devutil.platform = function(platform) {
switch (platform) {
case 'android':