mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-18 08:03:30 +02:00
Implement set Wifi on/off.
This commit is contained in:
@@ -521,6 +521,20 @@ module.exports = syrup.serial()
|
||||
})
|
||||
}
|
||||
|
||||
plugin.setWifiEnabled = function(enabled) {
|
||||
return runServiceCommand(
|
||||
apk.wire.MessageType.SET_WIFI_ENABLED
|
||||
, new apk.wire.SetWifiEnabledRequest(enabled)
|
||||
)
|
||||
.timeout(10000)
|
||||
.then(function(data) {
|
||||
var response = apk.wire.SetWifiEnabledResponse.decode(data)
|
||||
if (!response.success) {
|
||||
throw new Error('Unable to set Wifi')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function runServiceCommand(type, cmd) {
|
||||
var resolver = Promise.defer()
|
||||
var id = Math.floor(Math.random() * 0xFFFFFF)
|
||||
|
||||
35
lib/roles/device/plugins/wifi.js
Normal file
35
lib/roles/device/plugins/wifi.js
Normal file
@@ -0,0 +1,35 @@
|
||||
var syrup = require('syrup')
|
||||
|
||||
var logger = require('../../../util/logger')
|
||||
var wire = require('../../../wire')
|
||||
var wireutil = require('../../../wire/util')
|
||||
|
||||
module.exports = syrup.serial()
|
||||
.dependency(require('./service'))
|
||||
.dependency(require('../support/router'))
|
||||
.dependency(require('../support/push'))
|
||||
.define(function(options, service, router, push) {
|
||||
var log = logger.createLogger('device:plugins:wifi')
|
||||
|
||||
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() {
|
||||
push.send([
|
||||
channel
|
||||
, reply.okay()
|
||||
])
|
||||
})
|
||||
.error(function(err) {
|
||||
log.error('Setting wifi enabled failed', err.stack)
|
||||
push.send([
|
||||
channel
|
||||
, reply.fail(err.message)
|
||||
])
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user