mirror of
https://github.com/openstf/stf
synced 2025-10-04 18:29:17 +02:00
Merge pull request #806 from thinkhy/patch_180204
Use 'ps -lef' instead of 'ps' to list Pids on Android 8.x
This commit is contained in:
commit
32c9949bd7
1 changed files with 45 additions and 19 deletions
|
@ -39,28 +39,54 @@ devutil.listPidsByComm = function(adb, serial, comm, bin) {
|
||||||
shell: true
|
shell: true
|
||||||
}
|
}
|
||||||
|
|
||||||
return adb.shell(serial, ['ps'])
|
var findProcess = function(out) {
|
||||||
.then(function(out) {
|
return new Promise(function(resolve) {
|
||||||
return new Promise(function(resolve) {
|
var header = true
|
||||||
var header = true
|
var pids = []
|
||||||
var pids = []
|
var showTotalPid = false
|
||||||
out.pipe(split())
|
|
||||||
.on('data', function(chunk) {
|
out.pipe(split())
|
||||||
if (header) {
|
.on('data', function(chunk) {
|
||||||
header = false
|
if (header) {
|
||||||
|
header = false
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var cols = chunk.toString().split(/\s+/)
|
||||||
|
if (!showTotalPid && cols[0] === 'root') {
|
||||||
|
showTotalPid = true
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
var cols = chunk.toString().split(/\s+/)
|
// last column of output would be command name containing absolute path like '/data/local/tmp/minicap'
|
||||||
if (cols.pop() === bin && users[cols[0]]) {
|
// or just binary name like 'minicap', it depends on device/ROM
|
||||||
pids.push(Number(cols[1]))
|
var lastCol = cols.pop()
|
||||||
}
|
if ((lastCol === comm || lastCol === bin) && users[cols[0]]) {
|
||||||
|
pids.push(Number(cols[1]))
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
.on('end', function() {
|
})
|
||||||
resolve(pids)
|
.on('end', function() {
|
||||||
})
|
resolve({showTotalPid: showTotalPid, pids: pids})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return adb.shell(serial, 'ps 2>/dev/null')
|
||||||
|
.then(findProcess)
|
||||||
|
.then(function(res) {
|
||||||
|
// return pids if process can be found in the output of 'ps' command
|
||||||
|
// or 'ps' command has already displayed all the processes including processes launched by root user
|
||||||
|
if (res.showTotalPid || res.pids.length > 0) {
|
||||||
|
return Promise.resolve(res.pids)
|
||||||
|
}
|
||||||
|
// otherwise try to run 'ps -elf'
|
||||||
|
else {
|
||||||
|
return adb.shell(serial, 'ps -lef 2>/dev/null')
|
||||||
|
.then(findProcess)
|
||||||
|
.then(function(res) {
|
||||||
|
return Promise.resolve(res.pids)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
devutil.waitForProcsToDie = function(adb, serial, comm, bin) {
|
devutil.waitForProcsToDie = function(adb, serial, comm, bin) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue