diff --git a/lib/roles/device/plugins/account.js b/lib/roles/device/plugins/account.js index 6a971d48..395e25f0 100644 --- a/lib/roles/device/plugins/account.js +++ b/lib/roles/device/plugins/account.js @@ -14,6 +14,28 @@ module.exports = syrup.serial() .define(function(options, service, identity, touch, router, push, adb) { var log = logger.createLogger('device:plugins:account') + router.on(wire.AccountGetMessage, function(channel, message){ + var reply = wireutil.reply(options.serial) + + log.info('Getting account(s) of type "%s"', message.type) + + service.getAccounts(message.type) + .timeout(30000) + .then(function(accounts) { + push.send([ + channel + , reply.okay('success',accounts) + ]) + }) + .catch(function(err) { + log.error('Account get failed', err.stack) + push.send([ + channel + , reply.fail(err.message) + ]) + }) + }) + router.on(wire.AccountRemoveMessage, function(channel, message) { var reply = wireutil.reply(options.serial) diff --git a/lib/roles/device/plugins/service.js b/lib/roles/device/plugins/service.js index 1769c004..9e8af4ad 100644 --- a/lib/roles/device/plugins/service.js +++ b/lib/roles/device/plugins/service.js @@ -490,6 +490,21 @@ module.exports = syrup.serial() }) } + plugin.getAccounts = function(type) { + return runServiceCommand( + apk.wire.MessageType.GET_ACCOUNTS + , new apk.wire.GetAccountsRequest(type) + ) + .timeout(15000) + .then(function(data) { + var response = apk.wire.GetAccountsResponse.decode(data) + if (response.success) { + return response.accounts + } + throw new Error('No accounts returned') + }) + } + plugin.removeAccount = function(data) { return runServiceCommand( apk.wire.MessageType.DO_REMOVE_ACCOUNT diff --git a/lib/roles/device/resources/service.js b/lib/roles/device/resources/service.js index ba7c5d33..987ceaee 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.17' + requiredVersion: '0.7.18' , 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 3925738c..584d648b 100644 --- a/lib/roles/websocket.js +++ b/lib/roles/websocket.js @@ -362,6 +362,16 @@ module.exports = function(options) { ) ]) }) + .on('account.get', function(channel, responseChannel, data) { + joinChannel(responseChannel) + push.send([ + channel + , wireutil.transaction( + responseChannel + , new wire.AccountGetMessage(data.type) + ) + ]) + }) .on('sd.status', function(channel, responseChannel) { joinChannel(responseChannel) push.send([ diff --git a/lib/wire/wire.proto b/lib/wire/wire.proto index 4f43cdd2..f6c08973 100644 --- a/lib/wire/wire.proto +++ b/lib/wire/wire.proto @@ -60,6 +60,7 @@ enum MessageType { WifiGetStatusMessage = 58; AccountAddMenuMessage = 59; AccountAddMessage = 60; + AccountGetMessage = 62; SdStatusMessage = 61; } @@ -403,6 +404,10 @@ message AccountAddMessage { required string password = 2; } +message AccountGetMessage { + required string type = 1; +} + message SdStatusMessage { } diff --git a/res/app/components/stf/control/control-service.js b/res/app/components/stf/control/control-service.js index 1477b76f..8e68a507 100644 --- a/res/app/components/stf/control/control-service.js +++ b/res/app/components/stf/control/control-service.js @@ -236,6 +236,12 @@ module.exports = function ControlServiceFactory( }) } + this.getAccounts = function(type) { + return sendTwoWay('account.get', { + type: type + }) + } + this.getSdStatus = function() { return sendTwoWay('sd.status') } diff --git a/vendor/STFService/STFService.apk b/vendor/STFService/STFService.apk index 010999c3..67ad5280 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 2068a82c..645eed88 100644 --- a/vendor/STFService/wire.proto +++ b/vendor/STFService/wire.proto @@ -9,6 +9,7 @@ enum MessageType { DO_WAKE = 4; DO_ADD_ACCOUNT_MENU = 24; DO_REMOVE_ACCOUNT = 20; + GET_ACCOUNTS = 26; GET_BROWSERS = 5; GET_CLIPBOARD = 6; GET_DISPLAY = 19; @@ -178,6 +179,15 @@ message DoIdentifyResponse { required bool success = 1; } +message GetAccountsRequest { + required string type = 1; +} + +message GetAccountsResponse { + required bool success = 1; + repeated string accounts = 2; +} + message DoAddAccountMenuRequest { }