mirror of
https://github.com/openstf/stf
synced 2025-10-05 02:29:26 +02:00
Fix all lib/ files with ESLint rules with 0 errors.
This commit is contained in:
parent
994977ea94
commit
434f63b3a9
69 changed files with 793 additions and 764 deletions
|
@ -18,7 +18,7 @@ module.exports = syrup.serial()
|
|||
return service.getAccounts({type: type})
|
||||
.timeout(30000)
|
||||
.then(function(accounts) {
|
||||
if(accounts.indexOf(account) >= 0) {
|
||||
if (accounts.indexOf(account) >= 0) {
|
||||
return true
|
||||
}
|
||||
throw new Error('The account is not added')
|
||||
|
@ -28,7 +28,7 @@ module.exports = syrup.serial()
|
|||
router.on(wire.AccountCheckMessage, function(channel, message) {
|
||||
var reply = wireutil.reply(options.serial)
|
||||
|
||||
log.info('Checking if account "%s" is added',message.account)
|
||||
log.info('Checking if account "%s" is added', message.account)
|
||||
checkAccount(message.type, message.account)
|
||||
.then(function() {
|
||||
push.send([
|
||||
|
@ -55,7 +55,7 @@ module.exports = syrup.serial()
|
|||
.then(function(accounts) {
|
||||
push.send([
|
||||
channel
|
||||
, reply.okay('success',accounts)
|
||||
, reply.okay('success', accounts)
|
||||
])
|
||||
})
|
||||
.catch(function(err) {
|
||||
|
@ -113,12 +113,12 @@ module.exports = syrup.serial()
|
|||
|
||||
router.on(wire.AccountAddMessage, function(channel, message) {
|
||||
var reply = wireutil.reply(options.serial)
|
||||
var type = "com.google"
|
||||
var account = message.user + "@gmail.com";
|
||||
var type = 'com.google'
|
||||
var account = message.user + '@gmail.com'
|
||||
|
||||
log.info('Adding Google Account automatedly')
|
||||
|
||||
var version = identity.version.substring(0,3)
|
||||
var version = identity.version.substring(0, 3)
|
||||
|
||||
function automation() {
|
||||
switch (version) {
|
||||
|
@ -235,8 +235,8 @@ module.exports = syrup.serial()
|
|||
.then(function() {
|
||||
return service.pressKey('enter')
|
||||
})
|
||||
//case '4.3': // tested: 4.3
|
||||
//case '4.4': // tested: 4.4.2
|
||||
// case '4.3': // tested: 4.3
|
||||
// case '4.4': // tested: 4.4.2
|
||||
default:
|
||||
return service.pressKey('tab').delay(1000)
|
||||
.then(function() {
|
||||
|
@ -293,17 +293,17 @@ module.exports = syrup.serial()
|
|||
.delay(5000)
|
||||
.then(function() {
|
||||
// Just in case the add account menu has any button focused
|
||||
return touch.tap({x:0, y:0.9})
|
||||
return touch.tap({x: 0, y: 0.9})
|
||||
})
|
||||
.delay(500)
|
||||
.then(function() {
|
||||
return automation()
|
||||
})
|
||||
.delay(3000)
|
||||
.then(function () {
|
||||
.then(function() {
|
||||
return service.pressKey('home')
|
||||
})
|
||||
.then(function () {
|
||||
.then(function() {
|
||||
return checkAccount(type, account)
|
||||
})
|
||||
.then(function() {
|
||||
|
|
|
@ -51,8 +51,17 @@ module.exports = syrup.serial()
|
|||
|
||||
function compareIgnoreCase(a, b) {
|
||||
var la = (a || '').toLowerCase()
|
||||
, lb = (b || '').toLowerCase()
|
||||
return la === lb ? 0 : (la < lb ? -1 : 1)
|
||||
var lb = (b || '').toLowerCase()
|
||||
|
||||
if (la === lb) {
|
||||
return 0
|
||||
}
|
||||
else if (la < lb) {
|
||||
return -1
|
||||
}
|
||||
else {
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
||||
function updateBrowsers(data) {
|
||||
|
|
|
@ -40,7 +40,6 @@ module.exports = syrup.serial()
|
|||
group.on('leave', function() {
|
||||
plugin.removePackages()
|
||||
})
|
||||
|
||||
})
|
||||
.return(plugin)
|
||||
})
|
||||
|
|
|
@ -18,8 +18,8 @@ module.exports = syrup.serial()
|
|||
.dependency(require('./util/urlformat'))
|
||||
.define(function(options, adb, router, push, group, solo, urlformat) {
|
||||
var log = logger.createLogger('device:plugins:connect')
|
||||
, plugin = Object.create(null)
|
||||
, activeServer = null
|
||||
var plugin = Object.create(null)
|
||||
var activeServer = null
|
||||
|
||||
plugin.port = options.connectPort
|
||||
plugin.url = urlformat(options.connectUrlPattern, plugin.port)
|
||||
|
|
|
@ -44,7 +44,7 @@ module.exports = syrup.serial()
|
|||
if (/closed/.test(err.message) && times > 1) {
|
||||
return Promise.delay(delay)
|
||||
.then(function() {
|
||||
return tryConnect(--times, delay * 2)
|
||||
return tryConnect(times - 1, delay * 2)
|
||||
})
|
||||
}
|
||||
return Promise.reject(err)
|
||||
|
|
|
@ -5,6 +5,115 @@ var net = require('net')
|
|||
var ForwardReader = require('./reader')
|
||||
var ForwardWriter = require('./writer')
|
||||
|
||||
// Handles a single connection
|
||||
function DestHandler(id, conn, options) {
|
||||
var dest = net.connect({
|
||||
host: options.targetHost
|
||||
, port: options.targetPort
|
||||
})
|
||||
|
||||
var writer = dest.pipe(new ForwardWriter(id))
|
||||
|
||||
// We can't just pipe to conn because we don't want to end it
|
||||
// when the dest closes. Instead we'll send a special packet
|
||||
// to it (which is handled by the writer).
|
||||
function maybePipeManually() {
|
||||
var chunk
|
||||
while ((chunk = writer.read())) {
|
||||
if (!conn.write(chunk)) {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function readableListener() {
|
||||
maybePipeManually()
|
||||
}
|
||||
|
||||
function drainListener() {
|
||||
maybePipeManually()
|
||||
}
|
||||
|
||||
function endListener() {
|
||||
conn.removeListener('drain', drainListener)
|
||||
writer.removeListener('readable', readableListener)
|
||||
this.emit('end')
|
||||
}
|
||||
|
||||
function errorListener() {
|
||||
writer.end()
|
||||
}
|
||||
|
||||
writer.on('end', endListener.bind(this))
|
||||
writer.on('readable', readableListener)
|
||||
dest.on('error', errorListener)
|
||||
conn.on('drain', drainListener)
|
||||
|
||||
this.end = function() {
|
||||
dest.end()
|
||||
}
|
||||
|
||||
this.write = function(chunk) {
|
||||
dest.write(chunk)
|
||||
}
|
||||
|
||||
events.EventEmitter.call(this)
|
||||
}
|
||||
|
||||
util.inherits(DestHandler, events.EventEmitter)
|
||||
|
||||
// Handles a single port
|
||||
function ForwardHandler(conn, options) {
|
||||
var destHandlersById = Object.create(null)
|
||||
|
||||
function endListener() {
|
||||
this.emit('end')
|
||||
}
|
||||
|
||||
function packetEndListener(id) {
|
||||
delete destHandlersById[id]
|
||||
}
|
||||
|
||||
function packetListener(id, packet) {
|
||||
var dest = destHandlersById[id]
|
||||
|
||||
if (packet) {
|
||||
if (!dest) {
|
||||
// Let's create a new connection
|
||||
dest = destHandlersById[id] = new DestHandler(id, conn, options)
|
||||
dest.on('end', packetEndListener.bind(null, id))
|
||||
}
|
||||
|
||||
dest.write(packet)
|
||||
}
|
||||
else {
|
||||
// It's a simulated fin packet
|
||||
if (dest) {
|
||||
dest.end()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function readableListener() {
|
||||
// No-op but must exist so that we get the 'end' event.
|
||||
}
|
||||
|
||||
conn.pipe(new ForwardReader())
|
||||
.on('end', endListener.bind(this))
|
||||
.on('packet', packetListener)
|
||||
.on('readable', readableListener)
|
||||
|
||||
this.options = options
|
||||
|
||||
this.end = function() {
|
||||
conn.end()
|
||||
}
|
||||
|
||||
events.EventEmitter.call(this)
|
||||
}
|
||||
|
||||
util.inherits(ForwardHandler, events.EventEmitter)
|
||||
|
||||
// Handles multiple ports
|
||||
function ForwardManager() {
|
||||
var handlersById = Object.create(null)
|
||||
|
@ -61,113 +170,4 @@ function ForwardManager() {
|
|||
|
||||
util.inherits(ForwardManager, events.EventEmitter)
|
||||
|
||||
// Handles a single port
|
||||
function ForwardHandler(conn, options) {
|
||||
var destHandlersById = Object.create(null)
|
||||
|
||||
function endListener() {
|
||||
this.emit('end')
|
||||
}
|
||||
|
||||
function packetEndListener(id) {
|
||||
delete destHandlersById[id]
|
||||
}
|
||||
|
||||
function packetListener(id, packet) {
|
||||
var dest = destHandlersById[id]
|
||||
|
||||
if (packet) {
|
||||
if (!dest) {
|
||||
// Let's create a new connection
|
||||
dest = destHandlersById[id] = new DestHandler(id, conn, options)
|
||||
dest.on('end', packetEndListener.bind(null, id))
|
||||
}
|
||||
|
||||
dest.write(packet)
|
||||
}
|
||||
else {
|
||||
// It's a simulated fin packet
|
||||
if (dest) {
|
||||
dest.end()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function readableListener() {
|
||||
// No-op but must exist so that we get the 'end' event.
|
||||
}
|
||||
|
||||
conn.pipe(new ForwardReader())
|
||||
.on('end', endListener.bind(this))
|
||||
.on('packet', packetListener)
|
||||
.on('readable', readableListener)
|
||||
|
||||
this.options = options
|
||||
|
||||
this.end = function() {
|
||||
conn.end()
|
||||
}
|
||||
|
||||
events.EventEmitter.call(this)
|
||||
}
|
||||
|
||||
util.inherits(ForwardHandler, events.EventEmitter)
|
||||
|
||||
// Handles a single connection
|
||||
function DestHandler(id, conn, options) {
|
||||
function endListener() {
|
||||
conn.removeListener('drain', drainListener)
|
||||
writer.removeListener('readable', readableListener)
|
||||
this.emit('end')
|
||||
}
|
||||
|
||||
function errorListener() {
|
||||
writer.end()
|
||||
}
|
||||
|
||||
function readableListener() {
|
||||
maybePipeManually()
|
||||
}
|
||||
|
||||
function drainListener() {
|
||||
maybePipeManually()
|
||||
}
|
||||
|
||||
// We can't just pipe to conn because we don't want to end it
|
||||
// when the dest closes. Instead we'll send a special packet
|
||||
// to it (which is handled by the writer).
|
||||
function maybePipeManually() {
|
||||
var chunk
|
||||
while ((chunk = writer.read())) {
|
||||
if (!conn.write(chunk)) {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var dest = net.connect({
|
||||
host: options.targetHost
|
||||
, port: options.targetPort
|
||||
})
|
||||
.on('error', errorListener)
|
||||
|
||||
var writer = dest.pipe(new ForwardWriter(id))
|
||||
.on('end', endListener.bind(this))
|
||||
.on('readable', readableListener)
|
||||
|
||||
conn.on('drain', drainListener)
|
||||
|
||||
this.end = function() {
|
||||
dest.end()
|
||||
}
|
||||
|
||||
this.write = function(chunk) {
|
||||
dest.write(chunk)
|
||||
}
|
||||
|
||||
events.EventEmitter.call(this)
|
||||
}
|
||||
|
||||
util.inherits(DestHandler, events.EventEmitter)
|
||||
|
||||
module.exports = ForwardManager
|
||||
|
|
|
@ -11,9 +11,9 @@ function ForwardWriter(target) {
|
|||
|
||||
util.inherits(ForwardWriter, stream.Transform)
|
||||
|
||||
ForwardWriter.prototype._transform = function(chunk, encoding, done) {
|
||||
var header
|
||||
, length
|
||||
ForwardWriter.prototype._transform = function(fullChunk, encoding, done) {
|
||||
var chunk = fullChunk
|
||||
var header, length
|
||||
|
||||
do {
|
||||
length = Math.min(MAX_PACKET_SIZE, chunk.length)
|
||||
|
|
|
@ -19,8 +19,8 @@ module.exports = syrup.serial()
|
|||
.dependency(require('../support/channels'))
|
||||
.define(function(options, solo, ident, service, router, push, sub, channels) {
|
||||
var log = logger.createLogger('device:plugins:group')
|
||||
, currentGroup = null
|
||||
, plugin = new events.EventEmitter()
|
||||
var currentGroup = null
|
||||
var plugin = new events.EventEmitter()
|
||||
|
||||
plugin.get = Promise.method(function() {
|
||||
if (!currentGroup) {
|
||||
|
|
|
@ -27,7 +27,7 @@ module.exports = syrup.serial()
|
|||
|
||||
router.on(wire.InstallMessage, function(channel, message) {
|
||||
var manifest = JSON.parse(message.manifest)
|
||||
, pkg = manifest.package
|
||||
var pkg = manifest.package
|
||||
|
||||
log.info('Installing package "%s" from "%s"', pkg, message.href)
|
||||
|
||||
|
@ -98,8 +98,8 @@ module.exports = syrup.serial()
|
|||
pushApp()
|
||||
.then(function(apk) {
|
||||
var start = 50
|
||||
, end = 90
|
||||
, guesstimate = start
|
||||
var end = 90
|
||||
var guesstimate = start
|
||||
|
||||
sendProgress('installing_app', guesstimate)
|
||||
return promiseutil.periodicNotify(
|
||||
|
|
|
@ -13,8 +13,8 @@ module.exports = syrup.serial()
|
|||
.dependency(require('./group'))
|
||||
.define(function(options, adb, router, push, group) {
|
||||
var log = logger.createLogger('device:plugins:logcat')
|
||||
, plugin = Object.create(null)
|
||||
, activeLogcat = null
|
||||
var plugin = Object.create(null)
|
||||
var activeLogcat = null
|
||||
|
||||
plugin.start = function(filters) {
|
||||
return group.get()
|
||||
|
|
|
@ -13,12 +13,12 @@ module.exports = syrup.serial()
|
|||
log.info('Will mute master volume during use')
|
||||
|
||||
group.on('join', function() {
|
||||
log.info('Muting master volume');
|
||||
log.info('Muting master volume')
|
||||
service.setMasterMute(true)
|
||||
})
|
||||
|
||||
group.on('leave', function() {
|
||||
log.info('Unmuting master volume');
|
||||
log.info('Unmuting master volume')
|
||||
service.setMasterMute(false)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -176,11 +176,13 @@ module.exports = syrup.serial()
|
|||
}
|
||||
|
||||
FrameProducer.prototype.nextFrame = function() {
|
||||
var frame = null, chunk
|
||||
var frame = null
|
||||
var chunk
|
||||
|
||||
if (this.parser) {
|
||||
while ((frame = this.parser.nextFrame()) === null) {
|
||||
if ((chunk = this.socket.stream.read())) {
|
||||
chunk = this.socket.stream.read()
|
||||
if (chunk) {
|
||||
this.parser.push(chunk)
|
||||
}
|
||||
else {
|
||||
|
@ -243,9 +245,9 @@ module.exports = syrup.serial()
|
|||
return lifecycle.fatal()
|
||||
}
|
||||
|
||||
var match
|
||||
if ((match = /^PID: (\d+)$/.exec(line))) {
|
||||
this.pid = +match[1]
|
||||
var match = /^PID: (\d+)$/.exec(line)
|
||||
if (match) {
|
||||
this.pid = Number(match[1])
|
||||
this.emit('pid', this.pid)
|
||||
}
|
||||
|
||||
|
@ -259,7 +261,7 @@ module.exports = syrup.serial()
|
|||
}
|
||||
|
||||
var pidListener
|
||||
return new Promise(function(resolve/*, reject*/) {
|
||||
return new Promise(function(resolve) {
|
||||
this.on('pid', pidListener = resolve)
|
||||
}.bind(this)).bind(this)
|
||||
.timeout(2000)
|
||||
|
@ -279,7 +281,7 @@ module.exports = syrup.serial()
|
|||
if (/closed/.test(err.message) && times > 1) {
|
||||
return Promise.delay(delay)
|
||||
.then(function() {
|
||||
return tryConnect(--times, delay * 2)
|
||||
return tryConnect(times - 1, delay * 2)
|
||||
})
|
||||
}
|
||||
return Promise.reject(err)
|
||||
|
@ -326,7 +328,7 @@ module.exports = syrup.serial()
|
|||
socket.stream.removeListener('readable', this.readableListener)
|
||||
|
||||
var endListener
|
||||
return new Promise(function(resolve/*, reject*/) {
|
||||
return new Promise(function(resolve) {
|
||||
socket.on('end', endListener = function() {
|
||||
resolve(true)
|
||||
})
|
||||
|
@ -354,8 +356,8 @@ module.exports = syrup.serial()
|
|||
}
|
||||
|
||||
var signum = {
|
||||
'SIGTERM': -15
|
||||
, 'SIGKILL': -9
|
||||
SIGTERM: -15
|
||||
, SIGKILL: -9
|
||||
}[signal]
|
||||
|
||||
log.info('Sending %s to minicap', signal)
|
||||
|
@ -478,8 +480,8 @@ module.exports = syrup.serial()
|
|||
})
|
||||
|
||||
frameProducer.on('readable', function next() {
|
||||
var frame
|
||||
if ((frame = frameProducer.nextFrame())) {
|
||||
var frame = frameProducer.nextFrame()
|
||||
if (frame) {
|
||||
Promise.settle([broadcastSet.keys().map(function(id) {
|
||||
return broadcastSet.get(id).onFrame(frame)
|
||||
})]).then(next)
|
||||
|
@ -557,8 +559,8 @@ module.exports = syrup.serial()
|
|||
}
|
||||
|
||||
ws.on('message', function(data) {
|
||||
var match
|
||||
if ((match = /^(on|off|(size) ([0-9]+)x([0-9]+))$/.exec(data))) {
|
||||
var match = /^(on|off|(size) ([0-9]+)x([0-9]+))$/.exec(data)
|
||||
if (match) {
|
||||
switch (match[2] || match[1]) {
|
||||
case 'on':
|
||||
broadcastSet.insert(id, {
|
||||
|
@ -570,7 +572,8 @@ module.exports = syrup.serial()
|
|||
broadcastSet.remove(id)
|
||||
break
|
||||
case 'size':
|
||||
frameProducer.updateProjection(+match[3], +match[4])
|
||||
frameProducer.updateProjection(
|
||||
Number(match[3]), Number(match[4]))
|
||||
break
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,12 +30,17 @@ FrameParser.prototype.nextFrame = function() {
|
|||
var bytesLeft = len - this.cursor
|
||||
|
||||
if (bytesLeft >= this.frameBodyLength) {
|
||||
var completeBody = this.frameBody
|
||||
? Buffer.concat([
|
||||
this.frameBody
|
||||
var completeBody
|
||||
if (this.frameBody) {
|
||||
completeBody = Buffer.concat([
|
||||
this.frameBody
|
||||
, this.chunk.slice(this.cursor, this.cursor + this.frameBodyLength)
|
||||
])
|
||||
: this.chunk.slice(this.cursor, this.cursor + this.frameBodyLength)
|
||||
])
|
||||
}
|
||||
else {
|
||||
completeBody = this.chunk.slice(this.cursor,
|
||||
this.cursor + this.frameBodyLength)
|
||||
}
|
||||
|
||||
this.cursor += this.frameBodyLength
|
||||
this.frameBodyLength = this.readFrameBytes = 0
|
||||
|
@ -46,9 +51,13 @@ FrameParser.prototype.nextFrame = function() {
|
|||
else {
|
||||
// @todo Consider/benchmark continuation frames to prevent
|
||||
// potential Buffer thrashing.
|
||||
this.frameBody = this.frameBody
|
||||
? Buffer.concat([this.frameBody, this.chunk.slice(this.cursor, len)])
|
||||
: this.chunk.slice(this.cursor, len)
|
||||
if (this.frameBody) {
|
||||
this.frameBody =
|
||||
Buffer.concat([this.frameBody, this.chunk.slice(this.cursor, len)])
|
||||
}
|
||||
else {
|
||||
this.frameBody = this.chunk.slice(this.cursor, len)
|
||||
}
|
||||
|
||||
this.frameBodyLength -= bytesLeft
|
||||
this.readFrameBytes += bytesLeft
|
||||
|
|
|
@ -52,6 +52,219 @@ module.exports = syrup.serial()
|
|||
, port: 1100
|
||||
}
|
||||
|
||||
function stopAgent() {
|
||||
return devutil.killProcsByComm(
|
||||
adb
|
||||
, options.serial
|
||||
, 'stf.agent'
|
||||
, 'stf.agent'
|
||||
)
|
||||
}
|
||||
|
||||
function callService(intent) {
|
||||
return adb.shell(options.serial, util.format(
|
||||
'am startservice --user 0 %s'
|
||||
, intent
|
||||
))
|
||||
.timeout(15000)
|
||||
.then(function(out) {
|
||||
return streamutil.findLine(out, /^Error/)
|
||||
.finally(function() {
|
||||
out.end()
|
||||
})
|
||||
.timeout(10000)
|
||||
.then(function(line) {
|
||||
if (line.indexOf('--user') !== -1) {
|
||||
return adb.shell(options.serial, util.format(
|
||||
'am startservice %s'
|
||||
, intent
|
||||
))
|
||||
.timeout(15000)
|
||||
.then(function() {
|
||||
return streamutil.findLine(out, /^Error/)
|
||||
.finally(function() {
|
||||
out.end()
|
||||
})
|
||||
.timeout(10000)
|
||||
.then(function(line) {
|
||||
throw new Error(util.format(
|
||||
'Service had an error: "%s"'
|
||||
, line
|
||||
))
|
||||
})
|
||||
.catch(streamutil.NoSuchLineError, function() {
|
||||
return true
|
||||
})
|
||||
})
|
||||
}
|
||||
else {
|
||||
throw new Error(util.format(
|
||||
'Service had an error: "%s"'
|
||||
, line
|
||||
))
|
||||
}
|
||||
})
|
||||
.catch(streamutil.NoSuchLineError, function() {
|
||||
return true
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function prepareForServiceDeath(conn) {
|
||||
function endListener() {
|
||||
var startTime = Date.now()
|
||||
log.important('Service connection ended, attempting to relaunch')
|
||||
|
||||
/* eslint no-use-before-define: 0 */
|
||||
openService()
|
||||
.timeout(5000)
|
||||
.then(function() {
|
||||
log.important('Service relaunched in %dms', Date.now() - startTime)
|
||||
})
|
||||
.catch(function(err) {
|
||||
log.fatal('Service connection could not be relaunched', err.stack)
|
||||
lifecycle.fatal()
|
||||
})
|
||||
}
|
||||
|
||||
conn.once('end', endListener)
|
||||
|
||||
conn.on('error', function(err) {
|
||||
log.fatal('Service connection had an error', err.stack)
|
||||
lifecycle.fatal()
|
||||
})
|
||||
}
|
||||
|
||||
function handleEnvelope(data) {
|
||||
var envelope = apk.wire.Envelope.decode(data)
|
||||
var message
|
||||
if (envelope.id !== null) {
|
||||
messageResolver.resolve(envelope.id, envelope.message)
|
||||
}
|
||||
else {
|
||||
switch (envelope.type) {
|
||||
case apk.wire.MessageType.EVENT_AIRPLANE_MODE:
|
||||
message = apk.wire.AirplaneModeEvent.decode(envelope.message)
|
||||
push.send([
|
||||
wireutil.global
|
||||
, wireutil.envelope(new wire.AirplaneModeEvent(
|
||||
options.serial
|
||||
, message.enabled
|
||||
))
|
||||
])
|
||||
plugin.emit('airplaneModeChange', message)
|
||||
break
|
||||
case apk.wire.MessageType.EVENT_BATTERY:
|
||||
message = apk.wire.BatteryEvent.decode(envelope.message)
|
||||
push.send([
|
||||
wireutil.global
|
||||
, wireutil.envelope(new wire.BatteryEvent(
|
||||
options.serial
|
||||
, message.status
|
||||
, message.health
|
||||
, message.source
|
||||
, message.level
|
||||
, message.scale
|
||||
, message.temp
|
||||
, message.voltage
|
||||
))
|
||||
])
|
||||
plugin.emit('batteryChange', message)
|
||||
break
|
||||
case apk.wire.MessageType.EVENT_BROWSER_PACKAGE:
|
||||
message = apk.wire.BrowserPackageEvent.decode(envelope.message)
|
||||
plugin.emit('browserPackageChange', message)
|
||||
break
|
||||
case apk.wire.MessageType.EVENT_CONNECTIVITY:
|
||||
message = apk.wire.ConnectivityEvent.decode(envelope.message)
|
||||
push.send([
|
||||
wireutil.global
|
||||
, wireutil.envelope(new wire.ConnectivityEvent(
|
||||
options.serial
|
||||
, message.connected
|
||||
, message.type
|
||||
, message.subtype
|
||||
, message.failover
|
||||
, message.roaming
|
||||
))
|
||||
])
|
||||
plugin.emit('connectivityChange', message)
|
||||
break
|
||||
case apk.wire.MessageType.EVENT_PHONE_STATE:
|
||||
message = apk.wire.PhoneStateEvent.decode(envelope.message)
|
||||
push.send([
|
||||
wireutil.global
|
||||
, wireutil.envelope(new wire.PhoneStateEvent(
|
||||
options.serial
|
||||
, message.state
|
||||
, message.manual
|
||||
, message.operator
|
||||
))
|
||||
])
|
||||
plugin.emit('phoneStateChange', message)
|
||||
break
|
||||
case apk.wire.MessageType.EVENT_ROTATION:
|
||||
message = apk.wire.RotationEvent.decode(envelope.message)
|
||||
push.send([
|
||||
wireutil.global
|
||||
, wireutil.envelope(new wire.RotationEvent(
|
||||
options.serial
|
||||
, message.rotation
|
||||
))
|
||||
])
|
||||
plugin.emit('rotationChange', message)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The APK should be up to date at this point. If it was reinstalled, the
|
||||
// service should have been automatically stopped while it was happening.
|
||||
// So, we should be good to go.
|
||||
function openService() {
|
||||
log.info('Launching service')
|
||||
return callService(util.format(
|
||||
"-a '%s' -n '%s'"
|
||||
, apk.startIntent.action
|
||||
, apk.startIntent.component
|
||||
))
|
||||
.then(function() {
|
||||
return devutil.waitForPort(adb, options.serial, service.port)
|
||||
.timeout(15000)
|
||||
})
|
||||
.then(function(conn) {
|
||||
service.socket = conn
|
||||
service.reader = conn.pipe(new ms.DelimitedStream())
|
||||
service.reader.on('data', handleEnvelope)
|
||||
service.writer = new ms.DelimitingStream()
|
||||
service.writer.pipe(conn)
|
||||
return prepareForServiceDeath(conn)
|
||||
})
|
||||
}
|
||||
|
||||
function prepareForAgentDeath(conn) {
|
||||
function endListener() {
|
||||
var startTime = Date.now()
|
||||
log.important('Agent connection ended, attempting to relaunch')
|
||||
openService()
|
||||
.timeout(5000)
|
||||
.then(function() {
|
||||
log.important('Agent relaunched in %dms', Date.now() - startTime)
|
||||
})
|
||||
.catch(function(err) {
|
||||
log.fatal('Agent connection could not be relaunched', err.stack)
|
||||
lifecycle.fatal()
|
||||
})
|
||||
}
|
||||
|
||||
conn.once('end', endListener)
|
||||
|
||||
conn.on('error', function(err) {
|
||||
log.fatal('Agent connection had an error', err.stack)
|
||||
lifecycle.fatal()
|
||||
})
|
||||
}
|
||||
|
||||
function openAgent() {
|
||||
log.info('Launching agent')
|
||||
return stopAgent()
|
||||
|
@ -83,215 +296,12 @@ module.exports = syrup.serial()
|
|||
})
|
||||
}
|
||||
|
||||
function prepareForAgentDeath(conn) {
|
||||
function endListener() {
|
||||
var startTime = Date.now()
|
||||
log.important('Agent connection ended, attempting to relaunch')
|
||||
openService()
|
||||
.timeout(5000)
|
||||
.then(function() {
|
||||
log.important('Agent relaunched in %dms', Date.now() - startTime)
|
||||
})
|
||||
.catch(function(err) {
|
||||
log.fatal('Agent connection could not be relaunched', err.stack)
|
||||
lifecycle.fatal()
|
||||
})
|
||||
}
|
||||
|
||||
conn.once('end', endListener)
|
||||
|
||||
conn.on('error', function(err) {
|
||||
log.fatal('Agent connection had an error', err.stack)
|
||||
lifecycle.fatal()
|
||||
})
|
||||
}
|
||||
|
||||
function stopAgent() {
|
||||
return devutil.killProcsByComm(
|
||||
adb
|
||||
, options.serial
|
||||
, 'stf.agent'
|
||||
, 'stf.agent'
|
||||
)
|
||||
}
|
||||
|
||||
function callService(intent) {
|
||||
return adb.shell(options.serial, util.format(
|
||||
'am startservice --user 0 %s'
|
||||
, intent
|
||||
))
|
||||
.timeout(15000)
|
||||
.then(function(out) {
|
||||
return streamutil.findLine(out, /^Error/)
|
||||
.finally(function() {
|
||||
out.end()
|
||||
})
|
||||
.timeout(10000)
|
||||
.then(function(line) {
|
||||
if (line.indexOf('--user') !== -1) {
|
||||
return adb.shell(options.serial, util.format(
|
||||
'am startservice %s'
|
||||
, intent
|
||||
))
|
||||
.timeout(15000)
|
||||
.then(function() {
|
||||
return streamutil.findLine(out, /^Error/)
|
||||
.finally(function() {
|
||||
out.end()
|
||||
})
|
||||
.timeout(10000)
|
||||
.then(function(line) {
|
||||
throw new Error(util.format(
|
||||
'Service had an error: "%s"'
|
||||
, line
|
||||
))
|
||||
})
|
||||
.catch(streamutil.NoSuchLineError, function() {
|
||||
return true
|
||||
})
|
||||
})
|
||||
}
|
||||
else {
|
||||
throw new Error(util.format(
|
||||
'Service had an error: "%s"'
|
||||
, line
|
||||
))
|
||||
}
|
||||
})
|
||||
.catch(streamutil.NoSuchLineError, function() {
|
||||
return true
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// The APK should be up to date at this point. If it was reinstalled, the
|
||||
// service should have been automatically stopped while it was happening.
|
||||
// So, we should be good to go.
|
||||
function openService() {
|
||||
log.info('Launching service')
|
||||
return callService(util.format(
|
||||
"-a '%s' -n '%s'"
|
||||
, apk.startIntent.action
|
||||
, apk.startIntent.component
|
||||
))
|
||||
.then(function() {
|
||||
return devutil.waitForPort(adb, options.serial, service.port)
|
||||
.timeout(15000)
|
||||
})
|
||||
.then(function(conn) {
|
||||
service.socket = conn
|
||||
service.reader = conn.pipe(new ms.DelimitedStream())
|
||||
service.reader.on('data', handleEnvelope)
|
||||
service.writer = new ms.DelimitingStream()
|
||||
service.writer.pipe(conn)
|
||||
return prepareForServiceDeath(conn)
|
||||
})
|
||||
}
|
||||
|
||||
function prepareForServiceDeath(conn) {
|
||||
function endListener() {
|
||||
var startTime = Date.now()
|
||||
log.important('Service connection ended, attempting to relaunch')
|
||||
openService()
|
||||
.timeout(5000)
|
||||
.then(function() {
|
||||
log.important('Service relaunched in %dms', Date.now() - startTime)
|
||||
})
|
||||
.catch(function(err) {
|
||||
log.fatal('Service connection could not be relaunched', err.stack)
|
||||
lifecycle.fatal()
|
||||
})
|
||||
}
|
||||
|
||||
conn.once('end', endListener)
|
||||
|
||||
conn.on('error', function(err) {
|
||||
log.fatal('Service connection had an error', err.stack)
|
||||
lifecycle.fatal()
|
||||
})
|
||||
}
|
||||
|
||||
function handleEnvelope(data) {
|
||||
var envelope = apk.wire.Envelope.decode(data)
|
||||
, message
|
||||
if (envelope.id !== null) {
|
||||
messageResolver.resolve(envelope.id, envelope.message)
|
||||
}
|
||||
else {
|
||||
switch (envelope.type) {
|
||||
case apk.wire.MessageType.EVENT_AIRPLANE_MODE:
|
||||
message = apk.wire.AirplaneModeEvent.decode(envelope.message)
|
||||
push.send([
|
||||
wireutil.global
|
||||
, wireutil.envelope(new wire.AirplaneModeEvent(
|
||||
options.serial
|
||||
, message.enabled
|
||||
))
|
||||
])
|
||||
plugin.emit('airplaneModeChange', message)
|
||||
break
|
||||
case apk.wire.MessageType.EVENT_BATTERY:
|
||||
message = apk.wire.BatteryEvent.decode(envelope.message)
|
||||
push.send([
|
||||
wireutil.global
|
||||
, wireutil.envelope(new wire.BatteryEvent(
|
||||
options.serial
|
||||
, message.status
|
||||
, message.health
|
||||
, message.source
|
||||
, message.level
|
||||
, message.scale
|
||||
, message.temp
|
||||
, message.voltage
|
||||
))
|
||||
])
|
||||
plugin.emit('batteryChange', message)
|
||||
break
|
||||
case apk.wire.MessageType.EVENT_BROWSER_PACKAGE:
|
||||
message = apk.wire.BrowserPackageEvent.decode(envelope.message)
|
||||
plugin.emit('browserPackageChange', message)
|
||||
break
|
||||
case apk.wire.MessageType.EVENT_CONNECTIVITY:
|
||||
message = apk.wire.ConnectivityEvent.decode(envelope.message)
|
||||
push.send([
|
||||
wireutil.global
|
||||
, wireutil.envelope(new wire.ConnectivityEvent(
|
||||
options.serial
|
||||
, message.connected
|
||||
, message.type
|
||||
, message.subtype
|
||||
, message.failover
|
||||
, message.roaming
|
||||
))
|
||||
])
|
||||
plugin.emit('connectivityChange', message)
|
||||
break
|
||||
case apk.wire.MessageType.EVENT_PHONE_STATE:
|
||||
message = apk.wire.PhoneStateEvent.decode(envelope.message)
|
||||
push.send([
|
||||
wireutil.global
|
||||
, wireutil.envelope(new wire.PhoneStateEvent(
|
||||
options.serial
|
||||
, message.state
|
||||
, message.manual
|
||||
, message.operator
|
||||
))
|
||||
])
|
||||
plugin.emit('phoneStateChange', message)
|
||||
break
|
||||
case apk.wire.MessageType.EVENT_ROTATION:
|
||||
message = apk.wire.RotationEvent.decode(envelope.message)
|
||||
push.send([
|
||||
wireutil.global
|
||||
, wireutil.envelope(new wire.RotationEvent(
|
||||
options.serial
|
||||
, message.rotation
|
||||
))
|
||||
])
|
||||
plugin.emit('rotationChange', message)
|
||||
break
|
||||
}
|
||||
}
|
||||
function runAgentCommand(type, cmd) {
|
||||
agent.writer.write(new apk.wire.Envelope(
|
||||
null
|
||||
, type
|
||||
, cmd.encodeNB()
|
||||
).encodeNB())
|
||||
}
|
||||
|
||||
function keyEvent(data) {
|
||||
|
@ -326,6 +336,17 @@ module.exports = syrup.serial()
|
|||
return plugin.getClipboard()
|
||||
}
|
||||
|
||||
function runServiceCommand(type, cmd) {
|
||||
var resolver = Promise.defer()
|
||||
var id = Math.floor(Math.random() * 0xFFFFFF)
|
||||
service.writer.write(new apk.wire.Envelope(
|
||||
id
|
||||
, type
|
||||
, cmd.encodeNB()
|
||||
).encodeNB())
|
||||
return messageResolver.await(id, resolver)
|
||||
}
|
||||
|
||||
plugin.getDisplay = function(id) {
|
||||
return runServiceCommand(
|
||||
apk.wire.MessageType.GET_DISPLAY
|
||||
|
@ -651,7 +672,7 @@ module.exports = syrup.serial()
|
|||
})
|
||||
}
|
||||
|
||||
plugin.getSdStatus = function () {
|
||||
plugin.getSdStatus = function() {
|
||||
return runServiceCommand(
|
||||
apk.wire.MessageType.GET_SD_STATUS
|
||||
, new apk.wire.GetSdStatusRequest()
|
||||
|
@ -685,25 +706,6 @@ module.exports = syrup.serial()
|
|||
})
|
||||
}
|
||||
|
||||
function runServiceCommand(type, cmd) {
|
||||
var resolver = Promise.defer()
|
||||
var id = Math.floor(Math.random() * 0xFFFFFF)
|
||||
service.writer.write(new apk.wire.Envelope(
|
||||
id
|
||||
, type
|
||||
, cmd.encodeNB()
|
||||
).encodeNB())
|
||||
return messageResolver.await(id, resolver)
|
||||
}
|
||||
|
||||
function runAgentCommand(type, cmd) {
|
||||
agent.writer.write(new apk.wire.Envelope(
|
||||
null
|
||||
, type
|
||||
, cmd.encodeNB()
|
||||
).encodeNB())
|
||||
}
|
||||
|
||||
return openAgent()
|
||||
.then(openService)
|
||||
.then(function() {
|
||||
|
@ -723,7 +725,7 @@ module.exports = syrup.serial()
|
|||
, keyCode: keyutil.namedKey(message.key)
|
||||
})
|
||||
}
|
||||
catch(e) {
|
||||
catch (e) {
|
||||
log.warn(e.message)
|
||||
}
|
||||
})
|
||||
|
@ -734,7 +736,7 @@ module.exports = syrup.serial()
|
|||
, keyCode: keyutil.namedKey(message.key)
|
||||
})
|
||||
}
|
||||
catch(e) {
|
||||
catch (e) {
|
||||
log.warn(e.message)
|
||||
}
|
||||
})
|
||||
|
@ -745,7 +747,7 @@ module.exports = syrup.serial()
|
|||
, keyCode: keyutil.namedKey(message.key)
|
||||
})
|
||||
}
|
||||
catch(e) {
|
||||
catch (e) {
|
||||
log.warn(e.message)
|
||||
}
|
||||
})
|
||||
|
|
|
@ -22,7 +22,11 @@ module.exports = syrup.serial()
|
|||
.timeout(10000)
|
||||
.then(function(stream) {
|
||||
var resolver = Promise.defer()
|
||||
, timer
|
||||
var timer
|
||||
|
||||
function forceStop() {
|
||||
stream.end()
|
||||
}
|
||||
|
||||
function keepAliveListener(channel, message) {
|
||||
clearTimeout(timer)
|
||||
|
@ -51,10 +55,6 @@ module.exports = syrup.serial()
|
|||
resolver.reject(err)
|
||||
}
|
||||
|
||||
function forceStop() {
|
||||
stream.end()
|
||||
}
|
||||
|
||||
stream.setEncoding('utf8')
|
||||
|
||||
stream.on('readable', readableListener)
|
||||
|
|
|
@ -268,7 +268,7 @@ module.exports = syrup.serial()
|
|||
if (/closed/.test(err.message) && times > 1) {
|
||||
return Promise.delay(delay)
|
||||
.then(function() {
|
||||
return tryConnect(--times, delay * 2)
|
||||
return tryConnect(times - 1, delay * 2)
|
||||
})
|
||||
}
|
||||
return Promise.reject(err)
|
||||
|
@ -315,7 +315,7 @@ module.exports = syrup.serial()
|
|||
socket.stream.removeListener('readable', this.readableListener)
|
||||
|
||||
var endListener
|
||||
return new Promise(function(resolve/*, reject*/) {
|
||||
return new Promise(function(resolve) {
|
||||
socket.on('end', endListener = function() {
|
||||
resolve(true)
|
||||
})
|
||||
|
@ -343,8 +343,8 @@ module.exports = syrup.serial()
|
|||
}
|
||||
|
||||
var signum = {
|
||||
'SIGTERM': -15
|
||||
, 'SIGKILL': -9
|
||||
SIGTERM: -15
|
||||
, SIGKILL: -9
|
||||
}[signal]
|
||||
|
||||
log.info('Sending %s to minitouch', signal)
|
||||
|
@ -395,7 +395,7 @@ module.exports = syrup.serial()
|
|||
var args = chunk.toString().split(/ /g)
|
||||
switch (args[0]) {
|
||||
case 'v':
|
||||
banner.version = +args[1]
|
||||
banner.version = Number(args[1])
|
||||
break
|
||||
default:
|
||||
throw new Error(util.format(
|
||||
|
@ -432,7 +432,7 @@ module.exports = syrup.serial()
|
|||
var args = chunk.toString().split(/ /g)
|
||||
switch (args[0]) {
|
||||
case '$':
|
||||
banner.pid = +args[1]
|
||||
banner.pid = Number(args[1])
|
||||
break
|
||||
default:
|
||||
throw new Error(util.format(
|
||||
|
|
|
@ -8,9 +8,9 @@ module.exports = syrup.serial()
|
|||
return data && data.flags && !!data.flags[flag]
|
||||
}
|
||||
, get: function(flag, defaultValue) {
|
||||
return data && data.flags && data.flags[flag] !== void 0
|
||||
? data.flags[flag]
|
||||
: defaultValue
|
||||
return data && data.flags && typeof data.flags[flag] !== 'undefined' ?
|
||||
data.flags[flag] :
|
||||
defaultValue
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
@ -8,11 +8,11 @@ module.exports = syrup.serial()
|
|||
.define(function(options, identity, data) {
|
||||
function createSlug() {
|
||||
var model = identity.model
|
||||
, name = data ? data.name.id : ''
|
||||
var name = data ? data.name.id : ''
|
||||
|
||||
return (name === '' || model.toLowerCase() === name.toLowerCase())
|
||||
? tr.slugify(model)
|
||||
: tr.slugify(name + ' ' + model)
|
||||
return (name === '' || model.toLowerCase() === name.toLowerCase()) ?
|
||||
tr.slugify(model) :
|
||||
tr.slugify(name + ' ' + model)
|
||||
}
|
||||
|
||||
var defaults = {
|
||||
|
|
|
@ -182,15 +182,16 @@ module.exports = syrup.serial()
|
|||
var decoded = jpeg.decompressSync(
|
||||
connState.lastFrame, connState.frameConfig)
|
||||
|
||||
conn.writeFramebufferUpdate([
|
||||
{ xPosition: 0
|
||||
conn.writeFramebufferUpdate([{
|
||||
xPosition: 0
|
||||
, yPosition: 0
|
||||
, width: decoded.width
|
||||
, height: decoded.height
|
||||
, encodingType: VncConnection.ENCODING_RAW
|
||||
, data: decoded.data
|
||||
}
|
||||
, { xPosition: 0
|
||||
, {
|
||||
xPosition: 0
|
||||
, yPosition: 0
|
||||
, width: decoded.width
|
||||
, height: decoded.height
|
||||
|
@ -203,7 +204,7 @@ module.exports = syrup.serial()
|
|||
}
|
||||
|
||||
function vncStartListener(frameProducer) {
|
||||
return new Promise(function(resolve/*, reject*/) {
|
||||
return new Promise(function(resolve) {
|
||||
connState.frameWidth = frameProducer.banner.virtualWidth
|
||||
connState.frameHeight = frameProducer.banner.virtualHeight
|
||||
resolve()
|
||||
|
@ -211,7 +212,7 @@ module.exports = syrup.serial()
|
|||
}
|
||||
|
||||
function vncFrameListener(frame) {
|
||||
return new Promise(function(resolve/*, reject*/) {
|
||||
return new Promise(function(resolve) {
|
||||
connState.lastFrame = frame
|
||||
connState.lastFrameTime = Date.now()
|
||||
maybeSendFrame()
|
||||
|
@ -238,8 +239,10 @@ module.exports = syrup.serial()
|
|||
})
|
||||
|
||||
conn.on('formatchange', function(format) {
|
||||
var same = os.endianness() === 'BE'
|
||||
=== Boolean(format.bigEndianFlag)
|
||||
var same = os.endianness() === 'BE' ===
|
||||
Boolean(format.bigEndianFlag)
|
||||
var formatOrder = (format.redShift > format.blueShift) === same
|
||||
|
||||
switch (format.bitsPerPixel) {
|
||||
case 8:
|
||||
connState.frameConfig = {
|
||||
|
@ -248,20 +251,19 @@ module.exports = syrup.serial()
|
|||
break
|
||||
case 24:
|
||||
connState.frameConfig = {
|
||||
format: ((format.redShift > format.blueShift) === same)
|
||||
? jpeg.FORMAT_BGR
|
||||
: jpeg.FORMAT_RGB
|
||||
format: formatOrder ? jpeg.FORMAT_BGR : jpeg.FORMAT_RGB
|
||||
}
|
||||
break
|
||||
case 32:
|
||||
var f
|
||||
if (formatOrder) {
|
||||
f = format.blueShift === 0 ? jpeg.FORMAT_BGRX : jpeg.FORMAT_XBGR
|
||||
}
|
||||
else {
|
||||
f = format.redShift === 0 ? jpeg.FORMAT_RGBX : jpeg.FORMAT_XRGB
|
||||
}
|
||||
connState.frameConfig = {
|
||||
format: ((format.redShift > format.blueShift) === same)
|
||||
? (format.blueShift === 0
|
||||
? jpeg.FORMAT_BGRX
|
||||
: jpeg.FORMAT_XBGR)
|
||||
: (format.redShift === 0
|
||||
? jpeg.FORMAT_RGBX
|
||||
: jpeg.FORMAT_XRGB)
|
||||
format: f
|
||||
}
|
||||
break
|
||||
}
|
||||
|
|
|
@ -90,7 +90,8 @@ VncConnection.CLIENT_MESSAGE_CLIENTCUTTEXT = 6
|
|||
|
||||
VncConnection.SERVER_MESSAGE_FBUPDATE = 0
|
||||
|
||||
var StateReverse = Object.create(null), State = {
|
||||
var StateReverse = Object.create(null)
|
||||
var State = {
|
||||
STATE_NEED_CLIENT_VERSION: 10
|
||||
, STATE_NEED_CLIENT_SECURITY: 20
|
||||
, STATE_NEED_CLIENT_INIT: 30
|
||||
|
|
|
@ -31,7 +31,7 @@ module.exports = syrup.serial()
|
|||
})
|
||||
})
|
||||
|
||||
router.on(wire.WifiGetStatusMessage, function(channel){
|
||||
router.on(wire.WifiGetStatusMessage, function(channel) {
|
||||
var reply = wireutil.reply(options.serial)
|
||||
log.info('Getting Wifi status')
|
||||
service.getWifiStatus()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue