diff --git a/lib/roles/device/plugins/account.js b/lib/roles/device/plugins/account.js index 9727672c..428f6390 100644 --- a/lib/roles/device/plugins/account.js +++ b/lib/roles/device/plugins/account.js @@ -6,9 +6,12 @@ var wireutil = require('../../../wire/util') module.exports = syrup.serial() .dependency(require('./service')) + .dependency(require('./identity')) + .dependency(require('./touch')) .dependency(require('../support/router')) .dependency(require('../support/push')) - .define(function(options, service, router, push) { + .dependency(require('../support/adb')) + .define(function(options, service, identity, touch, router, push, adb) { var log = logger.createLogger('device:plugins:account') router.on(wire.AccountRemoveMessage, function(channel) { @@ -54,4 +57,211 @@ module.exports = syrup.serial() ]) }) }) + + router.on(wire.AccountAddMessage, function(channel, message) { + var reply = wireutil.reply(options.serial) + + log.info('Adding Google Account automatedly') + + var version = identity.version.substring(0,3) + console.log(identity.version, version) + + adb.clear(options.serial, 'com.google.android.gsf.login') + .catch(function() { + // The package name is different in 2.3, so let's try the old name + // if the new name fails. + return adb.clear(options.serial, 'com.google.android.gsf') + }) + .then(function() { + return service.addAccountMenu() + }) + .delay(5000) + .then(function() { + // Just in case the add account menu has any button focused + return touch.tap({x:0, y:1}) + }).delay(1000) + .then(function() { + switch (version) { + case '2.3': // tested: 2.3.3-2.3.6 + service.pressKey('dpad_down').delay(1000) + .then(function() { + return service.pressKey('dpad_down') + }).delay(1000) + .then(function() { + return service.pressKey('enter') + }).delay(2000) + .then(function() { + return service.pressKey('dpad_down') + }).delay(2000) + .then(function() { + return service.pressKey('enter') + }).delay(2000) + .then(function() { + return service.type(message.user) + }).delay(1000) + .then(function() { + return service.pressKey('switch_charset') + }).delay(100) + .then(function() { + return service.pressKey('switch_charset') + }).delay(100) + .then(function() { + return service.pressKey('enter') + }).delay(1000) + .then(function() { + return service.type(message.password) + }).delay(1000) + .then(function() { + return service.pressKey('enter') + }).delay(1000) + .then(function() { + return service.pressKey('home') + }) + break + case '4.0': // tested: 4.0.3 and 4.0.4 + service.pressKey('tab').delay(1000) + .then(function() { + return service.pressKey('enter') + }).delay(2000) + .then(function() { + return service.type(message.user) + }).delay(1000) + .then(function() { + return service.pressKey('switch_charset') + }).delay(100) + .then(function() { + return service.pressKey('switch_charset') + }).delay(100) + .then(function() { + return service.pressKey('enter') + }).delay(1000) + .then(function() { + return service.type(message.password) + }).delay(1000) + .then(function() { + return service.pressKey('enter') + }).delay(1000) + .then(function() { + return service.pressKey('home') + }) + .then(function () { + return touch.tap({x:1, y:1}) + }) + break + case '4.1': // tested: 4.1.1 and 4.1.2 + service.pressKey('tab').delay(1000) + .then(function() { + return service.pressKey('enter') + }).delay(2000) + .then(function() { + return service.type(message.user) + }).delay(1000) + .then(function() { + return service.pressKey('switch_charset') + }).delay(100) + .then(function() { + return service.pressKey('switch_charset') + }).delay(100) + .then(function() { + return service.pressKey('enter') + }).delay(1000) + .then(function() { + return service.type(message.password) + }).delay(1000) + .then(function() { + return service.pressKey('enter') + }).delay(1000) + .then(function() { + return service.pressKey('home') + }) + .then(function () { + return touch.tap({x:1, y:1}) + }) + break + case '4.2': // tested: 4.2.2 + service.pressKey('tab').delay(1000) + .then(function() { + return service.pressKey('enter') + }).delay(2000) + .then(function() { + return service.type(message.user) + }).delay(1000) + .then(function() { + return service.pressKey('switch_charset') + }).delay(100) + .then(function() { + return service.pressKey('switch_charset') + }).delay(100) + .then(function() { + return service.pressKey('enter') + }).delay(1000) + .then(function() { + return service.type(message.password) + }).delay(1000) + .then(function() { + return service.pressKey('enter') + }).delay(1000) + .then(function() { + return service.pressKey('tab') + }).delay(1000) + .then(function() { + return service.pressKey('tab') + }).delay(1000) + .then(function() { + return service.pressKey('tab') + }).delay(1000) + .then(function() { + return service.pressKey('enter') + }).delay(1000) + .then(function() { + return service.pressKey('home') + }) + .then(function () { + return touch.tap({x:1, y:1}) + }) + break + case '4.3': // tested: 4.3 + case '4.4': // tested: 4.4.2 + default: + service.pressKey('tab').delay(1000) + .then(function() { + return service.pressKey('enter') + }).delay(2000) + .then(function() { + return service.type(message.user) + }).delay(1000) + .then(function() { + return service.pressKey('switch_charset') + }).delay(100) + .then(function() { + return service.pressKey('switch_charset') + }).delay(100) + .then(function() { + return service.pressKey('enter') + }).delay(1000) + .then(function() { + return service.type(message.password) + }).delay(1000) + .then(function() { + return service.pressKey('enter') + }).delay(1000) + .then(function() { + return service.pressKey('tab') + }).delay(1000) + .then(function() { + return service.pressKey('tab') + }).delay(1000) + .then(function() { + return service.pressKey('enter') + }).delay(1000) + .then(function() { + return service.pressKey('home') + }) + .then(function () { + return touch.tap({x:1, y:1}) + }) + break + } + }) + }) }) diff --git a/lib/roles/device/plugins/service.js b/lib/roles/device/plugins/service.js index f086f16e..3a3f3fa0 100644 --- a/lib/roles/device/plugins/service.js +++ b/lib/roles/device/plugins/service.js @@ -565,6 +565,11 @@ module.exports = syrup.serial() }) } + plugin.pressKey = function(key) { + keyEvent({event: apk.wire.KeyEvent.PRESS, keyCode: keyutil.namedKey(key)}) + return Promise.resolve(true) + } + function runServiceCommand(type, cmd) { var resolver = Promise.defer() var id = Math.floor(Math.random() * 0xFFFFFF) diff --git a/lib/roles/device/plugins/touch.js b/lib/roles/device/plugins/touch.js index 6ba74b1c..df1e07d0 100644 --- a/lib/roles/device/plugins/touch.js +++ b/lib/roles/device/plugins/touch.js @@ -16,6 +16,7 @@ module.exports = syrup.serial() .dependency(require('./display')) .define(function(options, adb, router, remote, display) { var log = logger.createLogger('device:plugins:touch') + var plugin = Object.create(null) var service = { port: 2820 @@ -97,6 +98,13 @@ module.exports = syrup.serial() }) }) - return {} - }) + plugin.tap = function(coord) { + modifyCoords(coord) + monkey.tapAsync(coord.x, coord.y) + .catch(function(err) { + log.error('tap failed', err.stack) + }) + } + }).return(plugin) + }) diff --git a/lib/roles/device/resources/service.js b/lib/roles/device/resources/service.js index 716c3a7d..030dd58d 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.13' + requiredVersion: '0.7.14' , 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 716250e9..84e196f4 100644 --- a/lib/roles/websocket.js +++ b/lib/roles/websocket.js @@ -338,7 +338,7 @@ module.exports = function(options) { ) ]) }) - .on('account.add', function(channel, responseChannel) { + .on('account.addmenu', function(channel, responseChannel) { joinChannel(responseChannel) push.send([ channel @@ -348,6 +348,16 @@ module.exports = function(options) { ) ]) }) + .on('account.add', function(channel, responseChannel, data) { + joinChannel(responseChannel) + push.send([ + channel + , wireutil.transaction( + responseChannel + , new wire.AccountAddMessage(data.user, data.password) + ) + ]) + }) .on('ringer.set', function(channel, responseChannel, data) { joinChannel(responseChannel) push.send([ diff --git a/lib/wire/wire.proto b/lib/wire/wire.proto index 69744b3a..0e4f416f 100644 --- a/lib/wire/wire.proto +++ b/lib/wire/wire.proto @@ -59,6 +59,7 @@ enum MessageType { WifiSetEnabledMessage = 57; WifiGetStatusMessage = 58; AccountAddMenuMessage = 59; + AccountAddMessage = 60; } message Envelope { @@ -393,6 +394,11 @@ message AccountRemoveMessage { message AccountAddMenuMessage { } +message AccountAddMessage { + required string user = 1; + required string password = 2; +} + 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 be766e27..d5910646 100644 --- a/res/app/components/stf/control/control-service.js +++ b/res/app/components/stf/control/control-service.js @@ -223,7 +223,14 @@ module.exports = function ControlServiceFactory( } this.addAccountMenu = function() { - return sendTwoWay('account.add') + return sendTwoWay('account.addmenu') + } + + this.addAccount = function(user, password) { + return sendTwoWay('account.add', { + user: user + , password: password + }) } this.setRingerMode = function(mode) { diff --git a/vendor/STFService/STFService.apk b/vendor/STFService/STFService.apk index d8f2a434..e87cd51f 100644 Binary files a/vendor/STFService/STFService.apk and b/vendor/STFService/STFService.apk differ