mirror of
https://github.com/openstf/stf
synced 2025-10-04 18:29:17 +02:00
Port to new adbkit.
This commit is contained in:
parent
ca401d7b9c
commit
d90d450400
4 changed files with 38 additions and 32 deletions
|
@ -65,7 +65,7 @@ module.exports = function(options) {
|
|||
})
|
||||
|
||||
// Adb
|
||||
var adb = Promise.promisifyAll(adbkit.createClient())
|
||||
var adb = adbkit.createClient()
|
||||
|
||||
// Input
|
||||
var sub = zmq.socket('sub')
|
||||
|
@ -101,13 +101,13 @@ module.exports = function(options) {
|
|||
selfDestruct()
|
||||
})
|
||||
|
||||
promiseutil.periodicNotify(adb.waitBootCompleteAsync(options.serial), 1000)
|
||||
promiseutil.periodicNotify(adb.waitBootComplete(options.serial), 1000)
|
||||
.progressed(function() {
|
||||
log.info('Waiting for boot to complete')
|
||||
})
|
||||
.then(function() {
|
||||
log.info('Gathering properties')
|
||||
return adb.getPropertiesAsync(options.serial)
|
||||
return adb.getProperties(options.serial)
|
||||
})
|
||||
.then(function(properties) {
|
||||
log.info('Solving identity')
|
||||
|
@ -118,9 +118,10 @@ module.exports = function(options) {
|
|||
return Promise.all(Object.keys(vendor).map(function(id) {
|
||||
var res = vendor[id]
|
||||
log.info(util.format('Pushing vendor file "%s"', res.dest))
|
||||
return adb.pushAsync(options.serial, res.src, res.dest, res.mode)
|
||||
return adb.push(options.serial, res.src, res.dest, res.mode)
|
||||
.then(function(transfer) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
transfer.on('error', reject)
|
||||
transfer.on('end', resolve)
|
||||
})
|
||||
})
|
||||
|
@ -148,7 +149,7 @@ module.exports = function(options) {
|
|||
return devutil.ensureUnusedPort(adb, options.serial, 2870)
|
||||
.then(function(port) {
|
||||
var log = logger.createLogger('device:remote:http')
|
||||
return adb.shellAsync(options.serial, [
|
||||
return adb.shell(options.serial, [
|
||||
vendor.bin.dest
|
||||
, '--lib', vendor.lib.dest
|
||||
, '--listen-http', port
|
||||
|
@ -173,7 +174,7 @@ module.exports = function(options) {
|
|||
|
||||
log.info('Opening device HTTP API forwarder on "%s"', url)
|
||||
|
||||
return adb.forwardAsync(
|
||||
return adb.forward(
|
||||
options.serial
|
||||
, util.format('tcp:%d', ours)
|
||||
, util.format('tcp:%d', port)
|
||||
|
@ -295,7 +296,7 @@ module.exports = function(options) {
|
|||
return devutil.ensureUnusedPort(adb, options.serial, 2820)
|
||||
.then(function(port) {
|
||||
var log = logger.createLogger('device:remote:touch')
|
||||
return adb.shellAsync(options.serial, [
|
||||
return adb.shell(options.serial, [
|
||||
vendor.bin.dest
|
||||
, '--lib', vendor.lib.dest
|
||||
, '--listen-input', port
|
||||
|
@ -327,7 +328,7 @@ module.exports = function(options) {
|
|||
return devutil.ensureUnusedPort(adb, options.serial, 2830)
|
||||
.then(function(port) {
|
||||
var log = logger.createLogger('device:remote:stats')
|
||||
return adb.shellAsync(options.serial, [
|
||||
return adb.shell(options.serial, [
|
||||
vendor.bin.dest
|
||||
, '--lib', vendor.lib.dest
|
||||
, '--listen-stats', port
|
||||
|
@ -343,7 +344,7 @@ module.exports = function(options) {
|
|||
})
|
||||
.then(function() {
|
||||
log.info('Launching logcat service')
|
||||
return adb.openLogcatAsync(options.serial)
|
||||
return adb.openLogcat(options.serial)
|
||||
.then(function(logcat) {
|
||||
services.logcat = vitals.register('device:logcat', logcat)
|
||||
resetLogcat()
|
||||
|
@ -489,7 +490,7 @@ module.exports = function(options) {
|
|||
, seq = 0
|
||||
|
||||
log.info('Running shell command "%s"', message.command)
|
||||
adb.shellAsync(options.serial, message.command)
|
||||
adb.shell(options.serial, message.command)
|
||||
.then(function(stream) {
|
||||
var resolver = Promise.defer()
|
||||
, timer
|
||||
|
|
|
@ -14,7 +14,7 @@ var procutil = require('../util/procutil')
|
|||
|
||||
module.exports = function(options) {
|
||||
var log = logger.createLogger('provider')
|
||||
var client = Promise.promisifyAll(adb.createClient())
|
||||
var client = adb.createClient()
|
||||
var workers = {}
|
||||
var solo = wireutil.makePrivateChannel()
|
||||
var lists = {
|
||||
|
@ -81,7 +81,7 @@ module.exports = function(options) {
|
|||
})
|
||||
|
||||
// Track and manage devices
|
||||
client.trackDevicesAsync().then(function(tracker) {
|
||||
client.trackDevices().then(function(tracker) {
|
||||
log.info('Tracking devices')
|
||||
|
||||
// Helper for ignoring unwanted devices
|
||||
|
@ -349,6 +349,16 @@ module.exports = function(options) {
|
|||
flippedTracker.emit(device.id, 'remove', device)
|
||||
}))
|
||||
|
||||
tracker.on('error', function(err) {
|
||||
log.fatal('Tracker had an error:', err.stack)
|
||||
process.exit(1)
|
||||
})
|
||||
|
||||
tracker.on('end', function() {
|
||||
log.fatal('Tracker ended')
|
||||
process.exit(1)
|
||||
})
|
||||
|
||||
sub.on('message', wirerouter()
|
||||
.on(wire.DeviceRegisteredMessage, function(channel, message) {
|
||||
flippedTracker.emit(message.serial, 'register')
|
||||
|
|
|
@ -30,7 +30,7 @@ util.inherits(IncompatibleVersionError, Error)
|
|||
inputAgent.IncompatibleVersionError = IncompatibleVersionError
|
||||
|
||||
inputAgent.getInstalledPath = function(adb, serial) {
|
||||
return adb.shellAsync(serial, util.format("pm path '%s'", pkg))
|
||||
return adb.shell(serial, util.format("pm path '%s'", pkg))
|
||||
.then(function(out) {
|
||||
return streamutil.findLine(out, (/^package:/))
|
||||
.then(function(line) {
|
||||
|
@ -42,7 +42,7 @@ inputAgent.getInstalledPath = function(adb, serial) {
|
|||
inputAgent.ensureInstalled = function(adb, serial) {
|
||||
return inputAgent.getInstalledPath(adb, serial)
|
||||
.then(function(installedPath) {
|
||||
return adb.shellAsync(serial, util.format(
|
||||
return adb.shell(serial, util.format(
|
||||
"export CLASSPATH='%s';"
|
||||
+ ' exec app_process /system/bin'
|
||||
+ ' jp.co.cyberagent.stf.input.agent.InputAgent --version'
|
||||
|
@ -63,7 +63,7 @@ inputAgent.ensureInstalled = function(adb, serial) {
|
|||
})
|
||||
})
|
||||
.catch(function() {
|
||||
return adb.installAsync(serial, apk)
|
||||
return adb.install(serial, apk)
|
||||
.then(function() {
|
||||
return inputAgent.getInstalledPath(adb, serial)
|
||||
})
|
||||
|
@ -73,7 +73,7 @@ inputAgent.ensureInstalled = function(adb, serial) {
|
|||
inputAgent.openAgent = function(adb, serial) {
|
||||
return inputAgent.ensureInstalled(adb, serial)
|
||||
.then(function(installedPath) {
|
||||
return adb.shellAsync(serial, util.format(
|
||||
return adb.shell(serial, util.format(
|
||||
"export CLASSPATH='%s';"
|
||||
+ ' exec app_process /system/bin'
|
||||
+ ' jp.co.cyberagent.stf.input.agent.InputAgent'
|
||||
|
@ -87,7 +87,7 @@ inputAgent.openService = function(adb, serial) {
|
|||
.then(function() {
|
||||
var intent =
|
||||
'-a jp.co.cyberagent.stf.input.agent.InputService.ACTION_START'
|
||||
return adb.shellAsync(serial, util.format(
|
||||
return adb.shell(serial, util.format(
|
||||
'am startservice --user 0 %s || am startservice %s'
|
||||
, intent
|
||||
, intent
|
||||
|
@ -97,7 +97,7 @@ inputAgent.openService = function(adb, serial) {
|
|||
|
||||
inputAgent.stopService = function(adb, serial) {
|
||||
var intent = '-a jp.co.cyberagent.stf.input.agent.InputService.ACTION_STOP'
|
||||
return adb.shellAsync(serial, util.format(
|
||||
return adb.shell(serial, util.format(
|
||||
'am startservice --user 0 %s || am startservice %s'
|
||||
, intent
|
||||
, intent
|
||||
|
|
|
@ -10,6 +10,10 @@ var pathutil = require('./pathutil')
|
|||
|
||||
var devutil = module.exports = Object.create(null)
|
||||
|
||||
function closedError(err) {
|
||||
return err.message.indexOf('closed') !== -1
|
||||
}
|
||||
|
||||
devutil.matchesRequirements = function(capabilities, requirements) {
|
||||
return requirements.every(function(req) {
|
||||
var capability = capabilities[req.name]
|
||||
|
@ -61,10 +65,7 @@ devutil.vendorFiles = function(identity) {
|
|||
}
|
||||
|
||||
devutil.ensureUnusedPort = function(adb, serial, port) {
|
||||
function closedError(err) {
|
||||
return err.message === 'closed'
|
||||
}
|
||||
return adb.openTcpAsync(serial, port)
|
||||
return adb.openTcp(serial, port)
|
||||
.then(function(conn) {
|
||||
conn.end()
|
||||
throw new Error(util.format('Port "%d" should be unused', port))
|
||||
|
@ -75,10 +76,7 @@ devutil.ensureUnusedPort = function(adb, serial, port) {
|
|||
}
|
||||
|
||||
devutil.waitForPort = function(adb, serial, port) {
|
||||
function closedError(err) {
|
||||
return err.message === 'closed'
|
||||
}
|
||||
return adb.openTcpAsync(serial, port)
|
||||
return adb.openTcp(serial, port)
|
||||
.then(function(conn) {
|
||||
conn.port = port
|
||||
return conn
|
||||
|
@ -92,10 +90,7 @@ devutil.waitForPort = function(adb, serial, port) {
|
|||
}
|
||||
|
||||
devutil.waitForPortToFree = function(adb, serial, port) {
|
||||
function closedError(err) {
|
||||
return err.message === 'closed'
|
||||
}
|
||||
return adb.openTcpAsync(serial, port)
|
||||
return adb.openTcp(serial, port)
|
||||
.then(function(conn) {
|
||||
var resolver = Promise.defer()
|
||||
|
||||
|
@ -126,7 +121,7 @@ devutil.listPidsByComm = function(adb, serial, comm, bin) {
|
|||
shell: true
|
||||
}
|
||||
|
||||
return adb.shellAsync(serial, ['ps', comm])
|
||||
return adb.shell(serial, ['ps', comm])
|
||||
.then(function(out) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
var header = false
|
||||
|
@ -168,7 +163,7 @@ devutil.killProcsByComm = function(adb, serial, comm, bin, mode) {
|
|||
if (!pids.length) {
|
||||
return Promise.resolve()
|
||||
}
|
||||
return adb.shellAsync(serial, ['kill', mode || -15].concat(pids))
|
||||
return adb.shell(serial, ['kill', mode || -15].concat(pids))
|
||||
.then(function(out) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
out.on('end', resolve)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue