1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-04 18:29:17 +02:00

Use 'ps -lef' instead of 'ps' to list Pids on Android 8.x

This commit is contained in:
song 2018-02-04 18:48:28 +08:00
parent 2dac3d1bbd
commit fa50c56bb9

View file

@ -5,6 +5,8 @@ var Promise = require('bluebird')
var devutil = module.exports = Object.create(null)
var commands = Object.create(null)
function closedError(err) {
return err.message.indexOf('closed') !== -1
}
@ -39,28 +41,46 @@ devutil.listPidsByComm = function(adb, serial, comm, bin) {
shell: true
}
return adb.shell(serial, ['ps'])
.then(function(out) {
return new Promise(function(resolve) {
var header = true
var pids = []
out.pipe(split())
.on('data', function(chunk) {
if (header) {
header = false
}
else {
var cols = chunk.toString().split(/\s+/)
if (cols.pop() === bin && users[cols[0]]) {
pids.push(Number(cols[1]))
}
}
})
.on('end', function() {
resolve(pids)
})
})
})
return new Promise(function(resolve) {
if ('ps' in commands) {
resolve(commands)
} else {
adb.getProperties(serial)
.then(function (properties) {
version = properties['ro.build.version.release']
if (version.match(/^8\./) != null) {
commands['ps'] = 'ps -lef'
} else {
commands['ps'] = 'ps'
}
resolve(commands)
})
}
})
.then(function (commands) {
return adb.shell(serial, [commands['ps']])
.then(function (out) {
return new Promise(function (resolve) {
var header = true
var pids = []
out.pipe(split())
.on('data', function (chunk) {
if (header) {
header = false
}
else {
var cols = chunk.toString().split(/\s+/)
if (cols.pop() === bin && users[cols[0]]) {
pids.push(Number(cols[1]))
}
}
})
.on('end', function () {
resolve(pids)
})
})
})
})
}
devutil.waitForProcsToDie = function(adb, serial, comm, bin) {