diff --git a/lib/roles/device.js b/lib/roles/device.js index fd82199f..393e467b 100644 --- a/lib/roles/device.js +++ b/lib/roles/device.js @@ -34,6 +34,7 @@ module.exports = function(options) { .dependency(require('./device/plugins/connect')) .dependency(require('./device/plugins/account')) .dependency(require('./device/plugins/ringer')) + .dependency(require('./device/plugins/wifi')) .define(function(options, solo) { if (process.send) { // Only if we have a parent process diff --git a/lib/roles/device/plugins/service.js b/lib/roles/device/plugins/service.js index bd63ce30..48d053b7 100644 --- a/lib/roles/device/plugins/service.js +++ b/lib/roles/device/plugins/service.js @@ -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) diff --git a/lib/roles/device/plugins/wifi.js b/lib/roles/device/plugins/wifi.js new file mode 100644 index 00000000..b614b1df --- /dev/null +++ b/lib/roles/device/plugins/wifi.js @@ -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) + ]) + }) + }) + }) diff --git a/lib/roles/websocket.js b/lib/roles/websocket.js index 49a64e30..dc0160e1 100644 --- a/lib/roles/websocket.js +++ b/lib/roles/websocket.js @@ -341,6 +341,16 @@ module.exports = function(options) { ) ]) }) + .on('wifi.set', function(channel, responseChannel, data) { + joinChannel(responseChannel) + push.send([ + channel + , wireutil.transaction( + responseChannel + , new wire.WifiSetEnabledMessage(data.enabled) + ) + ]) + }) .on('group.invite', function(channel, responseChannel, data) { joinChannel(responseChannel) push.send([ diff --git a/lib/wire/wire.proto b/lib/wire/wire.proto index e1a344ea..4966d9e5 100644 --- a/lib/wire/wire.proto +++ b/lib/wire/wire.proto @@ -56,6 +56,7 @@ enum MessageType { ConnectStopMessage = 54; AccountRemoveMessage = 55; RingerSetMessage = 56; + WifiSetEnabledMessage = 57; } message Envelope { @@ -391,6 +392,10 @@ message RingerSetMessage { required int32 mode = 1; } +message WifiSetEnabledMessage { + required bool enabled = 1; +} + // Events, these must be kept in sync with STFService/wire.proto message AirplaneModeEvent { diff --git a/res/app/components/stf/control/control-service.js b/res/app/components/stf/control/control-service.js index 14d7ee7d..0b976746 100644 --- a/res/app/components/stf/control/control-service.js +++ b/res/app/components/stf/control/control-service.js @@ -228,6 +228,12 @@ module.exports = function ControlServiceFactory( }) } + this.setWifiEnabled = function(enabled) { + return sendTwoWay('wifi.set', { + enabled: enabled + }) + } + window.cc = this } diff --git a/vendor/STFService/STFService.apk b/vendor/STFService/STFService.apk index 1c70699f..0ad65618 100644 Binary files a/vendor/STFService/STFService.apk and b/vendor/STFService/STFService.apk differ diff --git a/vendor/STFService/wire.proto b/vendor/STFService/wire.proto index 257f85be..90144d5c 100644 --- a/vendor/STFService/wire.proto +++ b/vendor/STFService/wire.proto @@ -17,6 +17,7 @@ enum MessageType { SET_RINGER_MODE = 21; SET_ROTATION = 12; SET_WAKE_LOCK = 11; + SET_WIFI_ENABLED = 22; EVENT_AIRPLANE_MODE = 13; EVENT_BATTERY = 14; EVENT_CONNECTIVITY = 15; @@ -195,6 +196,14 @@ message SetRingerModeResponse { required bool success = 1; } +message SetWifiEnabledRequest { + required bool enabled = 1; +} + +message SetWifiEnabledResponse { + required bool success = 1; +} + // Agent enum KeyEvent {