diff --git a/lib/roles/device/plugins/ringer.js b/lib/roles/device/plugins/ringer.js index 3d1fd5a1..0d3ce9a3 100644 --- a/lib/roles/device/plugins/ringer.js +++ b/lib/roles/device/plugins/ringer.js @@ -24,7 +24,7 @@ module.exports = syrup.serial() , reply.okay() ]) }) - .error(function(err) { + .catch(function(err) { log.error('Setting ringer mode failed', err.stack) push.send([ channel @@ -32,4 +32,26 @@ module.exports = syrup.serial() ]) }) }) + + router.on(wire.RingerGetMessage, function(channel) { + var reply = wireutil.reply(options.serial) + + log.info('Getting ringer mode') + + service.getRingerMode() + .timeout(30000) + .then(function(mode) { + push.send([ + channel + , reply.okay('success', mode) + ]) + }) + .catch(function(err) { + log.error('Getting ringer mode failed', err.stack) + push.send([ + channel + , reply.fail(err.message) + ]) + }) + }) }) diff --git a/lib/roles/device/plugins/service.js b/lib/roles/device/plugins/service.js index d54be848..a1747763 100644 --- a/lib/roles/device/plugins/service.js +++ b/lib/roles/device/plugins/service.js @@ -552,6 +552,25 @@ module.exports = syrup.serial() }) } + plugin.getRingerMode = function() { + return runServiceCommand( + apk.wire.MessageType.GET_RINGER_MODE + , new apk.wire.GetRingerModeRequest() + ) + .timeout(10000) + .then(function(data) { + var response = apk.wire.GetRingerModeResponse.decode(data) + // Reflection to decode enums to their string values, otherwise + // we only get an integer + var ringerMode = apk.builder.lookup('jp.co.cyberagent.stf.proto.RingerMode') + .children[response.mode].name + if (response.success) { + return ringerMode + } + throw new Error('Unable to get ringer mode') + }) + } + plugin.setWifiEnabled = function(enabled) { return runServiceCommand( apk.wire.MessageType.SET_WIFI_ENABLED diff --git a/lib/roles/device/resources/service.js b/lib/roles/device/resources/service.js index af0a413c..e9a1ef3c 100644 --- a/lib/roles/device/resources/service.js +++ b/lib/roles/device/resources/service.js @@ -13,15 +13,15 @@ module.exports = syrup.serial() .dependency(require('../support/adb')) .define(function(options, adb) { var log = logger.createLogger('device:resources:service') + var builder = ProtoBuf.loadProtoFile(pathutil.vendor('STFService/wire.proto')) var resource = { - requiredVersion: '0.7.20' + requiredVersion: '0.7.21' , pkg: 'jp.co.cyberagent.stf' , main: 'jp.co.cyberagent.stf.Agent' , apk: pathutil.vendor('STFService/STFService.apk') - , wire: ProtoBuf.loadProtoFile( - pathutil.vendor('STFService/wire.proto') - ).build().jp.co.cyberagent.stf.proto + , wire: builder.build().jp.co.cyberagent.stf.proto + , builder: builder , startIntent: { action: 'jp.co.cyberagent.stf.ACTION_START' , component: 'jp.co.cyberagent.stf/.Service' diff --git a/lib/roles/websocket.js b/lib/roles/websocket.js index 535b178e..a8409caa 100644 --- a/lib/roles/websocket.js +++ b/lib/roles/websocket.js @@ -402,6 +402,16 @@ module.exports = function(options) { ) ]) }) + .on('ringer.get', function(channel, responseChannel) { + joinChannel(responseChannel) + push.send([ + channel + , wireutil.transaction( + responseChannel + , new wire.RingerGetMessage() + ) + ]) + }) .on('wifi.set', function(channel, responseChannel, data) { joinChannel(responseChannel) push.send([ diff --git a/lib/wire/wire.proto b/lib/wire/wire.proto index f29b43e5..6f74e6d2 100644 --- a/lib/wire/wire.proto +++ b/lib/wire/wire.proto @@ -55,6 +55,7 @@ enum MessageType { ConnectStartMessage = 53; ConnectStopMessage = 54; RingerSetMessage = 56; + RingerGetMessage = 64; WifiSetEnabledMessage = 57; WifiGetStatusMessage = 58; AccountAddMenuMessage = 59; @@ -427,6 +428,9 @@ message RingerSetMessage { required RingerMode mode = 1; } +message RingerGetMessage { +} + message WifiSetEnabledMessage { required bool enabled = 1; } diff --git a/res/app/components/stf/control/control-service.js b/res/app/components/stf/control/control-service.js index 2f8ad1f7..338342f8 100644 --- a/res/app/components/stf/control/control-service.js +++ b/res/app/components/stf/control/control-service.js @@ -259,6 +259,10 @@ module.exports = function ControlServiceFactory( }) } + this.getRingerMode = function() { + return sendTwoWay('ringer.get') + } + this.setWifiEnabled = function(enabled) { return sendTwoWay('wifi.set', { enabled: enabled diff --git a/vendor/STFService/STFService.apk b/vendor/STFService/STFService.apk index 5429ae14..86b3f311 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 ae7b4a0f..44b07565 100644 --- a/vendor/STFService/wire.proto +++ b/vendor/STFService/wire.proto @@ -14,6 +14,7 @@ enum MessageType { GET_CLIPBOARD = 6; GET_DISPLAY = 19; GET_PROPERTIES = 7; + GET_RINGER_MODE = 27; GET_SD_STATUS = 25; GET_VERSION = 8; GET_WIFI_STATUS = 23; @@ -218,6 +219,14 @@ message SetRingerModeResponse { required bool success = 1; } +message GetRingerModeRequest { +} + +message GetRingerModeResponse { + required bool success = 1; + required RingerMode mode = 2; +} + message SetWifiEnabledRequest { required bool enabled = 1; }