diff --git a/lib/roles/device/plugins/service.js b/lib/roles/device/plugins/service.js index 48d053b7..1140a967 100644 --- a/lib/roles/device/plugins/service.js +++ b/lib/roles/device/plugins/service.js @@ -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) diff --git a/lib/roles/device/plugins/wifi.js b/lib/roles/device/plugins/wifi.js index b614b1df..2c758039 100644 --- a/lib/roles/device/plugins/wifi.js +++ b/lib/roles/device/plugins/wifi.js @@ -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) diff --git a/lib/roles/device/resources/service.js b/lib/roles/device/resources/service.js index 485ae6a8..98294486 100644 --- a/lib/roles/device/resources/service.js +++ b/lib/roles/device/resources/service.js @@ -15,7 +15,7 @@ module.exports = syrup.serial() var log = logger.createLogger('device:resources:service') var resource = { - requiredVersion: '0.7.11' + requiredVersion: '0.7.12' , pkg: 'jp.co.cyberagent.stf' , main: 'jp.co.cyberagent.stf.Agent' , apk: pathutil.vendor('STFService/STFService.apk') diff --git a/lib/roles/websocket.js b/lib/roles/websocket.js index dc0160e1..99fcb94d 100644 --- a/lib/roles/websocket.js +++ b/lib/roles/websocket.js @@ -351,6 +351,16 @@ module.exports = function(options) { ) ]) }) + .on('wifi.get', function(channel, responseChannel) { + joinChannel(responseChannel) + push.send([ + channel + , wireutil.transaction( + responseChannel + , new wire.WifiGetStatusMessage() + ) + ]) + }) .on('group.invite', function(channel, responseChannel, data) { joinChannel(responseChannel) push.send([ diff --git a/lib/wire/wire.proto b/lib/wire/wire.proto index 4966d9e5..eff53268 100644 --- a/lib/wire/wire.proto +++ b/lib/wire/wire.proto @@ -57,6 +57,7 @@ enum MessageType { AccountRemoveMessage = 55; RingerSetMessage = 56; WifiSetEnabledMessage = 57; + WifiGetStatusMessage = 58; } message Envelope { @@ -396,6 +397,9 @@ message WifiSetEnabledMessage { required bool enabled = 1; } +message WifiGetStatusMessage { +} + // 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 0b976746..3d382d5a 100644 --- a/res/app/components/stf/control/control-service.js +++ b/res/app/components/stf/control/control-service.js @@ -234,6 +234,10 @@ module.exports = function ControlServiceFactory( }) } + this.getWifiStatus = function() { + return sendTwoWay('wifi.get') + } + window.cc = this } diff --git a/vendor/STFService/STFService.apk b/vendor/STFService/STFService.apk index 85d09b99..21962872 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 90144d5c..1511e371 100644 --- a/vendor/STFService/wire.proto +++ b/vendor/STFService/wire.proto @@ -12,6 +12,7 @@ enum MessageType { GET_DISPLAY = 19; GET_PROPERTIES = 7; GET_VERSION = 8; + GET_WIFI_STATUS = 23; SET_CLIPBOARD = 9; SET_KEYGUARD_STATE = 10; SET_RINGER_MODE = 21; @@ -204,6 +205,14 @@ message SetWifiEnabledResponse { required bool success = 1; } +message GetWifiStatusRequest { +} + +message GetWifiStatusResponse { + required bool success = 1; + required bool status = 2; +} + // Agent enum KeyEvent {