mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-17 23:53:25 +02:00
improve the solution with one-liner command 'ps -lef||ps'
This commit is contained in:
@@ -5,8 +5,6 @@ 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
|
||||
}
|
||||
@@ -41,48 +39,28 @@ devutil.listPidsByComm = function(adb, serial, comm, bin) {
|
||||
shell: true
|
||||
}
|
||||
|
||||
return new Promise(function(resolve) {
|
||||
if ('ps' in commands) {
|
||||
resolve(commands)
|
||||
}
|
||||
else {
|
||||
adb.getProperties(serial)
|
||||
.then(function(properties) {
|
||||
var 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
|
||||
return adb.shell(serial, 'ps -lef||ps')
|
||||
.then(function(out) {
|
||||
return new Promise(function(resolve) {
|
||||
var header = true
|
||||
var pids = []
|
||||
out.pipe(split())
|
||||
.on('data', function(chunk) {
|
||||
if (header&&chunk.toString().indexOf('bad pid') === -1) {
|
||||
header = false
|
||||
}
|
||||
else {
|
||||
var cols = chunk.toString().split(/\s+/)
|
||||
if (cols.pop() === bin && users[cols[0]]) {
|
||||
pids.push(Number(cols[1]))
|
||||
}
|
||||
else {
|
||||
var cols = chunk.toString().split(/\s+/)
|
||||
if (cols.pop() === bin && users[cols[0]]) {
|
||||
pids.push(Number(cols[1]))
|
||||
}
|
||||
}
|
||||
})
|
||||
.on('end', function() {
|
||||
resolve(pids)
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
.on('end', function() {
|
||||
resolve(pids)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
devutil.waitForProcsToDie = function(adb, serial, comm, bin) {
|
||||
|
||||
Reference in New Issue
Block a user