mirror of
https://github.com/openstf/stf
synced 2025-10-04 10:19:30 +02:00
Use InputAgent for the keyboard.
This commit is contained in:
parent
30fdc62711
commit
bc9d356d7f
12 changed files with 323 additions and 83 deletions
48
lib/services/inputagent.js
Normal file
48
lib/services/inputagent.js
Normal file
|
@ -0,0 +1,48 @@
|
|||
var util = require('util')
|
||||
|
||||
var Promise = require('bluebird')
|
||||
var ProtoBuf = require('protobufjs')
|
||||
var ByteBuffer = require('protobufjs/node_modules/bytebuffer')
|
||||
var split = require('split')
|
||||
|
||||
var pathutil = require('../util/pathutil')
|
||||
var streamutil = require('../util/streamutil')
|
||||
|
||||
var proto = ProtoBuf.loadProtoFile(
|
||||
pathutil.vendor('InputAgent/inputAgentProtocol.proto')
|
||||
).build().jp.co.cyberagent.stf.input.agent
|
||||
|
||||
var inputAgent = module.exports = Object.create(null)
|
||||
|
||||
inputAgent.open = function(adb, serial) {
|
||||
return adb.installAsync(serial, pathutil.vendor('InputAgent/InputAgent.apk'))
|
||||
.then(function() {
|
||||
return adb.shellAsync(serial, 'pm path jp.co.cyberagent.stf.input.agent')
|
||||
})
|
||||
.then(function(out) {
|
||||
return streamutil.findLine(out, (/^package:/))
|
||||
.then(function(line) {
|
||||
return line.substr(8)
|
||||
})
|
||||
})
|
||||
.then(function(apk) {
|
||||
return adb.shellAsync(serial, util.format(
|
||||
"export CLASSPATH='%s';"
|
||||
+ ' exec app_process /system/bin'
|
||||
+ ' jp.co.cyberagent.stf.input.agent.InputAgent'
|
||||
, apk
|
||||
))
|
||||
})
|
||||
}
|
||||
|
||||
inputAgent.sendInputEvent = function(agent, event) {
|
||||
var lengthBuffer = new ByteBuffer()
|
||||
, messageBuffer = new proto.InputEvent(event).encode()
|
||||
|
||||
lengthBuffer.writeVarint32(messageBuffer.length)
|
||||
|
||||
agent.write(Buffer.concat([
|
||||
lengthBuffer.toBuffer()
|
||||
, messageBuffer.toBuffer()
|
||||
]))
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue