1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-06 12:00:08 +02:00

Merge branch 'feature/get-ringer-mode' into develop

This commit is contained in:
Valverde Antonio 2014-08-15 18:50:03 +09:00
commit 27db828de3
8 changed files with 73 additions and 5 deletions

View file

@ -24,7 +24,7 @@ module.exports = syrup.serial()
, reply.okay() , reply.okay()
]) ])
}) })
.error(function(err) { .catch(function(err) {
log.error('Setting ringer mode failed', err.stack) log.error('Setting ringer mode failed', err.stack)
push.send([ push.send([
channel channel
@ -32,4 +32,26 @@ module.exports = syrup.serial()
]) ])
}) })
}) })
router.on(wire.RingerGetMessage, function(channel) {
var reply = wireutil.reply(options.serial)
log.info('Getting ringer mode')
service.getRingerMode()
.timeout(30000)
.then(function(mode) {
push.send([
channel
, reply.okay('success', mode)
])
})
.catch(function(err) {
log.error('Getting ringer mode failed', err.stack)
push.send([
channel
, reply.fail(err.message)
])
})
})
}) })

View file

@ -552,6 +552,25 @@ module.exports = syrup.serial()
}) })
} }
plugin.getRingerMode = function() {
return runServiceCommand(
apk.wire.MessageType.GET_RINGER_MODE
, new apk.wire.GetRingerModeRequest()
)
.timeout(10000)
.then(function(data) {
var response = apk.wire.GetRingerModeResponse.decode(data)
// Reflection to decode enums to their string values, otherwise
// we only get an integer
var ringerMode = apk.builder.lookup('jp.co.cyberagent.stf.proto.RingerMode')
.children[response.mode].name
if (response.success) {
return ringerMode
}
throw new Error('Unable to get ringer mode')
})
}
plugin.setWifiEnabled = function(enabled) { plugin.setWifiEnabled = function(enabled) {
return runServiceCommand( return runServiceCommand(
apk.wire.MessageType.SET_WIFI_ENABLED apk.wire.MessageType.SET_WIFI_ENABLED

View file

@ -13,15 +13,15 @@ module.exports = syrup.serial()
.dependency(require('../support/adb')) .dependency(require('../support/adb'))
.define(function(options, adb) { .define(function(options, adb) {
var log = logger.createLogger('device:resources:service') var log = logger.createLogger('device:resources:service')
var builder = ProtoBuf.loadProtoFile(pathutil.vendor('STFService/wire.proto'))
var resource = { var resource = {
requiredVersion: '0.7.20' requiredVersion: '0.7.21'
, pkg: 'jp.co.cyberagent.stf' , pkg: 'jp.co.cyberagent.stf'
, main: 'jp.co.cyberagent.stf.Agent' , main: 'jp.co.cyberagent.stf.Agent'
, apk: pathutil.vendor('STFService/STFService.apk') , apk: pathutil.vendor('STFService/STFService.apk')
, wire: ProtoBuf.loadProtoFile( , wire: builder.build().jp.co.cyberagent.stf.proto
pathutil.vendor('STFService/wire.proto') , builder: builder
).build().jp.co.cyberagent.stf.proto
, startIntent: { , startIntent: {
action: 'jp.co.cyberagent.stf.ACTION_START' action: 'jp.co.cyberagent.stf.ACTION_START'
, component: 'jp.co.cyberagent.stf/.Service' , component: 'jp.co.cyberagent.stf/.Service'

View file

@ -402,6 +402,16 @@ module.exports = function(options) {
) )
]) ])
}) })
.on('ringer.get', function(channel, responseChannel) {
joinChannel(responseChannel)
push.send([
channel
, wireutil.transaction(
responseChannel
, new wire.RingerGetMessage()
)
])
})
.on('wifi.set', function(channel, responseChannel, data) { .on('wifi.set', function(channel, responseChannel, data) {
joinChannel(responseChannel) joinChannel(responseChannel)
push.send([ push.send([

View file

@ -55,6 +55,7 @@ enum MessageType {
ConnectStartMessage = 53; ConnectStartMessage = 53;
ConnectStopMessage = 54; ConnectStopMessage = 54;
RingerSetMessage = 56; RingerSetMessage = 56;
RingerGetMessage = 64;
WifiSetEnabledMessage = 57; WifiSetEnabledMessage = 57;
WifiGetStatusMessage = 58; WifiGetStatusMessage = 58;
AccountAddMenuMessage = 59; AccountAddMenuMessage = 59;
@ -427,6 +428,9 @@ message RingerSetMessage {
required RingerMode mode = 1; required RingerMode mode = 1;
} }
message RingerGetMessage {
}
message WifiSetEnabledMessage { message WifiSetEnabledMessage {
required bool enabled = 1; required bool enabled = 1;
} }

View file

@ -259,6 +259,10 @@ module.exports = function ControlServiceFactory(
}) })
} }
this.getRingerMode = function() {
return sendTwoWay('ringer.get')
}
this.setWifiEnabled = function(enabled) { this.setWifiEnabled = function(enabled) {
return sendTwoWay('wifi.set', { return sendTwoWay('wifi.set', {
enabled: enabled enabled: enabled

Binary file not shown.

View file

@ -14,6 +14,7 @@ enum MessageType {
GET_CLIPBOARD = 6; GET_CLIPBOARD = 6;
GET_DISPLAY = 19; GET_DISPLAY = 19;
GET_PROPERTIES = 7; GET_PROPERTIES = 7;
GET_RINGER_MODE = 27;
GET_SD_STATUS = 25; GET_SD_STATUS = 25;
GET_VERSION = 8; GET_VERSION = 8;
GET_WIFI_STATUS = 23; GET_WIFI_STATUS = 23;
@ -218,6 +219,14 @@ message SetRingerModeResponse {
required bool success = 1; required bool success = 1;
} }
message GetRingerModeRequest {
}
message GetRingerModeResponse {
required bool success = 1;
required RingerMode mode = 2;
}
message SetWifiEnabledRequest { message SetWifiEnabledRequest {
required bool enabled = 1; required bool enabled = 1;
} }