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
|
@ -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)
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue