From b84d1b97c620aee34609fdb668e1563cdad5edad Mon Sep 17 00:00:00 2001 From: Valverde Antonio Date: Thu, 19 Jun 2014 19:29:59 +0900 Subject: [PATCH] Reboot functionality added --- lib/roles/device.js | 1 + lib/roles/device/plugins/reboot.js | 35 +++++++++++++++++++ lib/roles/websocket.js | 10 ++++++ lib/wire/wire.proto | 4 +++ .../components/stf/control/control-service.js | 4 +++ 5 files changed, 54 insertions(+) create mode 100644 lib/roles/device/plugins/reboot.js diff --git a/lib/roles/device.js b/lib/roles/device.js index 7ccbd7b8..1ca06d86 100644 --- a/lib/roles/device.js +++ b/lib/roles/device.js @@ -30,6 +30,7 @@ module.exports = function(options) { .dependency(require('./device/plugins/install')) .dependency(require('./device/plugins/forward')) .dependency(require('./device/plugins/group')) + .dependency(require('./device/plugins/reboot')) .define(function(options, solo) { if (process.send) { // Only if we have a parent process diff --git a/lib/roles/device/plugins/reboot.js b/lib/roles/device/plugins/reboot.js new file mode 100644 index 00000000..c0253f2f --- /dev/null +++ b/lib/roles/device/plugins/reboot.js @@ -0,0 +1,35 @@ +var syrup = require('syrup') + +var logger = require('../../../util/logger') +var wire = require('../../../wire') +var wireutil = require('../../../wire/util') + +module.exports = syrup.serial() + .dependency(require('../support/adb')) + .dependency(require('../support/router')) + .dependency(require('../support/push')) + .define(function(options, adb, router, push) { + var log = logger.createLogger('device:plugins:reboot') + + router.on(wire.RebootMessage, function(channel, message) { + var reply = wireutil.reply(options.serial) + + log.info('Rebooting') + + adb.reboot(options.serial) + .timeout(30000) + .then(function() { + push.send([ + channel + , reply.okay() + ]) + }) + .error(function(err) { + log.error('Reboot failed', err.stack) + push.send([ + channel + , reply.fail(err.message) + ]) + }) + }) + }) diff --git a/lib/roles/websocket.js b/lib/roles/websocket.js index 1b6a547f..1b007afb 100644 --- a/lib/roles/websocket.js +++ b/lib/roles/websocket.js @@ -310,6 +310,16 @@ module.exports = function(options) { ) ]) }) + .on('device.reboot', function(channel, responseChannel) { + joinChannel(responseChannel) + push.send([ + channel + , wireutil.transaction( + responseChannel + , new wire.RebootMessage() + ) + ]) + }) .on('group.invite', function(channel, responseChannel, data) { joinChannel(responseChannel) push.send([ diff --git a/lib/wire/wire.proto b/lib/wire/wire.proto index c44168f7..6f81b24e 100644 --- a/lib/wire/wire.proto +++ b/lib/wire/wire.proto @@ -51,6 +51,7 @@ enum MessageType { StoreOpenMessage = 49; ScreenCaptureMessage = 50; ProviderHeartbeatMessage = 51; + RebootMessage = 52; } message Envelope { @@ -279,6 +280,9 @@ message KeyPressMessage { required string key = 1; } +message RebootMessage { +} + // Output message DeviceLogcatEntryMessage { diff --git a/res/app/components/stf/control/control-service.js b/res/app/components/stf/control/control-service.js index ed3a69cc..0fef4615 100644 --- a/res/app/components/stf/control/control-service.js +++ b/res/app/components/stf/control/control-service.js @@ -148,6 +148,10 @@ module.exports = function ControlServiceFactory( }) } + this.reboot = function() { + return sendTwoWay('device.reboot') + } + this.rotate = function(rotation) { return sendOneWay('display.rotate', { rotation: rotation