mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-20 07:53:38 +02:00
Use InputAgent for the keyboard.
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user