mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-23 06:15:16 +02:00
Implement automated login (Google Account).
This commit is contained in:
@@ -6,9 +6,12 @@ var wireutil = require('../../../wire/util')
|
|||||||
|
|
||||||
module.exports = syrup.serial()
|
module.exports = syrup.serial()
|
||||||
.dependency(require('./service'))
|
.dependency(require('./service'))
|
||||||
|
.dependency(require('./identity'))
|
||||||
|
.dependency(require('./touch'))
|
||||||
.dependency(require('../support/router'))
|
.dependency(require('../support/router'))
|
||||||
.dependency(require('../support/push'))
|
.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')
|
var log = logger.createLogger('device:plugins:account')
|
||||||
|
|
||||||
router.on(wire.AccountRemoveMessage, function(channel) {
|
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
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -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) {
|
function runServiceCommand(type, cmd) {
|
||||||
var resolver = Promise.defer()
|
var resolver = Promise.defer()
|
||||||
var id = Math.floor(Math.random() * 0xFFFFFF)
|
var id = Math.floor(Math.random() * 0xFFFFFF)
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ module.exports = syrup.serial()
|
|||||||
.dependency(require('./display'))
|
.dependency(require('./display'))
|
||||||
.define(function(options, adb, router, remote, display) {
|
.define(function(options, adb, router, remote, display) {
|
||||||
var log = logger.createLogger('device:plugins:touch')
|
var log = logger.createLogger('device:plugins:touch')
|
||||||
|
var plugin = Object.create(null)
|
||||||
|
|
||||||
var service = {
|
var service = {
|
||||||
port: 2820
|
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)
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ module.exports = syrup.serial()
|
|||||||
var log = logger.createLogger('device:resources:service')
|
var log = logger.createLogger('device:resources:service')
|
||||||
|
|
||||||
var resource = {
|
var resource = {
|
||||||
requiredVersion: '0.7.13'
|
requiredVersion: '0.7.14'
|
||||||
, pkg: 'jp.co.cyberagent.stf'
|
, pkg: 'jp.co.cyberagent.stf'
|
||||||
, main: 'jp.co.cyberagent.stf.Agent'
|
, main: 'jp.co.cyberagent.stf.Agent'
|
||||||
, apk: pathutil.vendor('STFService/STFService.apk')
|
, apk: pathutil.vendor('STFService/STFService.apk')
|
||||||
|
|||||||
@@ -338,7 +338,7 @@ module.exports = function(options) {
|
|||||||
)
|
)
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
.on('account.add', function(channel, responseChannel) {
|
.on('account.addmenu', function(channel, responseChannel) {
|
||||||
joinChannel(responseChannel)
|
joinChannel(responseChannel)
|
||||||
push.send([
|
push.send([
|
||||||
channel
|
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) {
|
.on('ringer.set', function(channel, responseChannel, data) {
|
||||||
joinChannel(responseChannel)
|
joinChannel(responseChannel)
|
||||||
push.send([
|
push.send([
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ enum MessageType {
|
|||||||
WifiSetEnabledMessage = 57;
|
WifiSetEnabledMessage = 57;
|
||||||
WifiGetStatusMessage = 58;
|
WifiGetStatusMessage = 58;
|
||||||
AccountAddMenuMessage = 59;
|
AccountAddMenuMessage = 59;
|
||||||
|
AccountAddMessage = 60;
|
||||||
}
|
}
|
||||||
|
|
||||||
message Envelope {
|
message Envelope {
|
||||||
@@ -393,6 +394,11 @@ message AccountRemoveMessage {
|
|||||||
message AccountAddMenuMessage {
|
message AccountAddMenuMessage {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message AccountAddMessage {
|
||||||
|
required string user = 1;
|
||||||
|
required string password = 2;
|
||||||
|
}
|
||||||
|
|
||||||
message RingerSetMessage {
|
message RingerSetMessage {
|
||||||
required int32 mode = 1;
|
required int32 mode = 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -223,7 +223,14 @@ module.exports = function ControlServiceFactory(
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.addAccountMenu = function() {
|
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) {
|
this.setRingerMode = function(mode) {
|
||||||
|
|||||||
BIN
vendor/STFService/STFService.apk
vendored
BIN
vendor/STFService/STFService.apk
vendored
Binary file not shown.
Reference in New Issue
Block a user