mirror of
https://github.com/openstf/stf
synced 2025-10-04 10:19:30 +02:00
Mute devices when they're being used if the --mute-master option is given.
This commit is contained in:
parent
aca27428b0
commit
d9d47cc3bf
7 changed files with 65 additions and 2 deletions
11
lib/cli.js
11
lib/cli.js
|
@ -68,6 +68,8 @@ program
|
|||
, 'adb connect URL pattern'
|
||||
, String
|
||||
, '${publicIp}:${publicPort}')
|
||||
.option('--mute-master'
|
||||
, 'whether to mute master volume when devices are being used')
|
||||
.action(function() {
|
||||
var serials = cliutil.allUnknownArgs(arguments)
|
||||
, options = cliutil.lastArg(arguments)
|
||||
|
@ -107,7 +109,8 @@ program
|
|||
, '--screen-ws-url-pattern', options.screenWsUrlPattern
|
||||
, '--connect-url-pattern', options.connectUrlPattern
|
||||
, '--heartbeat-interval', options.heartbeatInterval
|
||||
])
|
||||
]
|
||||
.concat(options.muteMaster ? ['--mute-master'] : []))
|
||||
}
|
||||
, endpoints: {
|
||||
sub: options.connectSub
|
||||
|
@ -167,6 +170,8 @@ program
|
|||
, 'heartbeat interval'
|
||||
, Number
|
||||
, 10000)
|
||||
.option('--mute-master'
|
||||
, 'whether to mute master volume when devices are being used')
|
||||
.action(function(serial, options) {
|
||||
if (!options.connectSub) {
|
||||
this.missingArgument('--connect-sub')
|
||||
|
@ -204,6 +209,7 @@ program
|
|||
, connectUrlPattern: options.connectUrlPattern
|
||||
, connectPort: options.connectPort
|
||||
, heartbeatInterval: options.heartbeatInterval
|
||||
, muteMaster: options.muteMaster
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -911,6 +917,8 @@ program
|
|||
.option('--user-profile-url <url>'
|
||||
, 'URL to external user profile page'
|
||||
, String)
|
||||
.option('--mute-master'
|
||||
, 'whether to mute master volume when devices are being used')
|
||||
.action(function() {
|
||||
var log = logger.createLogger('cli:local')
|
||||
, args = arguments
|
||||
|
@ -976,6 +984,7 @@ program
|
|||
, '--adb-port', options.adbPort
|
||||
]
|
||||
.concat(options.allowRemote ? ['--allow-remote'] : [])
|
||||
.concat(options.muteMaster ? ['--mute-master'] : [])
|
||||
.concat(cliutil.allUnknownArgs(args)))
|
||||
|
||||
// auth
|
||||
|
|
|
@ -25,6 +25,7 @@ module.exports = function(options) {
|
|||
.dependency(require('./plugins/store'))
|
||||
.dependency(require('./plugins/clipboard'))
|
||||
.dependency(require('./plugins/logcat'))
|
||||
.dependency(require('./plugins/mute'))
|
||||
.dependency(require('./plugins/shell'))
|
||||
.dependency(require('./plugins/touch'))
|
||||
.dependency(require('./plugins/install'))
|
||||
|
|
30
lib/units/device/plugins/mute.js
Normal file
30
lib/units/device/plugins/mute.js
Normal file
|
@ -0,0 +1,30 @@
|
|||
var Promise = require('bluebird')
|
||||
var syrup = require('stf-syrup')
|
||||
|
||||
var logger = require('../../../util/logger')
|
||||
|
||||
module.exports = syrup.serial()
|
||||
.dependency(require('./group'))
|
||||
.dependency(require('./service'))
|
||||
.define(function(options, group, service) {
|
||||
var log = logger.createLogger('device:plugins:mute')
|
||||
|
||||
if (options.muteMaster) {
|
||||
log.info('Will mute master volume during use')
|
||||
|
||||
group.on('join', function() {
|
||||
log.info('Muting master volume');
|
||||
service.setMasterMute(true)
|
||||
})
|
||||
|
||||
group.on('leave', function() {
|
||||
log.info('Unmuting master volume');
|
||||
service.setMasterMute(false)
|
||||
})
|
||||
}
|
||||
else {
|
||||
log.info('Will not mute master volume during use')
|
||||
}
|
||||
|
||||
return Promise.resolve()
|
||||
})
|
|
@ -671,6 +671,20 @@ module.exports = syrup.serial()
|
|||
return Promise.resolve(true)
|
||||
}
|
||||
|
||||
plugin.setMasterMute = function(mode) {
|
||||
return runServiceCommand(
|
||||
apk.wire.MessageType.SET_MASTER_MUTE
|
||||
, new apk.wire.SetMasterMuteRequest(mode)
|
||||
)
|
||||
.timeout(10000)
|
||||
.then(function(data) {
|
||||
var response = apk.wire.SetMasterMuteResponse.decode(data)
|
||||
if (!response.success) {
|
||||
throw new Error('Unable to set master mute')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function runServiceCommand(type, cmd) {
|
||||
var resolver = Promise.defer()
|
||||
var id = Math.floor(Math.random() * 0xFFFFFF)
|
||||
|
|
|
@ -17,7 +17,7 @@ module.exports = syrup.serial()
|
|||
pathutil.vendor('STFService/wire.proto'))
|
||||
|
||||
var resource = {
|
||||
requiredVersion: '1.0.0'
|
||||
requiredVersion: '1.0.1'
|
||||
, pkg: 'jp.co.cyberagent.stf'
|
||||
, main: 'jp.co.cyberagent.stf.Agent'
|
||||
, apk: pathutil.vendor('STFService/STFService.apk')
|
||||
|
|
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
|
@ -24,6 +24,7 @@ enum MessageType {
|
|||
SET_ROTATION = 12;
|
||||
SET_WAKE_LOCK = 11;
|
||||
SET_WIFI_ENABLED = 22;
|
||||
SET_MASTER_MUTE = 28;
|
||||
EVENT_AIRPLANE_MODE = 13;
|
||||
EVENT_BATTERY = 14;
|
||||
EVENT_CONNECTIVITY = 15;
|
||||
|
@ -251,6 +252,14 @@ message GetSdStatusResponse {
|
|||
required bool mounted = 2;
|
||||
}
|
||||
|
||||
message SetMasterMuteRequest {
|
||||
required bool enabled = 1;
|
||||
}
|
||||
|
||||
message SetMasterMuteResponse {
|
||||
required bool success = 1;
|
||||
}
|
||||
|
||||
// Agent
|
||||
|
||||
enum KeyEvent {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue