Merge branch 'develop' of http://ghe.amb.ca.local/stf/stf into develop

Conflicts:
	res/app/components/stf/screen/screen.jade
	res/app/device-control/device-control.css
	res/app/scripts/controllers/DeviceScreenCtrl.js
	res/app/scripts/services/ControlService.js
This commit is contained in:
Gunther Brunner
2014-02-19 18:24:12 +09:00
13 changed files with 530 additions and 76 deletions

View File

@@ -8,7 +8,6 @@ var validator = require('express-validator')
var socketio = require('socket.io')
var zmq = require('zmq')
var Promise = require('bluebird')
var adb = require('adbkit')
var logger = require('../util/logger')
var pathutil = require('../util/pathutil')
@@ -309,32 +308,6 @@ module.exports = function(options) {
])
})
function fixedKeySender(klass, key) {
return function(channel) {
push.send([
channel
, wireutil.envelope(new klass(
key
))
])
}
}
socket.on('input.back', fixedKeySender(
wire.KeyPressMessage
, adb.Keycode.KEYCODE_BACK
))
socket.on('input.home', fixedKeySender(
wire.KeyPressMessage
, adb.Keycode.KEYCODE_HOME
))
socket.on('input.menu', fixedKeySender(
wire.KeyPressMessage
, adb.Keycode.KEYCODE_MENU
))
socket.on('flick', function(data) {})
socket.on('back', function(data) {})
socket.on('forward', function(data) {})

View File

@@ -19,6 +19,8 @@ var pathutil = require('../util/pathutil')
var promiseutil = require('../util/promiseutil')
var Vitals = require('../util/vitals')
var ChannelManager = require('../wire/channelmanager')
var keyutil = require('../util/keyutil')
var inputAgent = require('../services/inputagent')
module.exports = function(options) {
var log = logger.createLogger('device')
@@ -37,7 +39,6 @@ module.exports = function(options) {
}
, services = {
input: null
, monkey: null
, logcat: null
}
@@ -137,8 +138,8 @@ module.exports = function(options) {
, devutil.killProcsByComm(
adb
, options.serial
, 'commands.monkey'
, 'com.android.commands.monkey'
, 'app_process'
, 'app_process'
)
])
})
@@ -233,18 +234,19 @@ module.exports = function(options) {
})
})
.then(function() {
log.info('Launching monkey service')
return devutil.ensureUnusedPort(adb, options.serial, 1080)
log.info('Launching InputAgent')
return devutil.ensureUnusedPort(adb, options.serial, 1090)
.then(function(port) {
var log = logger.createLogger('device:remote:monkey')
return adb.shellAsync(options.serial, util.format(
// Some devices fail without an SD card installed; we can
// fake an external storage using this method
'EXTERNAL_STORAGE=/data/local/tmp monkey --port %d'
, port
))
var log = logger.createLogger('device:inputAgent')
return promiseutil.periodicNotify(
inputAgent.open(adb, options.serial)
, 1000
)
.progressed(function() {
log.info('Waiting for InputAgent')
})
.then(function(out) {
vitals.register('device:remote:monkey:shell', out)
vitals.register('device:inputAgent:shell', out)
out.pipe(split())
.on('data', function(chunk) {
log.info(chunk)
@@ -256,12 +258,9 @@ module.exports = function(options) {
return devutil.waitForPort(adb, options.serial, port)
})
.then(function(conn) {
return monkey.connectStream(conn)
})
.then(function(monkey) {
services.monkey = vitals.register(
'device:remote:monkey:monkey'
, Promise.promisifyAll(monkey)
services.inputAgentSocket = vitals.register(
'device:inputAgent:socket'
, conn
)
})
})
@@ -378,29 +377,30 @@ module.exports = function(options) {
log.error('tap failed', err.stack)
})
})
.on(wire.TypeMessage, function(channel, message) {
services.monkey.typeAsync(message.text)
.catch(function(err) {
log.error('type failed', err.stack)
})
})
.on(wire.KeyDownMessage, function(channel, message) {
services.monkey.keyDownAsync(message.key)
.catch(function(err) {
log.error('keyDown failed', err.stack)
})
inputAgent.sendInputEvent(services.inputAgentSocket, {
action: 0
, keyCode: keyutil.unwire(message.keyCode)
})
})
.on(wire.KeyUpMessage, function(channel, message) {
services.monkey.keyUpAsync(message.key)
.catch(function(err) {
log.error('keyUp failed', err.stack)
})
inputAgent.sendInputEvent(services.inputAgentSocket, {
action: 1
, keyCode: keyutil.unwire(message.keyCode)
})
})
.on(wire.KeyPressMessage, function(channel, message) {
services.monkey.pressAsync(message.key)
.catch(function(err) {
log.error('keyPress failed', err.stack)
})
inputAgent.sendInputEvent(services.inputAgentSocket, {
action: 2
, keyCode: keyutil.unwire(message.keyCode)
})
})
.on(wire.TypeMessage, function(channel, message) {
inputAgent.sendInputEvent(services.inputAgentSocket, {
action: 3
, keyCode: 0
, text: message.text
})
})
.on(wire.LogcatApplyFiltersMessage, function(channel, message) {
resetLogcat()

View File

@@ -30,7 +30,7 @@ module.exports = function(options) {
function totals() {
if (lists.waiting.length) {
log.info(
'Providing %d of %d device(s), and still waiting for "%s"'
'Providing %d of %d device(s); waiting for "%s"'
, lists.ready.length
, lists.all.length
, lists.waiting.join('", "')
@@ -38,10 +38,17 @@ module.exports = function(options) {
delayedTotals()
}
else if (lists.ready.length < lists.all.length) {
log.info(
'Providing all %d of %d device(s); ignoring "%s"'
, lists.ready.length
, lists.all.length
, _.difference(lists.all, lists.ready).join('", "')
)
}
else {
log.info(
'Providing all %d of %d device(s)'
, lists.ready.length
'Providing all %d device(s)'
, lists.all.length
)
}
@@ -298,6 +305,8 @@ module.exports = function(options) {
proc.on('error', errorListener)
proc.on('message', messageListener)
lists.waiting.push(device.id)
return resolver.promise
.finally(function() {
log.info('Cleaning up device worker "%s"', device.id)