Add an alternate install location for binary resources. Fixes devices where /data/local/tmp is mounted as noexec, like ZUK Z1. Closes #436.

This commit is contained in:
Simo Kinnunen
2017-02-10 04:45:14 +09:00
parent dc5ed0193f
commit 884c51b9b4
4 changed files with 145 additions and 38 deletions

View File

@@ -1,3 +1,4 @@
var fs = require('fs')
var util = require('util')
var path = require('path')
@@ -8,16 +9,17 @@ var logger = require('../../../util/logger')
var pathutil = require('../../../util/pathutil')
var devutil = require('../../../util/devutil')
var streamutil = require('../../../util/streamutil')
var Resource = require('./util/resource')
module.exports = syrup.serial()
.dependency(require('../support/adb'))
.dependency(require('../support/properties'))
.dependency(require('../support/abi'))
.define(function(options, adb, properties, abi) {
logger.createLogger('device:resources:minicap')
var log = logger.createLogger('device:resources:minicap')
var resources = {
bin: {
bin: new Resource({
src: pathutil.requiredMatch(abi.all.map(function(supportedAbi) {
return pathutil.module(util.format(
'minicap-prebuilt/prebuilt/%s/bin/minicap%s'
@@ -25,11 +27,14 @@ module.exports = syrup.serial()
, abi.pie ? '' : '-nopie'
))
}))
, dest: '/data/local/tmp/minicap'
, dest: [
'/data/local/tmp/minicap'
, '/data/data/com.android.shell/minicap'
]
, comm: 'minicap'
, mode: 0755
}
, lib: {
})
, lib: new Resource({
// @todo The lib ABI should match the bin ABI. Currently we don't
// have an x86_64 version of the binary while the lib supports it.
src: pathutil.requiredMatch(abi.all.reduce(function(all, supportedAbi) {
@@ -46,9 +51,13 @@ module.exports = syrup.serial()
))
])
}, []))
, dest: '/data/local/tmp/minicap.so'
, dest: [
'/data/local/tmp/minicap.so'
, '/data/data/com.android.shell/minicap.so'
]
, comm: 'minicap.so' // Not actually used for anything but log output
, mode: 0755
}
})
}
function removeResource(res) {
@@ -60,7 +69,7 @@ module.exports = syrup.serial()
.return(res)
}
function installResource(res) {
function pushResource(res) {
return adb.push(options.serial, res.src, res.dest, res.mode)
.timeout(10000)
.then(function(transfer) {
@@ -72,10 +81,39 @@ module.exports = syrup.serial()
.return(res)
}
function installResource(res) {
log.info('Installing "%s" as "%s"', res.comm, res.dest)
function checkExecutable(res) {
return adb.stat(options.serial, res.dest)
.timeout(5000)
.then(function(stats) {
return (stats.mode & fs.constants.S_IXUSR) === fs.constants.S_IXUSR
})
}
return removeResource(res)
.then(pushResource)
.then(function(res) {
return checkExecutable(res).then(function(ok) {
if (!ok) {
log.info(
'Pushed "%s" not executable, attempting fallback location'
, res.comm
)
res.shift()
return installResource(res)
}
return res
})
})
.return(res)
}
function installAll() {
return Promise.all([
removeResource(resources.bin).then(installResource)
, removeResource(resources.lib).then(installResource)
installResource(resources.bin)
, installResource(resources.lib)
])
}