diff --git a/lib/roles/device.js b/lib/roles/device.js index ac92b223..ce357a4d 100644 --- a/lib/roles/device.js +++ b/lib/roles/device.js @@ -32,6 +32,7 @@ module.exports = function(options) { .dependency(require('./device/plugins/group')) .dependency(require('./device/plugins/reboot')) .dependency(require('./device/plugins/connect')) + .dependency(require('./device/plugins/account')) .define(function(options, solo) { if (process.send) { // Only if we have a parent process diff --git a/lib/roles/device/plugins/account.js b/lib/roles/device/plugins/account.js new file mode 100644 index 00000000..e5f9e80e --- /dev/null +++ b/lib/roles/device/plugins/account.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:account') + + router.on(wire.AccountRemoveMessage, function(channel, message) { + var reply = wireutil.reply(options.serial) + + log.info('Removing current Google account(s)') + + service.removeAccount() + .timeout(30000) + .then(function() { + push.send([ + channel + , reply.okay() + ]) + }) + .error(function(err) { + log.error('Account removal 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 504bfd3a..72584b97 100644 --- a/lib/roles/device/plugins/service.js +++ b/lib/roles/device/plugins/service.js @@ -490,6 +490,21 @@ module.exports = syrup.serial() }) } + plugin.removeAccount = function() { + return runServiceCommand( + apk.wire.MessageType.REMOVE_ACCOUNT + , new apk.wire.RemoveAccountRequest() + ) + .timeout(15000) + .then(function(data) { + var response = apk.wire.RemoveAccountResponse.decode(data) + if (response.success) { + return true + } + throw new Error('Unable to remove account') + }) + } + 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 536be045..b9b38e7b 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.7' + requiredVersion: '0.7.8' , 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 981efed8..cfe0a698 100644 --- a/lib/roles/websocket.js +++ b/lib/roles/websocket.js @@ -321,6 +321,16 @@ module.exports = function(options) { ) ]) }) + .on('account.remove', function(channel, responseChannel) { + joinChannel(responseChannel) + push.send([ + channel + , wireutil.transaction( + responseChannel + , new wire.AccountRemoveMessage() + ) + ]) + }) .on('group.invite', function(channel, responseChannel, data) { joinChannel(responseChannel) push.send([ diff --git a/lib/wire/wire.proto b/lib/wire/wire.proto index f34701d1..68d90177 100644 --- a/lib/wire/wire.proto +++ b/lib/wire/wire.proto @@ -54,6 +54,7 @@ enum MessageType { RebootMessage = 52; ConnectStartMessage = 53; ConnectStopMessage = 54; + AccountRemoveMessage = 55; } message Envelope { @@ -382,6 +383,9 @@ message ConnectStartMessage { message ConnectStopMessage { } +message AccountRemoveMessage { +} + // 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 55f6c81a..79222d98 100644 --- a/res/app/components/stf/control/control-service.js +++ b/res/app/components/stf/control/control-service.js @@ -218,6 +218,10 @@ module.exports = function ControlServiceFactory( return sendTwoWay('screen.capture') } + this.removeAccount = function() { + return sendTwoWay('account.remove') + } + window.cc = this } diff --git a/vendor/STFService/STFService.apk b/vendor/STFService/STFService.apk index 855d668f..9608cb54 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 f799063f..b3bc4eb5 100644 --- a/vendor/STFService/wire.proto +++ b/vendor/STFService/wire.proto @@ -22,6 +22,7 @@ enum MessageType { EVENT_PHONE_STATE = 16; EVENT_ROTATION = 17; EVENT_BROWSER_PACKAGE = 18; + REMOVE_ACCOUNT = 20; } message Envelope { @@ -172,6 +173,13 @@ message DoIdentifyResponse { required bool success = 1; } +message RemoveAccountRequest { +} + +message RemoveAccountResponse { + required bool success = 1; +} + // Agent enum KeyEvent {