1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-04 10:19:30 +02:00

Implement set Wifi on/off.

This commit is contained in:
Valverde Antonio 2014-06-27 16:21:42 +09:00
parent 9a31fbbfca
commit 6f7fdffe3d
9 changed files with 81 additions and 1 deletions

View file

@ -34,6 +34,7 @@ module.exports = function(options) {
.dependency(require('./device/plugins/connect')) .dependency(require('./device/plugins/connect'))
.dependency(require('./device/plugins/account')) .dependency(require('./device/plugins/account'))
.dependency(require('./device/plugins/ringer')) .dependency(require('./device/plugins/ringer'))
.dependency(require('./device/plugins/wifi'))
.define(function(options, solo) { .define(function(options, solo) {
if (process.send) { if (process.send) {
// Only if we have a parent process // Only if we have a parent process

View file

@ -521,6 +521,20 @@ module.exports = syrup.serial()
}) })
} }
plugin.setWifiEnabled = function(enabled) {
return runServiceCommand(
apk.wire.MessageType.SET_WIFI_ENABLED
, new apk.wire.SetWifiEnabledRequest(enabled)
)
.timeout(10000)
.then(function(data) {
var response = apk.wire.SetWifiEnabledResponse.decode(data)
if (!response.success) {
throw new Error('Unable to set Wifi')
}
})
}
function runServiceCommand(type, cmd) { function runServiceCommand(type, cmd) {
var resolver = Promise.defer() var resolver = Promise.defer()
var id = Math.floor(Math.random() * 0xFFFFFF) var id = Math.floor(Math.random() * 0xFFFFFF)

View file

@ -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('./service'))
.dependency(require('../support/router'))
.dependency(require('../support/push'))
.define(function(options, service, router, push) {
var log = logger.createLogger('device:plugins:wifi')
router.on(wire.WifiSetEnabledMessage, function(channel, message) {
var reply = wireutil.reply(options.serial)
log.info('Setting Wifi "%s"', message.enabled)
service.setWifiEnabled(message.enabled)
.timeout(30000)
.then(function() {
push.send([
channel
, reply.okay()
])
})
.error(function(err) {
log.error('Setting wifi enabled failed', err.stack)
push.send([
channel
, reply.fail(err.message)
])
})
})
})

View file

@ -15,7 +15,7 @@ module.exports = syrup.serial()
var log = logger.createLogger('device:resources:service') var log = logger.createLogger('device:resources:service')
var resource = { var resource = {
requiredVersion: '0.7.10' requiredVersion: '0.7.11'
, 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')

View file

@ -341,6 +341,16 @@ module.exports = function(options) {
) )
]) ])
}) })
.on('wifi.set', function(channel, responseChannel, data) {
joinChannel(responseChannel)
push.send([
channel
, wireutil.transaction(
responseChannel
, new wire.WifiSetEnabledMessage(data.enabled)
)
])
})
.on('group.invite', function(channel, responseChannel, data) { .on('group.invite', function(channel, responseChannel, data) {
joinChannel(responseChannel) joinChannel(responseChannel)
push.send([ push.send([

View file

@ -56,6 +56,7 @@ enum MessageType {
ConnectStopMessage = 54; ConnectStopMessage = 54;
AccountRemoveMessage = 55; AccountRemoveMessage = 55;
RingerSetMessage = 56; RingerSetMessage = 56;
WifiSetEnabledMessage = 57;
} }
message Envelope { message Envelope {
@ -391,6 +392,10 @@ message RingerSetMessage {
required int32 mode = 1; required int32 mode = 1;
} }
message WifiSetEnabledMessage {
required bool enabled = 1;
}
// Events, these must be kept in sync with STFService/wire.proto // Events, these must be kept in sync with STFService/wire.proto
message AirplaneModeEvent { message AirplaneModeEvent {

View file

@ -228,6 +228,12 @@ module.exports = function ControlServiceFactory(
}) })
} }
this.setWifiEnabled = function(enabled) {
return sendTwoWay('wifi.set', {
enabled: enabled
})
}
window.cc = this window.cc = this
} }

Binary file not shown.

View file

@ -17,6 +17,7 @@ enum MessageType {
SET_RINGER_MODE = 21; SET_RINGER_MODE = 21;
SET_ROTATION = 12; SET_ROTATION = 12;
SET_WAKE_LOCK = 11; SET_WAKE_LOCK = 11;
SET_WIFI_ENABLED = 22;
EVENT_AIRPLANE_MODE = 13; EVENT_AIRPLANE_MODE = 13;
EVENT_BATTERY = 14; EVENT_BATTERY = 14;
EVENT_CONNECTIVITY = 15; EVENT_CONNECTIVITY = 15;
@ -195,6 +196,14 @@ message SetRingerModeResponse {
required bool success = 1; required bool success = 1;
} }
message SetWifiEnabledRequest {
required bool enabled = 1;
}
message SetWifiEnabledResponse {
required bool success = 1;
}
// Agent // Agent
enum KeyEvent { enum KeyEvent {