diff --git a/lib/roles/device.js b/lib/roles/device.js index ce357a4d..fd82199f 100644 --- a/lib/roles/device.js +++ b/lib/roles/device.js @@ -33,6 +33,7 @@ module.exports = function(options) { .dependency(require('./device/plugins/reboot')) .dependency(require('./device/plugins/connect')) .dependency(require('./device/plugins/account')) + .dependency(require('./device/plugins/ringer')) .define(function(options, solo) { if (process.send) { // Only if we have a parent process diff --git a/lib/roles/device/plugins/ringer.js b/lib/roles/device/plugins/ringer.js new file mode 100644 index 00000000..3d1fd5a1 --- /dev/null +++ b/lib/roles/device/plugins/ringer.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:ringer') + + router.on(wire.RingerSetMessage, function(channel, message) { + var reply = wireutil.reply(options.serial) + + log.info('Setting ringer mode to mode "%s"', message.mode) + + service.setRingerMode(message.mode) + .timeout(30000) + .then(function() { + push.send([ + channel + , reply.okay() + ]) + }) + .error(function(err) { + log.error('Setting 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 72584b97..bd63ce30 100644 --- a/lib/roles/device/plugins/service.js +++ b/lib/roles/device/plugins/service.js @@ -505,6 +505,22 @@ module.exports = syrup.serial() }) } + plugin.setRingerMode = function(mode) { + return runServiceCommand( + apk.wire.MessageType.SET_RINGER_MODE + , new apk.wire.SetRingerModeRequest( + mode + ) + ) + .timeout(10000) + .then(function(data) { + var response = apk.wire.SetRingerModeResponse.decode(data) + if (!response.success) { + throw new Error('Unable to set ringer mode') + } + }) + } + function runServiceCommand(type, cmd) { var resolver = Promise.defer() var id = Math.floor(Math.random() * 0xFFFFFF) diff --git a/lib/roles/device/resources/service.js b/lib/roles/device/resources/service.js index b9b38e7b..72b3c7be 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.8' + requiredVersion: '0.7.10' , 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 cfe0a698..49a64e30 100644 --- a/lib/roles/websocket.js +++ b/lib/roles/websocket.js @@ -331,6 +331,16 @@ module.exports = function(options) { ) ]) }) + .on('ringer.set', function(channel, responseChannel, data) { + joinChannel(responseChannel) + push.send([ + channel + , wireutil.transaction( + responseChannel + , new wire.RingerSetMessage(data.mode) + ) + ]) + }) .on('group.invite', function(channel, responseChannel, data) { joinChannel(responseChannel) push.send([ diff --git a/lib/wire/wire.proto b/lib/wire/wire.proto index 68d90177..e1a344ea 100644 --- a/lib/wire/wire.proto +++ b/lib/wire/wire.proto @@ -55,6 +55,7 @@ enum MessageType { ConnectStartMessage = 53; ConnectStopMessage = 54; AccountRemoveMessage = 55; + RingerSetMessage = 56; } message Envelope { @@ -386,6 +387,10 @@ message ConnectStopMessage { message AccountRemoveMessage { } +message RingerSetMessage { + required int32 mode = 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 79222d98..14d7ee7d 100644 --- a/res/app/components/stf/control/control-service.js +++ b/res/app/components/stf/control/control-service.js @@ -222,6 +222,12 @@ module.exports = function ControlServiceFactory( return sendTwoWay('account.remove') } + this.setRingerMode = function(mode) { + return sendTwoWay('ringer.set', { + mode: mode + }) + } + window.cc = this } diff --git a/vendor/STFService/STFService.apk b/vendor/STFService/STFService.apk index 9608cb54..1c70699f 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 b3bc4eb5..257f85be 100644 --- a/vendor/STFService/wire.proto +++ b/vendor/STFService/wire.proto @@ -14,8 +14,9 @@ enum MessageType { GET_VERSION = 8; SET_CLIPBOARD = 9; SET_KEYGUARD_STATE = 10; - SET_WAKE_LOCK = 11; + SET_RINGER_MODE = 21; SET_ROTATION = 12; + SET_WAKE_LOCK = 11; EVENT_AIRPLANE_MODE = 13; EVENT_BATTERY = 14; EVENT_CONNECTIVITY = 15; @@ -180,6 +181,20 @@ message RemoveAccountResponse { required bool success = 1; } +enum RingerMode { + SILENT = 0; + VIBRATE = 1; + NORMAL = 2; +} + +message SetRingerModeRequest { + required RingerMode mode = 1; +} + +message SetRingerModeResponse { + required bool success = 1; +} + // Agent enum KeyEvent {