mirror of
https://github.com/openstf/stf
synced 2025-10-04 18:29:17 +02:00
Implement set Wifi on/off.
This commit is contained in:
parent
9a31fbbfca
commit
6f7fdffe3d
9 changed files with 81 additions and 1 deletions
|
@ -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
|
||||||
|
|
|
@ -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)
|
||||||
|
|
35
lib/roles/device/plugins/wifi.js
Normal file
35
lib/roles/device/plugins/wifi.js
Normal 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)
|
||||||
|
])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
|
@ -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')
|
||||||
|
|
|
@ -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([
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -228,6 +228,12 @@ module.exports = function ControlServiceFactory(
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.setWifiEnabled = function(enabled) {
|
||||||
|
return sendTwoWay('wifi.set', {
|
||||||
|
enabled: enabled
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
window.cc = this
|
window.cc = this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
BIN
vendor/STFService/STFService.apk
vendored
BIN
vendor/STFService/STFService.apk
vendored
Binary file not shown.
9
vendor/STFService/wire.proto
vendored
9
vendor/STFService/wire.proto
vendored
|
@ -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 {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue