Rename "roles" to "units". Put units in their own folders.

This commit is contained in:
Simo Kinnunen
2014-08-26 14:34:34 +09:00
parent 7d9d64ddcb
commit 3a9b193f68
63 changed files with 105 additions and 105 deletions

View File

@@ -0,0 +1,103 @@
var util = require('util')
var Promise = require('bluebird')
var syrup = require('syrup')
var logger = require('../../../util/logger')
var pathutil = require('../../../util/pathutil')
var devutil = require('../../../util/devutil')
var streamutil = require('../../../util/streamutil')
module.exports = syrup.serial()
.dependency(require('../support/adb'))
.dependency(require('../support/properties'))
.define(function(options, adb, properties) {
var log = logger.createLogger('device:resources:remote')
var resources = {
bin: {
src: pathutil.vendor(util.format(
'remote/libs/%s/remote'
, properties['ro.product.cpu.abi']
))
, dest: '/data/local/tmp/remote'
, comm: 'remote'
, mode: 0755
}
, lib: {
src: pathutil.vendor(util.format(
'remote/external/android-%d/remote_external.so'
, properties['ro.build.version.sdk']
))
, dest: '/data/local/tmp/remote_external.so'
, mode: 0755
}
}
function removeResource(res) {
return adb.shell(options.serial, ['rm', res.dest])
.timeout(10000)
.then(function(out) {
return streamutil.readAll(out)
})
.return(res)
}
function installResource(res) {
return adb.push(options.serial, res.src, res.dest, res.mode)
.timeout(10000)
.then(function(transfer) {
return new Promise(function(resolve, reject) {
transfer.on('error', reject)
transfer.on('end', resolve)
})
})
.return(res)
}
function ensureNotBusy(res) {
return adb.shell(options.serial, [res.dest, '--help'])
.timeout(10000)
.then(function(out) {
// Can be "Text is busy", "text busy"
return streamutil.findLine(out, (/busy/i))
.timeout(10000)
.then(function() {
log.info('Binary is busy, will retry')
return Promise.delay(1000)
})
.then(function() {
return ensureNotBusy(res)
})
.catch(streamutil.NoSuchLineError, function() {
return res
})
})
}
function installAll() {
return Promise.all([
removeResource(resources.bin).then(installResource).then(ensureNotBusy)
, removeResource(resources.lib).then(installResource)
])
}
function stop() {
return devutil.killProcsByComm(
adb
, options.serial
, resources.bin.comm
, resources.bin.dest
)
.timeout(15000)
}
return stop()
.then(installAll)
.then(function() {
return {
bin: resources.bin.dest
, lib: resources.lib.dest
}
})
})

View File

@@ -0,0 +1,104 @@
var util = require('util')
var syrup = require('syrup')
var ProtoBuf = require('protobufjs')
var semver = require('semver')
var pathutil = require('../../../util/pathutil')
var streamutil = require('../../../util/streamutil')
var promiseutil = require('../../../util/promiseutil')
var logger = require('../../../util/logger')
module.exports = syrup.serial()
.dependency(require('../support/adb'))
.define(function(options, adb) {
var log = logger.createLogger('device:resources:service')
var builder = ProtoBuf.loadProtoFile(pathutil.vendor('STFService/wire.proto'))
var resource = {
requiredVersion: '0.7.21'
, pkg: 'jp.co.cyberagent.stf'
, main: 'jp.co.cyberagent.stf.Agent'
, apk: pathutil.vendor('STFService/STFService.apk')
, wire: builder.build().jp.co.cyberagent.stf.proto
, builder: builder
, startIntent: {
action: 'jp.co.cyberagent.stf.ACTION_START'
, component: 'jp.co.cyberagent.stf/.Service'
}
}
function getPath() {
return adb.shell(options.serial, ['pm', 'path', resource.pkg])
.timeout(10000)
.then(function(out) {
return streamutil.findLine(out, (/^package:/))
.timeout(15000)
.then(function(line) {
return line.substr(8)
})
})
}
function install() {
log.info('Checking whether we need to install STFService')
return getPath()
.then(function(installedPath) {
log.info('Running version check')
return adb.shell(options.serial, util.format(
"export CLASSPATH='%s';" +
" exec app_process /system/bin '%s' --version"
, installedPath
, resource.main
))
.timeout(10000)
.then(function(out) {
return streamutil.readAll(out)
.timeout(10000)
.then(function(buffer) {
var version = buffer.toString()
if (semver.satisfies(version, resource.requiredVersion)) {
return installedPath
}
else {
throw new Error(util.format(
'Incompatible version %s'
, version
))
}
})
})
})
.catch(function() {
log.info('Installing STFService')
// Uninstall first to make sure we don't have any certificate
// issues.
return adb.uninstall(options.serial, resource.pkg)
.timeout(15000)
.then(function() {
return promiseutil.periodicNotify(
adb.install(options.serial, resource.apk)
, 10000
)
.timeout(60000)
})
.progressed(function() {
log.warn(
'STFService installation is taking a long time; '
+ 'perhaps you have to accept 3rd party app installation '
+ 'on the device?'
)
})
.then(function() {
return getPath()
})
})
}
return install()
.then(function(path) {
log.info('STFService up to date')
resource.path = path
return resource
})
})