mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-19 00:23:25 +02:00
Implement get Wifi status.
This commit is contained in:
@@ -535,6 +535,21 @@ module.exports = syrup.serial()
|
||||
})
|
||||
}
|
||||
|
||||
plugin.getWifiStatus = function() {
|
||||
return runServiceCommand(
|
||||
apk.wire.MessageType.GET_WIFI_STATUS
|
||||
, new apk.wire.GetWifiStatusRequest()
|
||||
)
|
||||
.timeout(10000)
|
||||
.then(function(data) {
|
||||
var response = apk.wire.GetWifiStatusResponse.decode(data)
|
||||
if (response.success) {
|
||||
return response.status
|
||||
}
|
||||
throw new Error('Unable to get Wifi status')
|
||||
})
|
||||
}
|
||||
|
||||
function runServiceCommand(type, cmd) {
|
||||
var resolver = Promise.defer()
|
||||
var id = Math.floor(Math.random() * 0xFFFFFF)
|
||||
|
||||
@@ -13,9 +13,7 @@ module.exports = syrup.serial()
|
||||
|
||||
router.on(wire.WifiSetEnabledMessage, function(channel, message) {
|
||||
var reply = wireutil.reply(options.serial)
|
||||
|
||||
log.info('Setting Wifi "%s"', message.enabled)
|
||||
|
||||
service.setWifiEnabled(message.enabled)
|
||||
.timeout(30000)
|
||||
.then(function() {
|
||||
@@ -25,7 +23,27 @@ module.exports = syrup.serial()
|
||||
])
|
||||
})
|
||||
.error(function(err) {
|
||||
log.error('Setting wifi enabled failed', err.stack)
|
||||
log.error('Setting Wifi enabled failed', err.stack)
|
||||
push.send([
|
||||
channel
|
||||
, reply.fail(err.message)
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
router.on(wire.WifiGetStatusMessage, function(channel){
|
||||
var reply = wireutil.reply(options.serial)
|
||||
log.info('Getting Wifi status')
|
||||
service.getWifiStatus()
|
||||
.timeout(30000)
|
||||
.then(function(enabled) {
|
||||
push.send([
|
||||
channel
|
||||
, reply.okay(enabled ? 'wifi_enabled' : 'wifi_disabled')
|
||||
])
|
||||
})
|
||||
.error(function(err) {
|
||||
log.error('Getting Wifi status failed', err.stack)
|
||||
push.send([
|
||||
channel
|
||||
, reply.fail(err.message)
|
||||
|
||||
Reference in New Issue
Block a user