mirror of
https://github.com/openstf/stf
synced 2025-10-05 02:29:26 +02:00
Implement get SD card status (if it's mounted or not).
This commit is contained in:
parent
2c5a2de17c
commit
dab1ab9bd9
9 changed files with 77 additions and 1 deletions
|
@ -35,6 +35,7 @@ module.exports = function(options) {
|
|||
.dependency(require('./device/plugins/account'))
|
||||
.dependency(require('./device/plugins/ringer'))
|
||||
.dependency(require('./device/plugins/wifi'))
|
||||
.dependency(require('./device/plugins/sd'))
|
||||
.define(function(options, solo) {
|
||||
if (process.send) {
|
||||
// Only if we have a parent process
|
||||
|
|
33
lib/roles/device/plugins/sd.js
Normal file
33
lib/roles/device/plugins/sd.js
Normal file
|
@ -0,0 +1,33 @@
|
|||
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:sd')
|
||||
|
||||
router.on(wire.SdStatusMessage, function(channel, message) {
|
||||
var reply = wireutil.reply(options.serial)
|
||||
log.info('Getting SD card status')
|
||||
service.getSdStatus(message)
|
||||
.timeout(30000)
|
||||
.then(function(mounted) {
|
||||
push.send([
|
||||
channel
|
||||
, reply.okay(mounted ? 'sd_mounted' : 'sd_unmounted')
|
||||
])
|
||||
})
|
||||
.error(function(err) {
|
||||
log.error('Getting SD card Status', err.stack)
|
||||
push.send([
|
||||
channel
|
||||
, reply.fail(err.message)
|
||||
])
|
||||
})
|
||||
})
|
||||
})
|
|
@ -565,6 +565,21 @@ module.exports = syrup.serial()
|
|||
})
|
||||
}
|
||||
|
||||
plugin.getSdStatus = function () {
|
||||
return runServiceCommand(
|
||||
apk.wire.MessageType.GET_SD_STATUS
|
||||
, new apk.wire.GetSdStatusRequest()
|
||||
)
|
||||
.timeout(10000)
|
||||
.then(function(data) {
|
||||
var response = apk.wire.GetSdStatusResponse.decode(data)
|
||||
if (response.success) {
|
||||
return response.mounted
|
||||
}
|
||||
throw new Error('Unable to get SD card status')
|
||||
})
|
||||
}
|
||||
|
||||
plugin.pressKey = function(key) {
|
||||
keyEvent({event: apk.wire.KeyEvent.PRESS, keyCode: keyutil.namedKey(key)})
|
||||
return Promise.resolve(true)
|
||||
|
|
|
@ -15,7 +15,7 @@ module.exports = syrup.serial()
|
|||
var log = logger.createLogger('device:resources:service')
|
||||
|
||||
var resource = {
|
||||
requiredVersion: '0.7.15'
|
||||
requiredVersion: '0.7.16'
|
||||
, pkg: 'jp.co.cyberagent.stf'
|
||||
, main: 'jp.co.cyberagent.stf.Agent'
|
||||
, apk: pathutil.vendor('STFService/STFService.apk')
|
||||
|
|
|
@ -358,6 +358,16 @@ module.exports = function(options) {
|
|||
)
|
||||
])
|
||||
})
|
||||
.on('sd.status', function(channel, responseChannel) {
|
||||
joinChannel(responseChannel)
|
||||
push.send([
|
||||
channel
|
||||
, wireutil.transaction(
|
||||
responseChannel
|
||||
, new wire.SdStatusMessage()
|
||||
)
|
||||
])
|
||||
})
|
||||
.on('ringer.set', function(channel, responseChannel, data) {
|
||||
joinChannel(responseChannel)
|
||||
push.send([
|
||||
|
|
|
@ -60,6 +60,7 @@ enum MessageType {
|
|||
WifiGetStatusMessage = 58;
|
||||
AccountAddMenuMessage = 59;
|
||||
AccountAddMessage = 60;
|
||||
SdStatusMessage = 61;
|
||||
}
|
||||
|
||||
message Envelope {
|
||||
|
@ -399,6 +400,9 @@ message AccountAddMessage {
|
|||
required string password = 2;
|
||||
}
|
||||
|
||||
message SdStatusMessage {
|
||||
}
|
||||
|
||||
message RingerSetMessage {
|
||||
required int32 mode = 1;
|
||||
}
|
||||
|
|
|
@ -233,6 +233,10 @@ module.exports = function ControlServiceFactory(
|
|||
})
|
||||
}
|
||||
|
||||
this.getSdStatus = function() {
|
||||
return sendTwoWay('sd.status')
|
||||
}
|
||||
|
||||
this.setRingerMode = function(mode) {
|
||||
return sendTwoWay('ringer.set', {
|
||||
mode: mode
|
||||
|
|
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
|
@ -12,6 +12,7 @@ enum MessageType {
|
|||
GET_CLIPBOARD = 6;
|
||||
GET_DISPLAY = 19;
|
||||
GET_PROPERTIES = 7;
|
||||
GET_SD_STATUS = 25;
|
||||
GET_VERSION = 8;
|
||||
GET_WIFI_STATUS = 23;
|
||||
SET_CLIPBOARD = 9;
|
||||
|
@ -221,6 +222,14 @@ message GetWifiStatusResponse {
|
|||
required bool status = 2;
|
||||
}
|
||||
|
||||
message GetSdStatusRequest {
|
||||
}
|
||||
|
||||
message GetSdStatusResponse {
|
||||
required bool success = 1;
|
||||
required bool mounted = 2;
|
||||
}
|
||||
|
||||
// Agent
|
||||
|
||||
enum KeyEvent {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue