diff --git a/lib/roles/device.js b/lib/roles/device.js index 393e467b..2b8a3365 100644 --- a/lib/roles/device.js +++ b/lib/roles/device.js @@ -35,6 +35,7 @@ module.exports = function(options) { .dependency(require('./device/plugins/account')) .dependency(require('./device/plugins/ringer')) .dependency(require('./device/plugins/wifi')) + .dependency(require('./device/plugins/sd')) .define(function(options, solo) { if (process.send) { // Only if we have a parent process diff --git a/lib/roles/device/plugins/sd.js b/lib/roles/device/plugins/sd.js new file mode 100644 index 00000000..7dabeb13 --- /dev/null +++ b/lib/roles/device/plugins/sd.js @@ -0,0 +1,33 @@ +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:sd') + + router.on(wire.SdStatusMessage, function(channel, message) { + var reply = wireutil.reply(options.serial) + log.info('Getting SD card status') + service.getSdStatus(message) + .timeout(30000) + .then(function(mounted) { + push.send([ + channel + , reply.okay(mounted ? 'sd_mounted' : 'sd_unmounted') + ]) + }) + .error(function(err) { + log.error('Getting SD card Status', 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 3a3f3fa0..aeb0e2fa 100644 --- a/lib/roles/device/plugins/service.js +++ b/lib/roles/device/plugins/service.js @@ -565,6 +565,21 @@ module.exports = syrup.serial() }) } + plugin.getSdStatus = function () { + return runServiceCommand( + apk.wire.MessageType.GET_SD_STATUS + , new apk.wire.GetSdStatusRequest() + ) + .timeout(10000) + .then(function(data) { + var response = apk.wire.GetSdStatusResponse.decode(data) + if (response.success) { + return response.mounted + } + throw new Error('Unable to get SD card status') + }) + } + plugin.pressKey = function(key) { keyEvent({event: apk.wire.KeyEvent.PRESS, keyCode: keyutil.namedKey(key)}) return Promise.resolve(true) diff --git a/lib/roles/device/resources/service.js b/lib/roles/device/resources/service.js index a9219eb8..7a23f7b5 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.15' + requiredVersion: '0.7.16' , 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 70a90744..a578001a 100644 --- a/lib/roles/websocket.js +++ b/lib/roles/websocket.js @@ -358,6 +358,16 @@ module.exports = function(options) { ) ]) }) + .on('sd.status', function(channel, responseChannel) { + joinChannel(responseChannel) + push.send([ + channel + , wireutil.transaction( + responseChannel + , new wire.SdStatusMessage() + ) + ]) + }) .on('ringer.set', function(channel, responseChannel, data) { joinChannel(responseChannel) push.send([ diff --git a/lib/wire/wire.proto b/lib/wire/wire.proto index 0e4f416f..f6ad229c 100644 --- a/lib/wire/wire.proto +++ b/lib/wire/wire.proto @@ -60,6 +60,7 @@ enum MessageType { WifiGetStatusMessage = 58; AccountAddMenuMessage = 59; AccountAddMessage = 60; + SdStatusMessage = 61; } message Envelope { @@ -399,6 +400,9 @@ message AccountAddMessage { required string password = 2; } +message SdStatusMessage { +} + message RingerSetMessage { required int32 mode = 1; } diff --git a/res/app/components/stf/control/control-service.js b/res/app/components/stf/control/control-service.js index d5910646..5a862265 100644 --- a/res/app/components/stf/control/control-service.js +++ b/res/app/components/stf/control/control-service.js @@ -233,6 +233,10 @@ module.exports = function ControlServiceFactory( }) } + this.getSdStatus = function() { + return sendTwoWay('sd.status') + } + this.setRingerMode = function(mode) { return sendTwoWay('ringer.set', { mode: mode diff --git a/vendor/STFService/STFService.apk b/vendor/STFService/STFService.apk index a0b4fc9c..20bcbc71 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 d1f21622..69d892ec 100644 --- a/vendor/STFService/wire.proto +++ b/vendor/STFService/wire.proto @@ -12,6 +12,7 @@ enum MessageType { GET_CLIPBOARD = 6; GET_DISPLAY = 19; GET_PROPERTIES = 7; + GET_SD_STATUS = 25; GET_VERSION = 8; GET_WIFI_STATUS = 23; SET_CLIPBOARD = 9; @@ -221,6 +222,14 @@ message GetWifiStatusResponse { required bool status = 2; } +message GetSdStatusRequest { +} + +message GetSdStatusResponse { + required bool success = 1; + required bool mounted = 2; +} + // Agent enum KeyEvent {