diff --git a/lib/roles/device/plugins/browsers.js b/lib/roles/device/plugins/browsers.js index f4d3f429..310203d9 100644 --- a/lib/roles/device/plugins/browsers.js +++ b/lib/roles/device/plugins/browsers.js @@ -12,6 +12,7 @@ module.exports = syrup() log.info('Fetching browser list') return input.getBrowsers() + .timeout(15000) .then(function(browsers) { var icons = Object.create(null) diff --git a/lib/roles/device/plugins/http.js b/lib/roles/device/plugins/http.js index 1dd0e76e..19517218 100644 --- a/lib/roles/device/plugins/http.js +++ b/lib/roles/device/plugins/http.js @@ -27,12 +27,14 @@ module.exports = syrup.serial() function openService() { log.info('Launching HTTP API') return devutil.ensureUnusedPort(adb, options.serial, service.port) + .timeout(10000) .then(function() { return adb.shell(options.serial, [ remote.bin , '--lib', remote.lib , '--listen-http', service.port ]) + .timeout(10000) .then(function(out) { lifecycle.share('Remote shell', out) streamutil.talk(log, 'Remote shell says: "%s"', out) @@ -40,6 +42,7 @@ module.exports = syrup.serial() .then(function() { return devutil.waitForPort(adb, options.serial, service.port) }) + .timeout(20000) .then(function(conn) { var ours = options.ports.pop() , everyones = options.ports.pop() @@ -62,6 +65,7 @@ module.exports = syrup.serial() , util.format('tcp:%d', ours) , util.format('tcp:%d', service.port) ) + .timeout(10000) .then(function() { log.info( 'Opening HTTP API proxy on "http://%s:%s"' @@ -113,6 +117,7 @@ module.exports = syrup.serial() ) , json: true }) + .timeout(10000) .then(function(args) { var display = args[1] assert.ok('id' in display, 'Invalid response from HTTP API') diff --git a/lib/roles/device/plugins/input.js b/lib/roles/device/plugins/input.js index fc489c95..0be82f57 100644 --- a/lib/roles/device/plugins/input.js +++ b/lib/roles/device/plugins/input.js @@ -37,9 +37,11 @@ module.exports = syrup.serial() function openAgent() { log.info('Launching input agent') return stopAgent() + .timeout(15000) .then(function() { return devutil.ensureUnusedPort(adb, options.serial, agent.port) }) + .timeout(10000) .then(function() { return adb.shell(options.serial, util.format( "export CLASSPATH='%s'; exec app_process /system/bin '%s'" @@ -47,6 +49,7 @@ module.exports = syrup.serial() , apk.main )) }) + .timeout(10000) .then(function(out) { lifecycle.share('InputAgent shell', out) streamutil.talk(log, 'InputAgent says: "%s"', out) @@ -54,6 +57,7 @@ module.exports = syrup.serial() .then(function() { return devutil.waitForPort(adb, options.serial, agent.port) }) + .timeout(10000) .then(function(conn) { agent.socket = conn agent.writer = new ms.DelimitingStream() @@ -76,22 +80,26 @@ module.exports = syrup.serial() 'am startservice --user 0 %s' , intent )) + .timeout(15000) .then(function(out) { return streamutil.findLine(out, /^Error/) .finally(function() { out.end() }) + .timeout(10000) .then(function(line) { if (line.indexOf('--user') !== -1) { return adb.shell(options.serial, util.format( 'am startservice %s' , intent )) + .timeout(15000) .then(function() { return streamutil.findLine(out, /^Error/) .finally(function() { out.end() }) + .timeout(10000) .then(function(line) { throw new Error(util.format( 'Service had an error: "%s"' @@ -119,15 +127,18 @@ module.exports = syrup.serial() function openService() { log.info('Launching input service') return stopService() + .timeout(15000) .then(function() { return devutil.waitForPortToFree(adb, options.serial, service.port) }) + .timeout(10000) .then(function() { return callService(util.format("-a '%s'", apk.startAction)) }) .then(function() { return devutil.waitForPort(adb, options.serial, service.port) }) + .timeout(15000) .then(function(conn) { service.socket = conn service.reader = conn.pipe(new ms.DelimitedStream()) @@ -159,6 +170,7 @@ module.exports = syrup.serial() apk.serviceProto.RequestType.VERSION , new apk.serviceProto.VersionRequest() ) + .timeout(10000) .then(function(data) { var response = apk.serviceProto.VersionResponse.decode(data) if (response.success) { @@ -173,6 +185,7 @@ module.exports = syrup.serial() apk.serviceProto.RequestType.SET_KEYGUARD_STATE , new apk.serviceProto.SetKeyguardStateRequest(false) ) + .timeout(10000) .then(function(data) { var response = apk.serviceProto.SetKeyguardStateResponse.decode(data) if (!response.success) { @@ -186,6 +199,7 @@ module.exports = syrup.serial() apk.serviceProto.RequestType.SET_KEYGUARD_STATE , new apk.serviceProto.SetKeyguardStateRequest(true) ) + .timeout(10000) .then(function(data) { var response = apk.serviceProto.SetKeyguardStateResponse.decode(data) if (!response.success) { @@ -199,6 +213,7 @@ module.exports = syrup.serial() apk.serviceProto.RequestType.SET_WAKE_LOCK , new apk.serviceProto.SetWakeLockRequest(true) ) + .timeout(10000) .then(function(data) { var response = apk.serviceProto.SetWakeLockResponse.decode(data) if (!response.success) { @@ -212,6 +227,7 @@ module.exports = syrup.serial() apk.serviceProto.RequestType.SET_WAKE_LOCK , new apk.serviceProto.SetWakeLockRequest(false) ) + .timeout(10000) .then(function(data) { var response = apk.serviceProto.SetWakeLockResponse.decode(data) if (!response.success) { @@ -225,6 +241,7 @@ module.exports = syrup.serial() apk.serviceProto.RequestType.IDENTIFY , new apk.serviceProto.IdentifyRequest(options.serial) ) + .timeout(10000) .then(function(data) { var response = apk.serviceProto.IdentifyResponse.decode(data) if (!response.success) { @@ -241,6 +258,7 @@ module.exports = syrup.serial() , text ) ) + .timeout(10000) .then(function(data) { var response = apk.serviceProto.SetClipboardResponse.decode(data) if (!response.success) { @@ -256,6 +274,7 @@ module.exports = syrup.serial() apk.serviceProto.ClipboardType.TEXT ) ) + .timeout(10000) .then(function(data) { var response = apk.serviceProto.GetClipboardResponse.decode(data) if (response.success) { @@ -273,6 +292,7 @@ module.exports = syrup.serial() apk.serviceProto.RequestType.GET_BROWSERS , new apk.serviceProto.GetBrowsersRequest() ) + .timeout(15000) .then(function(data) { var response = apk.serviceProto.GetBrowsersResponse.decode(data) if (response.success) { diff --git a/lib/roles/device/plugins/install.js b/lib/roles/device/plugins/install.js index f2c9a36f..63e153f4 100644 --- a/lib/roles/device/plugins/install.js +++ b/lib/roles/device/plugins/install.js @@ -49,6 +49,7 @@ module.exports = syrup.serial() var target = '/data/local/tmp/_app.apk' return adb.push(options.serial, source, target) + .timeout(10000) .then(function(transfer) { var resolver = Promise.defer() @@ -93,6 +94,7 @@ module.exports = syrup.serial() sendProgress('Installing app', 80) return adb.installRemote(options.serial, apk) }) + .timeout(10000) .then(function() { if (message.launchActivity) { log.info( @@ -105,6 +107,7 @@ module.exports = syrup.serial() return adb.startActivity(options.serial, message.launchActivity) } }) + .timeout(15000) .then(function() { push.send([ channel diff --git a/lib/roles/device/plugins/logcat.js b/lib/roles/device/plugins/logcat.js index 51f4f89b..d94b683e 100644 --- a/lib/roles/device/plugins/logcat.js +++ b/lib/roles/device/plugins/logcat.js @@ -16,6 +16,7 @@ module.exports = syrup.serial() function openService() { log.info('Launching logcat service') return adb.openLogcat(options.serial) + .timeout(10000) .then(function(logcat) { return lifecycle.share('Logcat', logcat) }) diff --git a/lib/roles/device/plugins/shell.js b/lib/roles/device/plugins/shell.js index 2cabf7ae..159eeaf4 100644 --- a/lib/roles/device/plugins/shell.js +++ b/lib/roles/device/plugins/shell.js @@ -19,6 +19,7 @@ module.exports = syrup.serial() log.info('Running shell command "%s"', message.command) adb.shell(options.serial, message.command) + .timeout(10000) .then(function(stream) { var resolver = Promise.defer() , timer diff --git a/lib/roles/device/plugins/stats.js b/lib/roles/device/plugins/stats.js index 95971c81..d9cb7a40 100644 --- a/lib/roles/device/plugins/stats.js +++ b/lib/roles/device/plugins/stats.js @@ -17,6 +17,7 @@ module.exports = syrup.serial() function openService() { return devutil.ensureUnusedPort(adb, options.serial, service.port) + .timeout(10000) .then(function() { return adb.shell(options.serial, [ remote.bin @@ -28,9 +29,11 @@ module.exports = syrup.serial() streamutil.talk(log, 'Stats shell says: "%s"', out) }) }) + .timeout(10000) .then(function() { return devutil.waitForPort(adb, options.serial, service.port) }) + .timeout(15000) .then(function(conn) { return lifecycle.share('Stats connection', conn) }) diff --git a/lib/roles/device/plugins/touch.js b/lib/roles/device/plugins/touch.js index d559cede..16d4447c 100644 --- a/lib/roles/device/plugins/touch.js +++ b/lib/roles/device/plugins/touch.js @@ -22,6 +22,7 @@ module.exports = syrup.serial() function openService() { log.info('Launching touch service') return devutil.ensureUnusedPort(adb, options.serial, service.port) + .timeout(10000) .then(function() { return adb.shell(options.serial, [ remote.bin @@ -29,6 +30,7 @@ module.exports = syrup.serial() , '--listen-input', service.port ]) }) + .timeout(10000) .then(function(out) { lifecycle.share('Touch shell', out) streamutil.talk(log, 'Touch shell says: "%s"', out) @@ -36,6 +38,7 @@ module.exports = syrup.serial() .then(function() { return devutil.waitForPort(adb, options.serial, service.port) }) + .timeout(15000) .then(function(conn) { return Promise.promisifyAll(monkey.connectStream(conn)) }) diff --git a/lib/roles/device/resources/remote.js b/lib/roles/device/resources/remote.js index 93f1092d..9cedd801 100644 --- a/lib/roles/device/resources/remote.js +++ b/lib/roles/device/resources/remote.js @@ -36,6 +36,7 @@ module.exports = syrup.serial() function removeResource(res) { return adb.shell(options.serial, ['rm', res.dest]) + .timeout(10000) .then(function(out) { return streamutil.readAll(out) }) @@ -44,6 +45,7 @@ module.exports = syrup.serial() function installResource(res) { return adb.push(options.serial, res.src, res.dest, res.mode) + .timeout(10000) .then(function(transfer) { return new Promise(function(resolve, reject) { transfer.on('error', reject) @@ -55,9 +57,11 @@ module.exports = syrup.serial() function ensureNotBusy(res) { return adb.shell(options.serial, [res.dest, '--help']) + .timeout(10000) .then(function(out) { // Can be "Text is busy", "text busy" return streamutil.findLine(out, (/busy/i)) + .timeout(10000) .then(function() { log.info('Binary is busy, will retry') return Promise.delay(1000) @@ -80,11 +84,12 @@ module.exports = syrup.serial() function stop() { return devutil.killProcsByComm( - adb - , options.serial - , resources.bin.comm - , resources.bin.dest - ) + adb + , options.serial + , resources.bin.comm + , resources.bin.dest + ) + .timeout(15000) } return stop() diff --git a/lib/roles/device/resources/service.js b/lib/roles/device/resources/service.js index 15d6b1b7..f147ecce 100644 --- a/lib/roles/device/resources/service.js +++ b/lib/roles/device/resources/service.js @@ -30,8 +30,10 @@ module.exports = syrup.serial() function getPath() { return adb.shell(options.serial, ['pm', 'path', resource.pkg]) + .timeout(10000) .then(function(out) { return streamutil.findLine(out, (/^package:/)) + .timeout(15000) .then(function(line) { return line.substr(8) }) @@ -49,6 +51,7 @@ module.exports = syrup.serial() , installedPath , resource.main )) + .timeout(10000) .then(function(out) { return streamutil.readAll(out) .timeout(10000) @@ -69,6 +72,7 @@ module.exports = syrup.serial() .catch(function() { log.info('Installing STFService') return adb.install(options.serial, resource.apk) + .timeout(30000) .then(function() { return getPath() })