diff --git a/lib/db/api.js b/lib/db/api.js index 04972c49..c5fad9da 100644 --- a/lib/db/api.js +++ b/lib/db/api.js @@ -174,7 +174,7 @@ dbapi.setDevicePhoneState = function(serial, state) { dbapi.setDeviceRotation = function(serial, rotation) { return db.run(r.table('devices').get(serial).update({ display: { - orientation: rotation + rotation: rotation } })) } diff --git a/lib/roles/device.js b/lib/roles/device.js index 58dad0d3..7ccbd7b8 100644 --- a/lib/roles/device.js +++ b/lib/roles/device.js @@ -17,10 +17,10 @@ module.exports = function(options) { log.info('Preparing device') return syrup.serial() .dependency(require('./device/plugins/solo')) - .dependency(require('./device/plugins/display')) .dependency(require('./device/plugins/screenshot')) .dependency(require('./device/plugins/http')) .dependency(require('./device/plugins/service')) + .dependency(require('./device/plugins/display')) .dependency(require('./device/plugins/browser')) .dependency(require('./device/plugins/store')) .dependency(require('./device/plugins/clipboard')) diff --git a/lib/roles/device/plugins/display.js b/lib/roles/device/plugins/display.js index cac8f633..604f6056 100644 --- a/lib/roles/device/plugins/display.js +++ b/lib/roles/device/plugins/display.js @@ -3,13 +3,22 @@ var syrup = require('syrup') var logger = require('../../../util/logger') module.exports = syrup.serial() + .dependency(require('./service')) .dependency(require('./http')) - .define(function(options, http) { + .define(function(options, service, http) { var log = logger.createLogger('device:plugins:display') function fetch() { log.info('Fetching display info') - return http.getDisplay(0) + return service.getDisplay(0) + .catch(function() { + log.info('Falling back to HTTP API') + return http.getDisplay(0) + }) + .then(function(display) { + display.url = http.getDisplayUrl(display.id) + return display + }) } return fetch() diff --git a/lib/roles/device/plugins/http.js b/lib/roles/device/plugins/http.js index 1e1b2009..9346fb4e 100644 --- a/lib/roles/device/plugins/http.js +++ b/lib/roles/device/plugins/http.js @@ -123,14 +123,21 @@ module.exports = syrup.serial() .then(function(args) { var display = args[1] assert.ok('id' in display, 'Invalid response from HTTP API') - display.url = util.format( - '%s/api/v1/displays/%d/screenshot.jpg' - , service.publicUrl - , id - ) + // Fix rotation's old name + if ('orientation' in display) { + display.rotation = display.orientation + delete display.orientation + } return display }) } + , getDisplayUrl: function(id) { + return util.format( + '%s/api/v1/displays/%d/screenshot.jpg' + , service.publicUrl + , id + ) + } } }) }) diff --git a/lib/roles/device/plugins/service.js b/lib/roles/device/plugins/service.js index cf387cf7..504bfd3a 100644 --- a/lib/roles/device/plugins/service.js +++ b/lib/roles/device/plugins/service.js @@ -280,6 +280,31 @@ module.exports = syrup.serial() return plugin.getClipboard() } + plugin.getDisplay = function(id) { + return runServiceCommand( + apk.wire.MessageType.GET_DISPLAY + , new apk.wire.GetDisplayRequest(id) + ) + .timeout(10000) + .then(function(data) { + var response = apk.wire.GetDisplayResponse.decode(data) + if (response.success) { + return { + id: id + , width: response.width + , height: response.height + , xdpi: response.xdpi + , ydpi: response.ydpi + , fps: response.fps + , density: response.density + , rotation: response.rotation + , secure: response.secure + } + } + throw new Error('Unable to retrieve display information') + }) + } + plugin.wake = function() { return runAgentCommand( apk.wire.MessageType.DO_WAKE diff --git a/lib/roles/device/plugins/solo.js b/lib/roles/device/plugins/solo.js index 309894b8..a7f57955 100644 --- a/lib/roles/device/plugins/solo.js +++ b/lib/roles/device/plugins/solo.js @@ -28,18 +28,7 @@ module.exports = syrup.serial() , identity.version , identity.abi , identity.sdk - , new wire.DeviceDisplayMessage( - identity.display.id - , identity.display.width - , identity.display.height - , identity.display.orientation - , identity.display.xdpi - , identity.display.ydpi - , identity.display.fps - , identity.display.density - , identity.display.secure - , identity.display.url - ) + , new wire.DeviceDisplayMessage(identity.display) , new wire.DevicePhoneMessage(identity.phone) )) ]) diff --git a/lib/roles/device/resources/service.js b/lib/roles/device/resources/service.js index e9a514c7..536be045 100644 --- a/lib/roles/device/resources/service.js +++ b/lib/roles/device/resources/service.js @@ -15,7 +15,7 @@ module.exports = syrup.serial() var log = logger.createLogger('device:resources:service') var resource = { - requiredVersion: '0.7.3' + requiredVersion: '0.7.7' , pkg: 'jp.co.cyberagent.stf' , main: 'jp.co.cyberagent.stf.Agent' , apk: pathutil.vendor('STFService/STFService.apk') diff --git a/lib/roles/websocket.js b/lib/roles/websocket.js index ea75d0db..1b6a547f 100644 --- a/lib/roles/websocket.js +++ b/lib/roles/websocket.js @@ -236,7 +236,7 @@ module.exports = function(options) { , data: { serial: message.serial , display: { - orientation: message.rotation + rotation: message.rotation } } }) diff --git a/lib/util/fakedevice.js b/lib/util/fakedevice.js index eb03c745..7c8d9947 100644 --- a/lib/util/fakedevice.js +++ b/lib/util/fakedevice.js @@ -33,7 +33,7 @@ module.exports.generate = function() { , fps: 60 , height: 1920 , id: 0 - , orientation: 0 + , rotation: 0 , secure: true , url: '/404.jpg' , width: 1080 diff --git a/lib/wire/wire.proto b/lib/wire/wire.proto index a54f02e7..6e1b32b1 100644 --- a/lib/wire/wire.proto +++ b/lib/wire/wire.proto @@ -131,14 +131,14 @@ message DeviceStatusMessage { } message DeviceDisplayMessage { - required uint32 id = 1; - required uint32 width = 2; - required uint32 height = 3; - required uint32 orientation = 4; - required uint32 xdpi = 5; - required uint32 ydpi = 6; - required double fps = 7; - required double density = 8; + required int32 id = 1; + required int32 width = 2; + required int32 height = 3; + required int32 rotation = 4; + required float xdpi = 5; + required float ydpi = 6; + required float fps = 7; + required float density = 8; required bool secure = 9; required string url = 10; } diff --git a/res/app/components/stf/screen/screen-directive.js b/res/app/components/stf/screen/screen-directive.js index b64652ed..be144c0f 100644 --- a/res/app/components/stf/screen/screen-directive.js +++ b/res/app/components/stf/screen/screen-directive.js @@ -35,7 +35,7 @@ module.exports = function DeviceScreenDirective($document, ScalingService, Vendo function sendTouch(type, e) { var x = e.offsetX || e.layerX || 0 var y = e.offsetY || e.layerY || 0 - var r = scope.device.display.orientation + var r = scope.device.display.rotation if (BrowserInfo.touch) { if (e.touches && e.touches.length) { @@ -304,7 +304,7 @@ module.exports = function DeviceScreenDirective($document, ScalingService, Vendo scope.$watch('device.using', checkEnabled) scope.$on('visibilitychange', checkEnabled) - scope.$watch('device.display.orientation', function (r) { + scope.$watch('device.display.rotation', function (r) { rotation = r || 0 }) diff --git a/res/app/control-panes/device-control/device-control-controller.js b/res/app/control-panes/device-control/device-control-controller.js index 9aa723d4..de9889b7 100644 --- a/res/app/control-panes/device-control/device-control-controller.js +++ b/res/app/control-panes/device-control/device-control-controller.js @@ -46,14 +46,14 @@ module.exports = function DeviceControlCtrl($scope, DeviceService, GroupService, function isPortrait(value) { if (typeof value === 'undefined' && $scope.device) { - value = $scope.device.display.orientation + value = $scope.device.display.rotation } return (value === 0 || value === 180) } function isLandscape(value) { if (typeof value === 'undefined' && $scope.device) { - value = $scope.device.display.orientation + value = $scope.device.display.rotation } return (value === 90 || value === 270) } @@ -78,7 +78,7 @@ module.exports = function DeviceControlCtrl($scope, DeviceService, GroupService, $scope.currentRotation = 'portrait' - $scope.$watch('device.display.orientation', function (newValue, oldValue) { + $scope.$watch('device.display.rotation', function (newValue, oldValue) { if (isPortrait(newValue)) { $scope.currentRotation = 'portrait' } else if (isLandscape(newValue)) { diff --git a/res/app/control-panes/device-control/device-control.jade b/res/app/control-panes/device-control/device-control.jade index f44a9cc4..fb7dab83 100644 --- a/res/app/control-panes/device-control/device-control.jade +++ b/res/app/control-panes/device-control/device-control.jade @@ -6,10 +6,10 @@ .btn-group label.btn-sm.btn-primary-outline(type='button', ng-click='tryToRotate("portrait")', ng-model='currentRotation', btn-radio='"portrait"').pointer - i.fa.fa-mobile(tooltip='{{ "Portrait" | translate }} ({{ device.display.orientation }}°)', tooltip-placement='bottom') + i.fa.fa-mobile(tooltip='{{ "Portrait" | translate }} ({{ device.display.rotation }}°)', tooltip-placement='bottom') label.btn-sm.btn-primary-outline(type='button', ng-click='tryToRotate("landscape")', ng-model='currentRotation', btn-radio='"landscape"').pointer - i.fa.fa-mobile.fa-rotate-90(tooltip='{{ "Landscape" | translate }} ({{ device.display.orientation }}°)', tooltip-placement='bottom') + i.fa.fa-mobile.fa-rotate-90(tooltip='{{ "Landscape" | translate }} ({{ device.display.rotation }}°)', tooltip-placement='bottom') .button-spacer // NOTE: ui-bootstrap bug: tooltip breaks btn-checkbox so don't put in the same button button(type='button', ng-model='showScreen', btn-checkbox).btn.btn-sm.btn-danger diff --git a/res/app/control-panes/info/info.jade b/res/app/control-panes/info/info.jade index 58952b07..23928829 100644 --- a/res/app/control-panes/info/info.jade +++ b/res/app/control-panes/info/info.jade @@ -71,7 +71,7 @@ angular-packery='{draggable: true, draggableHandle: ".heading i"}') td {{device.display.id}} tr td(translate) Orientation - td {{device.display.orientation}}° + td {{device.display.rotation}}° tr td(translate) Encrypted td {{device.display.secure | humanizedBool}} diff --git a/vendor/STFService/STFService.apk b/vendor/STFService/STFService.apk index 032cabde..855d668f 100644 Binary files a/vendor/STFService/STFService.apk and b/vendor/STFService/STFService.apk differ diff --git a/vendor/STFService/wire.proto b/vendor/STFService/wire.proto index e0569afa..f799063f 100644 --- a/vendor/STFService/wire.proto +++ b/vendor/STFService/wire.proto @@ -9,6 +9,7 @@ enum MessageType { DO_WAKE = 4; GET_BROWSERS = 5; GET_CLIPBOARD = 6; + GET_DISPLAY = 19; GET_PROPERTIES = 7; GET_VERSION = 8; SET_CLIPBOARD = 9; @@ -133,6 +134,22 @@ message GetBrowsersResponse { repeated BrowserApp apps = 3; } +message GetDisplayRequest { + required int32 id = 1; +} + +message GetDisplayResponse { + required bool success = 1; + optional int32 width = 2; + optional int32 height = 3; + optional float xdpi = 4; + optional float ydpi = 5; + optional float fps = 6; + optional float density = 7; + optional int32 rotation = 8; + optional bool secure = 9; +} + message Property { required string name = 1; required string value = 2;