Implement account removal.

This commit is contained in:
Valverde Antonio
2014-06-25 17:47:45 +09:00
parent a8da19472d
commit 3a3937ec2f
9 changed files with 78 additions and 1 deletions

View File

@@ -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)
])
})
})
})

View File

@@ -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)