mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-18 16:13:24 +02:00
Fix okay response and double login problem in version 4.4*
This commit is contained in:
@@ -14,32 +14,35 @@ module.exports = syrup.serial()
|
||||
.define(function(options, service, identity, touch, router, push, adb) {
|
||||
var log = logger.createLogger('device:plugins:account')
|
||||
|
||||
function checkAccount(type, account) {
|
||||
return service.getAccounts(type)
|
||||
.timeout(30000)
|
||||
.then(function(accounts) {
|
||||
if(accounts.indexOf(account) >= 0) {
|
||||
return true
|
||||
}
|
||||
throw new Error('The account is not added')
|
||||
})
|
||||
}
|
||||
|
||||
router.on(wire.AccountCheckMessage, function(channel, message) {
|
||||
var reply = wireutil.reply(options.serial)
|
||||
|
||||
log.info('Checking if account "%s" is added',message.account)
|
||||
|
||||
service.getAccounts(message.type)
|
||||
.timeout(30000)
|
||||
.then(function(accounts) {
|
||||
if(accounts.indexOf(message.account) >= 0) {
|
||||
checkAccount(message.type, message.account)
|
||||
.then(function() {
|
||||
push.send([
|
||||
channel
|
||||
, reply.okay()
|
||||
])
|
||||
}
|
||||
else {
|
||||
throw new Error('The account is not added')
|
||||
}
|
||||
})
|
||||
.catch(function(err){
|
||||
.catch(function(err) {
|
||||
log.error('Account check failed', err.stack)
|
||||
push.send([
|
||||
channel
|
||||
, reply.fail(err.message)
|
||||
])
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
router.on(wire.AccountGetMessage, function(channel, message) {
|
||||
@@ -110,208 +113,212 @@ module.exports = syrup.serial()
|
||||
|
||||
router.on(wire.AccountAddMessage, function(channel, message) {
|
||||
var reply = wireutil.reply(options.serial)
|
||||
var type = "com.google"
|
||||
var account = message.user + "@gmail.com";
|
||||
|
||||
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')
|
||||
function automation() {
|
||||
switch (version) {
|
||||
case '2.3': // tested: 2.3.3-2.3.6
|
||||
return 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')
|
||||
})
|
||||
case '4.0': // tested: 4.0.3 and 4.0.4
|
||||
return 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')
|
||||
})
|
||||
case '4.1': // tested: 4.1.1 and 4.1.2
|
||||
return 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')
|
||||
})
|
||||
case '4.2': // tested: 4.2.2
|
||||
return 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')
|
||||
})
|
||||
case '4.3': // tested: 4.3
|
||||
case '4.4': // tested: 4.4.2
|
||||
default:
|
||||
return 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')
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// First check if the account is already added so we don't continue
|
||||
return checkAccount(type, account)
|
||||
.then(function() {
|
||||
push.send([
|
||||
channel
|
||||
, reply.fail('Add account failed: account was already added')
|
||||
])
|
||||
})
|
||||
.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
|
||||
}
|
||||
return 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:0.9})
|
||||
})
|
||||
.delay(500)
|
||||
.then(function() {
|
||||
return automation()
|
||||
})
|
||||
.delay(3000)
|
||||
.then(function () {
|
||||
return service.pressKey('home')
|
||||
})
|
||||
.then(function () {
|
||||
return checkAccount(type, account)
|
||||
})
|
||||
.then(function() {
|
||||
push.send([
|
||||
channel
|
||||
, reply.okay()
|
||||
])
|
||||
})
|
||||
.catch(function(err) {
|
||||
log.error('Add account failed', err.stack)
|
||||
push.send([
|
||||
channel
|
||||
, reply.fail('Add account failed: ' + err.message)
|
||||
])
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user