mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-17 15:43:25 +02:00
fix SDK<34 STFService installation (#804)
* tackle case where old SDK not support BLUETOOTH_CONNECT permission Signed-off-by: Jussi Vatjus-Anttila <jussiva@gmail.com> * make permissions logic more future proof Signed-off-by: Jussi Vatjus-Anttila <jussiva@gmail.com> --------- Signed-off-by: Jussi Vatjus-Anttila <jussiva@gmail.com>
This commit is contained in:
committed by
GitHub
parent
8aae1616ac
commit
8f22cb0a19
@@ -3,6 +3,7 @@ var util = require('util')
|
||||
var syrup = require('@devicefarmer/stf-syrup')
|
||||
var ProtoBuf = require('protobufjs')
|
||||
var semver = require('semver')
|
||||
var Promise = require('bluebird')
|
||||
|
||||
var pathutil = require('../../../util/pathutil')
|
||||
var streamutil = require('../../../util/streamutil')
|
||||
@@ -12,7 +13,8 @@ const adbkit = require('@devicefarmer/adbkit')
|
||||
|
||||
module.exports = syrup.serial()
|
||||
.dependency(require('../support/adb'))
|
||||
.define(function(options, adb) {
|
||||
.dependency(require('../support/sdk'))
|
||||
.define(function(options, adb, sdk) {
|
||||
var log = logger.createLogger('device:resources:service')
|
||||
var builder = ProtoBuf.loadProtoFile(
|
||||
pathutil.vendor('STFService/wire.proto'))
|
||||
@@ -97,19 +99,45 @@ module.exports = syrup.serial()
|
||||
})
|
||||
}
|
||||
|
||||
function setPermission(path) {
|
||||
function grantPermission(permission, minSdk) {
|
||||
if (minSdk && sdk.level < minSdk) {
|
||||
log.debug('SDK version (%d) is lower than %d, permission %s not supported',
|
||||
sdk.level, minSdk, permission)
|
||||
return Promise.resolve()
|
||||
}
|
||||
log.debug('Granting permission to STFService: ' + permission)
|
||||
return adb.shell(options.serial, [
|
||||
'pm', 'grant', resource.pkg
|
||||
, 'android.permission.BLUETOOTH_CONNECT'
|
||||
, 'android.permission.SYSTEM_ALERT_WINDOW'])
|
||||
'pm', 'grant', resource.pkg, permission])
|
||||
.then(adbkit.util.readAll)
|
||||
.then(function(out) {
|
||||
log.debug('output of granting permissions to STFService: ' + out.toString())
|
||||
return path
|
||||
.then(function() {
|
||||
log.debug('Permission granted %s', permission)
|
||||
})
|
||||
.catch(function(err) {
|
||||
log.error('Failed to grant permission %s: %s', permission, err)
|
||||
throw err
|
||||
})
|
||||
}
|
||||
function grantBluetoothPermission() {
|
||||
// https://developer.android.com/reference/android/Manifest.permission#BLUETOOTH_CONNECT
|
||||
// permission added in SDK 31 and above
|
||||
return grantPermission('android.permission.BLUETOOTH_CONNECT', 31)
|
||||
}
|
||||
function grantSystemPermission() {
|
||||
return grantPermission('android.permission.SYSTEM_ALERT_WINDOW')
|
||||
}
|
||||
|
||||
function grantServicePermissions() {
|
||||
return grantBluetoothPermission()
|
||||
.then(grantSystemPermission)
|
||||
}
|
||||
|
||||
return install()
|
||||
.then(setPermission)
|
||||
.then(function(path) {
|
||||
return grantServicePermissions()
|
||||
.then(function() {
|
||||
return path
|
||||
})
|
||||
})
|
||||
.then(function(path) {
|
||||
log.info('STFService up to date')
|
||||
resource.path = path
|
||||
|
||||
@@ -30,7 +30,8 @@
|
||||
},
|
||||
"scripts": {
|
||||
"test": "gulp test",
|
||||
"prepare": "bower install && not-in-install && gulp build || in-install"
|
||||
"prepare": "bower install && not-in-install && gulp build || in-install",
|
||||
"local": "node lib/cli/index.js local"
|
||||
},
|
||||
"dependencies": {
|
||||
"@devicefarmer/adbkit": "^2.11.3",
|
||||
|
||||
Reference in New Issue
Block a user