Wake up and unlock device when it's being used. A bit messy, pending refactor.

This commit is contained in:
Simo Kinnunen
2014-03-04 18:00:31 +09:00
parent 999e5113bf
commit a25df0b293
6 changed files with 183 additions and 20 deletions

View File

@@ -91,6 +91,36 @@ devutil.waitForPort = function(adb, serial, port) {
})
}
devutil.waitForPortToFree = function(adb, serial, port) {
function closedError(err) {
return err.message === 'closed'
}
return adb.openTcpAsync(serial, port)
.then(function(conn) {
var resolver = Promise.defer()
function endListener() {
resolver.resolve(port)
}
function errorListener(err) {
resolver.reject(err)
}
conn.on('end', endListener)
conn.on('error', errorListener)
return resolver.promise.finally(function() {
conn.removeListener('end', endListener)
conn.removeListener('error', errorListener)
conn.end()
})
})
.catch(closedError, function(err) {
return port
})
}
devutil.listPidsByComm = function(adb, serial, comm, bin) {
var users = {
shell: true

View File

@@ -1,6 +1,18 @@
var util = require('util')
var Promise = require('bluebird')
var split = require('split')
function NoSuchLineError(message) {
Error.call(this, message)
this.name = 'NoSuchLineError'
Error.captureStackTrace(this, NoSuchLineError)
}
util.inherits(NoSuchLineError, Error)
module.exports.NoSuchLineError = NoSuchLineError
module.exports.readAll = function(stream) {
var resolver = Promise.defer()
, collected = new Buffer(0)
@@ -41,7 +53,7 @@ module.exports.findLine = function(stream, re) {
}
function endListener() {
resolver.reject(new Error('No matching line found'))
resolver.reject(new NoSuchLineError())
}
function lineListener(line) {