diff --git a/communication/bluetooth_ble/src/main/js/test/BleAdvertiser.test.js b/communication/bluetooth_ble/src/main/js/test/BleAdvertiser.test.js index c748666b308e74e1c2ac504df965038e8d7ebbb9..006c6f73b87fbeec52e461da1f5a9fe319fd1b76 100644 --- a/communication/bluetooth_ble/src/main/js/test/BleAdvertiser.test.js +++ b/communication/bluetooth_ble/src/main/js/test/BleAdvertiser.test.js @@ -15,6 +15,11 @@ */ import bluetooth from '@ohos.bluetooth'; +import geolocation from '@ohos.geolocation'; +import geolocationm from '@ohos.geoLocationManager'; +import abilityAccessCtrl from '@ohos.abilityAccessCtrl'; +import bundle from '@ohos.bundle'; +import osaccount from '@ohos.account.osAccount'; import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' @@ -31,7 +36,7 @@ describe('bluetoothBLETest2', function() { case 0: console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta)); bluetooth.enableBluetooth(); - await sleep(3000); + await sleep(1000); break; case 1: console.info('[bluetooth_js] bt turning on:'+ JSON.stringify(sta)); @@ -43,12 +48,38 @@ describe('bluetoothBLETest2', function() { case 3: console.info('[bluetooth_js] bt turning off:'+ JSON.stringify(sta)); bluetooth.enableBluetooth(); - await sleep(3000); + await sleep(1000); break; default: console.info('[bluetooth_js] enable success'); } } + async function applyPermission() { + let osAccountManager = osaccount.getAccountManager(); + console.info("=== getAccountManager finish"); + let localId = await osAccountManager.getOsAccountLocalIdFromProcess(); + console.info("LocalId is :" + localId); + let appInfo = await bundle.getApplicationInfo('ohos.acts.location.geolocation.function', 0, localId); + let atManager = abilityAccessCtrl.createAtManager(); + if (atManager != null) { + let tokenID = appInfo.accessTokenId; + console.info('[permission] case accessTokenID is ' + tokenID); + let permissionName1 = 'ohos.permission.LOCATION'; + let permissionName2 = 'ohos.permission.LOCATION_IN_BACKGROUND'; + await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); + }); + await atManager.grantUserGrantedPermission(tokenID, permissionName2, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); + }); + } else { + console.info('[permission] case apply permission failed, createAtManager failed'); + } + } beforeAll(function () { console.info('beforeAll called') gattServer = bluetooth.BLE.createGattServer(); diff --git a/communication/bluetooth_ble/src/main/js/test/BleGattManager.test.js b/communication/bluetooth_ble/src/main/js/test/BleGattManager.test.js index 91d39d7060daf6a088c00e2b9ef78c8e02d2f870..f1841e59a25c54167aa944677e23fb7eecd15fca 100644 --- a/communication/bluetooth_ble/src/main/js/test/BleGattManager.test.js +++ b/communication/bluetooth_ble/src/main/js/test/BleGattManager.test.js @@ -14,6 +14,11 @@ */ import bluetooth from '@ohos.bluetooth'; +import geolocation from '@ohos.geolocation'; +import geolocationm from '@ohos.geoLocationManager'; +import abilityAccessCtrl from '@ohos.abilityAccessCtrl'; +import bundle from '@ohos.bundle'; +import osaccount from '@ohos.account.osAccount'; import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' export default function bluetoothBLETest() { @@ -30,7 +35,7 @@ describe('bluetoothBLETest', function() { case 0: console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta)); bluetooth.enableBluetooth(); - await sleep(3000); + await sleep(10000); break; case 1: console.info('[bluetooth_js] bt turning on:'+ JSON.stringify(sta)); @@ -42,12 +47,38 @@ describe('bluetoothBLETest', function() { case 3: console.info('[bluetooth_js] bt turning off:'+ JSON.stringify(sta)); bluetooth.enableBluetooth(); - await sleep(3000); + await sleep(1000); break; default: console.info('[bluetooth_js] enable success'); } } + async function applyPermission() { + let osAccountManager = osaccount.getAccountManager(); + console.info("=== getAccountManager finish"); + let localId = await osAccountManager.getOsAccountLocalIdFromProcess(); + console.info("LocalId is :" + localId); + let appInfo = await bundle.getApplicationInfo('ohos.acts.location.geolocation.function', 0, localId); + let atManager = abilityAccessCtrl.createAtManager(); + if (atManager != null) { + let tokenID = appInfo.accessTokenId; + console.info('[permission] case accessTokenID is ' + tokenID); + let permissionName1 = 'ohos.permission.LOCATION'; + let permissionName2 = 'ohos.permission.LOCATION_IN_BACKGROUND'; + await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); + }); + await atManager.grantUserGrantedPermission(tokenID, permissionName2, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); + }); + } else { + console.info('[permission] case apply permission failed, createAtManager failed'); + } + } beforeAll(function () { console.info('beforeAll called') gattServer = bluetooth.BLE.createGattServer(); diff --git a/communication/bluetooth_ble/src/main/js/test/BleService.test.js b/communication/bluetooth_ble/src/main/js/test/BleService.test.js index b8360840c10b2b68935d0d340363a9123e27ed40..50cd72c51b77f5e76264c197342394aa5c2b388f 100644 --- a/communication/bluetooth_ble/src/main/js/test/BleService.test.js +++ b/communication/bluetooth_ble/src/main/js/test/BleService.test.js @@ -14,6 +14,11 @@ */ import bluetooth from '@ohos.bluetooth'; +import geolocation from '@ohos.geolocation'; +import geolocationm from '@ohos.geoLocationManager'; +import abilityAccessCtrl from '@ohos.abilityAccessCtrl'; +import bundle from '@ohos.bundle'; +import osaccount from '@ohos.account.osAccount'; import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' export default function bluetoothBLETest1() { @@ -31,7 +36,7 @@ describe('bluetoothBLETest1', function() { case 0: console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta)); bluetooth.enableBluetooth(); - await sleep(3000); + await sleep(10000); break; case 1: console.info('[bluetooth_js] bt turning on:'+ JSON.stringify(sta)); @@ -43,12 +48,38 @@ describe('bluetoothBLETest1', function() { case 3: console.info('[bluetooth_js] bt turning off:'+ JSON.stringify(sta)); bluetooth.enableBluetooth(); - await sleep(3000); + await sleep(10000); break; default: console.info('[bluetooth_js] enable success'); } } + async function applyPermission() { + let osAccountManager = osaccount.getAccountManager(); + console.info("=== getAccountManager finish"); + let localId = await osAccountManager.getOsAccountLocalIdFromProcess(); + console.info("LocalId is :" + localId); + let appInfo = await bundle.getApplicationInfo('ohos.acts.location.geolocation.function', 0, localId); + let atManager = abilityAccessCtrl.createAtManager(); + if (atManager != null) { + let tokenID = appInfo.accessTokenId; + console.info('[permission] case accessTokenID is ' + tokenID); + let permissionName1 = 'ohos.permission.LOCATION'; + let permissionName2 = 'ohos.permission.LOCATION_IN_BACKGROUND'; + await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); + }); + await atManager.grantUserGrantedPermission(tokenID, permissionName2, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); + }); + } else { + console.info('[permission] case apply permission failed, createAtManager failed'); + } + } beforeAll(function () { console.info('beforeAll called') gattServer = bluetooth.BLE.createGattServer(); diff --git a/communication/bluetooth_manager/src/main/js/test/BleAdvertiser.test.js b/communication/bluetooth_manager/src/main/js/test/BleAdvertiser.test.js index 71ea19e33ef3e3788abc4c999034df05ceaca177..78f8fa93fe87cd15ce190bda595757159f9e7299 100644 --- a/communication/bluetooth_manager/src/main/js/test/BleAdvertiser.test.js +++ b/communication/bluetooth_manager/src/main/js/test/BleAdvertiser.test.js @@ -15,6 +15,11 @@ */ import bluetooth from '@ohos.bluetoothManager'; +import geolocation from '@ohos.geolocation'; +import geolocationm from '@ohos.geoLocationManager'; +import abilityAccessCtrl from '@ohos.abilityAccessCtrl'; +import bundle from '@ohos.bundle'; +import osaccount from '@ohos.account.osAccount'; import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' @@ -31,7 +36,7 @@ describe('bluetoothBLETest2', function() { case 0: console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta)); bluetooth.enableBluetooth(); - await sleep(3000); + await sleep(10000); break; case 1: console.info('[bluetooth_js] bt turning on:'+ JSON.stringify(sta)); @@ -43,12 +48,38 @@ describe('bluetoothBLETest2', function() { case 3: console.info('[bluetooth_js] bt turning off:'+ JSON.stringify(sta)); bluetooth.enableBluetooth(); - await sleep(3000); + await sleep(10000); break; default: console.info('[bluetooth_js] enable success'); } } + async function applyPermission() { + let osAccountManager = osaccount.getAccountManager(); + console.info("=== getAccountManager finish"); + let localId = await osAccountManager.getOsAccountLocalIdFromProcess(); + console.info("LocalId is :" + localId); + let appInfo = await bundle.getApplicationInfo('ohos.acts.location.geolocation.function', 0, localId); + let atManager = abilityAccessCtrl.createAtManager(); + if (atManager != null) { + let tokenID = appInfo.accessTokenId; + console.info('[permission] case accessTokenID is ' + tokenID); + let permissionName1 = 'ohos.permission.LOCATION'; + let permissionName2 = 'ohos.permission.LOCATION_IN_BACKGROUND'; + await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); + }); + await atManager.grantUserGrantedPermission(tokenID, permissionName2, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); + }); + } else { + console.info('[permission] case apply permission failed, createAtManager failed'); + } + } beforeAll(async function (done) { console.info('beforeAll called') await tryToEnableBt() diff --git a/communication/bluetooth_manager/src/main/js/test/BleAdvertiser401.test.js b/communication/bluetooth_manager/src/main/js/test/BleAdvertiser401.test.js index e770c8ff82b68bbaa1a2c02511b3338974708d04..264422a7a2afb3275b2a35c7d9a79c414b118b00 100644 --- a/communication/bluetooth_manager/src/main/js/test/BleAdvertiser401.test.js +++ b/communication/bluetooth_manager/src/main/js/test/BleAdvertiser401.test.js @@ -16,6 +16,11 @@ //import bluetooth from '@ohos.bluetooth'; import bluetooth from '@ohos.bluetoothManager'; +import geolocation from '@ohos.geolocation'; +import geolocationm from '@ohos.geoLocationManager'; +import abilityAccessCtrl from '@ohos.abilityAccessCtrl'; +import bundle from '@ohos.bundle'; +import osaccount from '@ohos.account.osAccount'; import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' @@ -32,7 +37,7 @@ describe('bluetoothBLETest5', function() { case 0: console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta)); bluetooth.enableBluetooth(); - await sleep(3000); + await sleep(10000); break; case 1: console.info('[bluetooth_js] bt turning on:'+ JSON.stringify(sta)); @@ -44,12 +49,38 @@ describe('bluetoothBLETest5', function() { case 3: console.info('[bluetooth_js] bt turning off:'+ JSON.stringify(sta)); bluetooth.enableBluetooth(); - await sleep(3000); + await sleep(10000); break; default: console.info('[bluetooth_js] enable success'); } } + async function applyPermission() { + let osAccountManager = osaccount.getAccountManager(); + console.info("=== getAccountManager finish"); + let localId = await osAccountManager.getOsAccountLocalIdFromProcess(); + console.info("LocalId is :" + localId); + let appInfo = await bundle.getApplicationInfo('ohos.acts.location.geolocation.function', 0, localId); + let atManager = abilityAccessCtrl.createAtManager(); + if (atManager != null) { + let tokenID = appInfo.accessTokenId; + console.info('[permission] case accessTokenID is ' + tokenID); + let permissionName1 = 'ohos.permission.LOCATION'; + let permissionName2 = 'ohos.permission.LOCATION_IN_BACKGROUND'; + await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); + }); + await atManager.grantUserGrantedPermission(tokenID, permissionName2, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); + }); + } else { + console.info('[permission] case apply permission failed, createAtManager failed'); + } + } beforeAll(async function (done) { console.info('beforeAll called') await tryToEnableBt() diff --git a/communication/bluetooth_manager/src/main/js/test/BleGattManager.test.js b/communication/bluetooth_manager/src/main/js/test/BleGattManager.test.js index 5a86892e054d0f73073642947acd4d29347cac8a..b9c48a0c630bb42a14299fc8ca2154c8f6695d94 100644 --- a/communication/bluetooth_manager/src/main/js/test/BleGattManager.test.js +++ b/communication/bluetooth_manager/src/main/js/test/BleGattManager.test.js @@ -14,6 +14,11 @@ */ import bluetooth from '@ohos.bluetoothManager'; +import geolocation from '@ohos.geolocation'; +import geolocationm from '@ohos.geoLocationManager'; +import abilityAccessCtrl from '@ohos.abilityAccessCtrl'; +import bundle from '@ohos.bundle'; +import osaccount from '@ohos.account.osAccount'; import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' export default function bluetoothBLETest() { @@ -30,7 +35,7 @@ describe('bluetoothBLETest', function() { case 0: console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta)); bluetooth.enableBluetooth(); - await sleep(3000); + await sleep(10000); break; case 1: console.info('[bluetooth_js] bt turning on:'+ JSON.stringify(sta)); @@ -42,12 +47,38 @@ describe('bluetoothBLETest', function() { case 3: console.info('[bluetooth_js] bt turning off:'+ JSON.stringify(sta)); bluetooth.enableBluetooth(); - await sleep(3000); + await sleep(10000); break; default: console.info('[bluetooth_js] enable success'); } } + async function applyPermission() { + let osAccountManager = osaccount.getAccountManager(); + console.info("=== getAccountManager finish"); + let localId = await osAccountManager.getOsAccountLocalIdFromProcess(); + console.info("LocalId is :" + localId); + let appInfo = await bundle.getApplicationInfo('ohos.acts.location.geolocation.function', 0, localId); + let atManager = abilityAccessCtrl.createAtManager(); + if (atManager != null) { + let tokenID = appInfo.accessTokenId; + console.info('[permission] case accessTokenID is ' + tokenID); + let permissionName1 = 'ohos.permission.LOCATION'; + let permissionName2 = 'ohos.permission.LOCATION_IN_BACKGROUND'; + await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); + }); + await atManager.grantUserGrantedPermission(tokenID, permissionName2, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); + }); + } else { + console.info('[permission] case apply permission failed, createAtManager failed'); + } + } beforeAll(function () { console.info('beforeAll called') gattServer = bluetooth.BLE.createGattServer(); diff --git a/communication/bluetooth_manager/src/main/js/test/BleGattManager401.test.js b/communication/bluetooth_manager/src/main/js/test/BleGattManager401.test.js index ed7b5f7c00cd6c65d009b89d644994a864bf8e25..089b48922dc725c3c4d633d531dd689d24e07558 100644 --- a/communication/bluetooth_manager/src/main/js/test/BleGattManager401.test.js +++ b/communication/bluetooth_manager/src/main/js/test/BleGattManager401.test.js @@ -15,6 +15,11 @@ //import bluetooth from '@ohos.bluetooth'; import bluetooth from '@ohos.bluetoothManager'; +import geolocation from '@ohos.geolocation'; +import geolocationm from '@ohos.geoLocationManager'; +import abilityAccessCtrl from '@ohos.abilityAccessCtrl'; +import bundle from '@ohos.bundle'; +import osaccount from '@ohos.account.osAccount'; import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' export default function bluetoothBLETest4() { @@ -30,7 +35,7 @@ describe('bluetoothBLETest4', function() { case 0: console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta)); bluetooth.enableBluetooth(); - await sleep(3000); + await sleep(10000); break; case 1: console.info('[bluetooth_js] bt turning on:'+ JSON.stringify(sta)); @@ -42,12 +47,38 @@ describe('bluetoothBLETest4', function() { case 3: console.info('[bluetooth_js] bt turning off:'+ JSON.stringify(sta)); bluetooth.enableBluetooth(); - await sleep(3000); + await sleep(10000); break; default: console.info('[bluetooth_js] enable success'); } } + async function applyPermission() { + let osAccountManager = osaccount.getAccountManager(); + console.info("=== getAccountManager finish"); + let localId = await osAccountManager.getOsAccountLocalIdFromProcess(); + console.info("LocalId is :" + localId); + let appInfo = await bundle.getApplicationInfo('ohos.acts.location.geolocation.function', 0, localId); + let atManager = abilityAccessCtrl.createAtManager(); + if (atManager != null) { + let tokenID = appInfo.accessTokenId; + console.info('[permission] case accessTokenID is ' + tokenID); + let permissionName1 = 'ohos.permission.LOCATION'; + let permissionName2 = 'ohos.permission.LOCATION_IN_BACKGROUND'; + await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); + }); + await atManager.grantUserGrantedPermission(tokenID, permissionName2, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); + }); + } else { + console.info('[permission] case apply permission failed, createAtManager failed'); + } + } beforeAll(function () { console.info('beforeAll called') gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); diff --git a/communication/bluetooth_manager/src/main/js/test/BleScanResult.test.js b/communication/bluetooth_manager/src/main/js/test/BleScanResult.test.js index 066aae03fdea8dd8500f2f626b5ebe02ead29f2c..9c657379a1952190abc08eb77d1834b367335f88 100644 --- a/communication/bluetooth_manager/src/main/js/test/BleScanResult.test.js +++ b/communication/bluetooth_manager/src/main/js/test/BleScanResult.test.js @@ -14,6 +14,11 @@ */ import bluetooth from '@ohos.bluetoothManager'; +import geolocation from '@ohos.geolocation'; +import geolocationm from '@ohos.geoLocationManager'; +import abilityAccessCtrl from '@ohos.abilityAccessCtrl'; +import bundle from '@ohos.bundle'; +import osaccount from '@ohos.account.osAccount'; import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' export default function bluetoothBLETest6() { @@ -27,7 +32,7 @@ describe('bluetoothBLETest6', function() { switch(sta){ case 0: bluetooth.enableBluetooth(); - await sleep(5000); + await sleep(10000); let sta1 = bluetooth.getState(); console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta1)); break; @@ -40,7 +45,7 @@ describe('bluetoothBLETest6', function() { break; case 3: bluetooth.enableBluetooth(); - await sleep(3000); + await sleep(10000); let sta2 = bluetooth.getState(); console.info('[bluetooth_js] bt turning off:'+ JSON.stringify(sta2)); break; @@ -48,6 +53,32 @@ describe('bluetoothBLETest6', function() { console.info('[bluetooth_js] enable success'); } } + async function applyPermission() { + let osAccountManager = osaccount.getAccountManager(); + console.info("=== getAccountManager finish"); + let localId = await osAccountManager.getOsAccountLocalIdFromProcess(); + console.info("LocalId is :" + localId); + let appInfo = await bundle.getApplicationInfo('ohos.acts.location.geolocation.function', 0, localId); + let atManager = abilityAccessCtrl.createAtManager(); + if (atManager != null) { + let tokenID = appInfo.accessTokenId; + console.info('[permission] case accessTokenID is ' + tokenID); + let permissionName1 = 'ohos.permission.LOCATION'; + let permissionName2 = 'ohos.permission.LOCATION_IN_BACKGROUND'; + await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); + }); + await atManager.grantUserGrantedPermission(tokenID, permissionName2, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); + }); + } else { + console.info('[permission] case apply permission failed, createAtManager failed'); + } + } beforeAll(function () { console.info('beforeAll called') }) diff --git a/communication/bluetooth_manager/src/main/js/test/BleService.test.js b/communication/bluetooth_manager/src/main/js/test/BleService.test.js index 42c8d5d41df0ce2b14319cb65d3ddfdce825d783..fc42fa8591fd9ea9ad02eb884bf6649e43d96381 100644 --- a/communication/bluetooth_manager/src/main/js/test/BleService.test.js +++ b/communication/bluetooth_manager/src/main/js/test/BleService.test.js @@ -14,8 +14,88 @@ */ import bluetooth from '@ohos.bluetoothManager'; +import geolocation from '@ohos.geolocation'; +import geolocationm from '@ohos.geoLocationManager'; +import abilityAccessCtrl from '@ohos.abilityAccessCtrl'; +import bundle from '@ohos.bundle'; +import osaccount from '@ohos.account.osAccount'; import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' +let BluetoothState = { + STATE_OFF: 0,STATE_TURNING_ON: 1, + STATE_ON: 2,STATE_TURNING_OFF: 3, + STATE_BLE_TURNING_ON: 4, STATE_BLE_ON: 5, + STATE_BLE_ON: 6 +}; + +let SppOption = {uuid: '00001810-0000-1000-8000-00805F9B34FB', + secure: true, type: bluetooth.SppType.SPP_RFCOMM}; + +let MajorMinorClass = { + COMPUTER_UNCATEGORIZED : 0x0100,COMPUTER_DESKTOP : 0x0104, + COMPUTER_SERVER : 0x0108,COMPUTER_LAPTOP : 0x010C, + COMPUTER_HANDHELD_PC_PDA : 0x0110,COMPUTER_PALM_SIZE_PC_PDA : 0x0114, + COMPUTER_WEARABLE : 0x0118,COMPUTER_TABLET : 0x011C, + PHONE_UNCATEGORIZED : 0x0200,PHONE_CELLULAR : 0x0204, + PHONE_CORDLESS : 0x0208,PHONE_SMART : 0x020C, + PHONE_MODEM_OR_GATEWAY : 0x0210,PHONE_ISDN : 0x0214, + NETWORK_FULLY_AVAILABLE : 0x0300,NETWORK_1_TO_17_UTILIZED : 0x0320, + NETWORK_17_TO_33_UTILIZED : 0x0340,NETWORK_33_TO_50_UTILIZED : 0x0360, + NETWORK_60_TO_67_UTILIZED : 0x0380,NETWORK_67_TO_83_UTILIZED : 0x03A0, + NETWORK_83_TO_99_UTILIZED : 0x03C0,NETWORK_NO_SERVICE : 0x03E0, + AUDIO_VIDEO_UNCATEGORIZED : 0x0400,AUDIO_VIDEO_WEARABLE_HEADSET: 0x0404, + AUDIO_VIDEO_HANDSFREE : 0x0408,AUDIO_VIDEO_MICROPHONE : 0x0410, + AUDIO_VIDEO_LOUDSPEAKER : 0x0414,AUDIO_VIDEO_HEADPHONES : 0x0418, + AUDIO_VIDEO_PORTABLE_AUDIO : 0x041C,AUDIO_VIDEO_CAR_AUDIO : 0x0420, + AUDIO_VIDEO_SET_TOP_BOX : 0x0424,AUDIO_VIDEO_HIFI_AUDIO : 0x0428, + AUDIO_VIDEO_VCR : 0x042C,AUDIO_VIDEO_VIDEO_CAMERA : 0x0430, + AUDIO_VIDEO_CAMCORDER : 0x0434,AUDIO_VIDEO_VIDEO_MONITOR : 0x0438, + AUDIO_VIDEO_VIDEO_DISPLAY_AND_LOUDSPEAKER : 0x043C, + AUDIO_VIDEO_VIDEO_CONFERENCING : 0x0440,AUDIO_VIDEO_VIDEO_GAMING_TOY: 0x0448, + PERIPHERAL_NON_KEYBOARD_NON_POINTING : 0x0500, + PERIPHERAL_KEYBOARD : 0x0540,PERIPHERAL_POINTING_DEVICE : 0x0580, + PERIPHERAL_KEYBOARD_POINTING : 0x05C0,PERIPHERAL_UNCATEGORIZED : 0x0500, + PERIPHERAL_JOYSTICK : 0x0504,PERIPHERAL_GAMEPAD : 0x0508, + PERIPHERAL_REMOTE_CONTROL : 0x05C0,PERIPHERAL_SENSING_DEVICE : 0x0510, + PERIPHERAL_DIGITIZER_TABLET : 0x0514, + PERIPHERAL_CARD_READER : 0x0518,PERIPHERAL_DIGITAL_PEN : 0x051C, + PERIPHERAL_SCANNER_RFID : 0x0520,PERIPHERAL_GESTURAL_INPUT : 0x0522, + IMAGING_UNCATEGORIZED : 0x0600,IMAGING_DISPLAY : 0x0610, + IMAGING_CAMERA : 0x0620,IMAGING_SCANNER : 0x0640, + IMAGING_PRINTER : 0x0680,WEARABLE_UNCATEGORIZED : 0x0700, + WEARABLE_WRIST_WATCH : 0x0704,WEARABLE_PAGER : 0x0708, + WEARABLE_JACKET : 0x070C,WEARABLE_HELMET : 0x0710, + WEARABLE_GLASSES : 0x0714,TOY_UNCATEGORIZED : 0x0800, + TOY_ROBOT : 0x0804,TOY_VEHICLE : 0x0808, + TOY_DOLL_ACTION_FIGURE : 0x080C,TOY_CONTROLLER : 0x0810, + TOY_GAME : 0x0814,HEALTH_UNCATEGORIZED : 0x0900, + HEALTH_BLOOD_PRESSURE : 0x0904,HEALTH_THERMOMETER : 0x0908, + HEALTH_WEIGHING : 0x090C,HEALTH_GLUCOSE : 0x0910, + HEALTH_PULSE_OXIMETER : 0x0914,HEALTH_PULSE_RATE : 0x0918, + HEALTH_DATA_DISPLAY : 0x091C,HEALTH_STEP_COUNTER : 0x0920, + HEALTH_BODY_COMPOSITION_ANALYZER : 0x0924, + HEALTH_PEAK_FLOW_MOITOR : 0x0928,HEALTH_MEDICATION_MONITOR : 0x092C, + HEALTH_KNEE_PROSTHESIS : 0x0930,HEALTH_ANKLE_PROSTHESIS : 0x0934, + HEALTH_GENERIC_HEALTH_MANAGER : 0x0938, + HEALTH_PERSONAL_MOBILITY_DEVICE : 0x093C, + HEALTH_PERSONAL_MOBILITY_DEVICE : 0x093C +}; +let MajorClass = { + MAJOR_MISC : 0x0000,MAJOR_COMPUTER : 0x0100, + MAJOR_PHONE : 0x0200,MAJOR_NETWORKING : 0x0300, + MAJOR_AUDIO_VIDEO: 0x0400,MAJOR_PERIPHERAL : 0x0500, + MAJOR_IMAGING : 0x0600,MAJOR_WEARABLE : 0x0700, + MAJOR_TOY : 0x0800,MAJOR_HEALTH : 0x0900, + MAJOR_UNCATEGORIZED : 0x1F00 +}; + +let ProfileId = { + PROFILE_A2DP_SOURCE: 1, + PROFILE_HANDS_FREE_AUDIO_GATEWAY: 4, + PROFILE_HID_HOST: 6, + PROFILE_PAN_NETWORK: 7 +}; + export default function bluetoothBLETest1() { describe('bluetoothBLETest1', function() { @@ -31,7 +111,7 @@ describe('bluetoothBLETest1', function() { case 0: console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta)); bluetooth.enableBluetooth(); - await sleep(3000); + await sleep(10000); break; case 1: console.info('[bluetooth_js] bt turning on:'+ JSON.stringify(sta)); @@ -43,12 +123,38 @@ describe('bluetoothBLETest1', function() { case 3: console.info('[bluetooth_js] bt turning off:'+ JSON.stringify(sta)); bluetooth.enableBluetooth(); - await sleep(3000); + await sleep(10000); break; default: console.info('[bluetooth_js] enable success'); } } + async function applyPermission() { + let osAccountManager = osaccount.getAccountManager(); + console.info("=== getAccountManager finish"); + let localId = await osAccountManager.getOsAccountLocalIdFromProcess(); + console.info("LocalId is :" + localId); + let appInfo = await bundle.getApplicationInfo('ohos.acts.location.geolocation.function', 0, localId); + let atManager = abilityAccessCtrl.createAtManager(); + if (atManager != null) { + let tokenID = appInfo.accessTokenId; + console.info('[permission] case accessTokenID is ' + tokenID); + let permissionName1 = 'ohos.permission.LOCATION'; + let permissionName2 = 'ohos.permission.LOCATION_IN_BACKGROUND'; + await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); + }); + await atManager.grantUserGrantedPermission(tokenID, permissionName2, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); + }); + } else { + console.info('[permission] case apply permission failed, createAtManager failed'); + } + } beforeAll(async function (done) { console.info('beforeAll called') await tryToEnableBt() diff --git a/communication/bluetooth_manager/src/main/js/test/SwitchOff003.test.js b/communication/bluetooth_manager/src/main/js/test/SwitchOff003.test.js index 6b4f16aa757c8f743b075da357f3bf0aa594348c..0bb3bdf7ab93824349cb835495cca64fd872d040 100644 --- a/communication/bluetooth_manager/src/main/js/test/SwitchOff003.test.js +++ b/communication/bluetooth_manager/src/main/js/test/SwitchOff003.test.js @@ -14,6 +14,11 @@ */ import bluetooth from '@ohos.bluetoothManager'; +import geolocation from '@ohos.geolocation'; +import geolocationm from '@ohos.geoLocationManager'; +import abilityAccessCtrl from '@ohos.abilityAccessCtrl'; +import bundle from '@ohos.bundle'; +import osaccount from '@ohos.account.osAccount'; import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' export default function bluetoothBLETest3() { @@ -46,6 +51,32 @@ describe('bluetoothBLETest3', function() { console.info('[bluetooth_js] enable success'); } } + async function applyPermission() { + let osAccountManager = osaccount.getAccountManager(); + console.info("=== getAccountManager finish"); + let localId = await osAccountManager.getOsAccountLocalIdFromProcess(); + console.info("LocalId is :" + localId); + let appInfo = await bundle.getApplicationInfo('ohos.acts.location.geolocation.function', 0, localId); + let atManager = abilityAccessCtrl.createAtManager(); + if (atManager != null) { + let tokenID = appInfo.accessTokenId; + console.info('[permission] case accessTokenID is ' + tokenID); + let permissionName1 = 'ohos.permission.LOCATION'; + let permissionName2 = 'ohos.permission.LOCATION_IN_BACKGROUND'; + await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); + }); + await atManager.grantUserGrantedPermission(tokenID, permissionName2, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); + }); + } else { + console.info('[permission] case apply permission failed, createAtManager failed'); + } + } beforeAll(function () { console.info('beforeAll called') gattServer = bluetooth.BLE.createGattServer(); @@ -198,12 +229,12 @@ describe('bluetoothBLETest3', function() { */ it('COMMUNICATION_BLUETOOTH_SwitchOff_0600', 0, async function (done) { try { - let a2dpSrcConn = bluetooth.getProfileConnState(bluetooth.ProfileId.PROFILE_A2DP_SOURCE); + let a2dpSrcConn = bluetooth.getProfileConnectionState(bluetooth.ProfileId.PROFILE_A2DP_SOURCE); console.info('[bluetooth_js]get a2dp result:' + JSON.stringify(a2dpSrcConn)); expect(true).assertFalse(); done() } catch (error) { - console.error('[bluetooth_js]getProfileConnState error.code:'+JSON.stringify(error.code)+ + console.error('[bluetooth_js]getProfileConnectionState error.code:'+JSON.stringify(error.code)+ 'error.message:'+JSON.stringify(error.message)); expect(error.code).assertEqual('2900003'); done() @@ -355,7 +386,7 @@ describe('bluetoothBLETest3', function() { */ it('COMMUNICATION_BLUETOOTH_SwitchOff_1600', 0, async function (done) { try { - let hfpSrc = bluetooth.getProfileInst(bluetooth.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY); + let hfpSrc = bluetooth.getProfileInstance(bluetooth.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY); let retArray = hfpSrc.getConnectionDevices(); console.info('[bluetooth_js]hfp getConnectionDevices:' + JSON.stringify(retArray)); expect(true).assertFalse(); @@ -571,7 +602,7 @@ describe('bluetoothBLETest3', function() { */ it('COMMUNICATION_BLUETOOTH_SwitchOff_2500', 0, async function (done) { try { - let panSrc = + let panSrc = bluetooth.getProfileInst(bluetooth.ProfileId.PROFILE_PAN_NETWORK); panSrc.disconnect('11:22:33:44:55:77'); expect(true).assertFalse(); @@ -595,7 +626,7 @@ describe('bluetoothBLETest3', function() { */ it('COMMUNICATION_BLUETOOTH_SwitchOff_2600', 0, async function (done) { try { - let panSrc = + let panSrc = bluetooth.getProfileInst(bluetooth.ProfileId.PROFILE_PAN_NETWORK); panSrc.setTethering(true); expect(true).assertFalse(); @@ -957,7 +988,7 @@ describe('bluetoothBLETest3', function() { * @tc.level Level 2 */ it('COMMUNICATION_BLUETOOTH_SwitchOff_4000', 0, async function (done) { - + try { bluetooth.cancelPairedDevice("11:22:55:66:33:44"); expect(true).assertFalse(); @@ -967,7 +998,7 @@ describe('bluetoothBLETest3', function() { 'error.message:'+JSON.stringify(error.message)); expect(error.code).assertEqual('2900003'); done() - } + } }) }) diff --git a/communication/bluetooth_on/src/main/js/test/BleScanResult.test.js b/communication/bluetooth_on/src/main/js/test/BleScanResult.test.js index 11ec404d23b084b966f4f8a3da25f32804d55e8c..b96f3a1b4cac34c350b489692caf851baee7b501 100644 --- a/communication/bluetooth_on/src/main/js/test/BleScanResult.test.js +++ b/communication/bluetooth_on/src/main/js/test/BleScanResult.test.js @@ -14,6 +14,11 @@ */ import bluetooth from '@ohos.bluetooth'; +import geolocation from '@ohos.geolocation'; +import geolocationm from '@ohos.geoLocationManager'; +import abilityAccessCtrl from '@ohos.abilityAccessCtrl'; +import bundle from '@ohos.bundle'; +import osaccount from '@ohos.account.osAccount'; import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' export default function bluetoothhostTest() { @@ -27,7 +32,7 @@ describe('bluetoothhostTest', function() { switch(sta){ case 0: bluetooth.enableBluetooth(); - await sleep(5000); + await sleep(10000); let sta1 = bluetooth.getState(); console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta1)); break; @@ -40,7 +45,7 @@ describe('bluetoothhostTest', function() { break; case 3: bluetooth.enableBluetooth(); - await sleep(3000); + await sleep(10000); let sta2 = bluetooth.getState(); console.info('[bluetooth_js] bt turning off:'+ JSON.stringify(sta2)); break; @@ -48,6 +53,32 @@ describe('bluetoothhostTest', function() { console.info('[bluetooth_js] enable success'); } } + async function applyPermission() { + let osAccountManager = osaccount.getAccountManager(); + console.info("=== getAccountManager finish"); + let localId = await osAccountManager.getOsAccountLocalIdFromProcess(); + console.info("LocalId is :" + localId); + let appInfo = await bundle.getApplicationInfo('ohos.acts.location.geolocation.function', 0, localId); + let atManager = abilityAccessCtrl.createAtManager(); + if (atManager != null) { + let tokenID = appInfo.accessTokenId; + console.info('[permission] case accessTokenID is ' + tokenID); + let permissionName1 = 'ohos.permission.LOCATION'; + let permissionName2 = 'ohos.permission.LOCATION_IN_BACKGROUND'; + await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); + }); + await atManager.grantUserGrantedPermission(tokenID, permissionName2, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); + }); + } else { + console.info('[permission] case apply permission failed, createAtManager failed'); + } + } beforeAll(function () { console.info('beforeAll called') }) diff --git a/communication/bluetooth_on/src/main/js/test/BluetoothPair.test.js b/communication/bluetooth_on/src/main/js/test/BluetoothPair.test.js index 0af005c4d0636c400480a70b1b1405a7ea9e3bfb..21d80d82ad6c31da7ad6bd6a194db6b05ab302ed 100644 --- a/communication/bluetooth_on/src/main/js/test/BluetoothPair.test.js +++ b/communication/bluetooth_on/src/main/js/test/BluetoothPair.test.js @@ -14,6 +14,11 @@ */ import bluetooth from '@ohos.bluetooth'; +import geolocation from '@ohos.geolocation'; +import geolocationm from '@ohos.geoLocationManager'; +import abilityAccessCtrl from '@ohos.abilityAccessCtrl'; +import bundle from '@ohos.bundle'; +import osaccount from '@ohos.account.osAccount'; import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' @@ -28,7 +33,7 @@ describe('bluetoothhostTest2', function() { switch(sta){ case 0: bluetooth.enableBluetooth(); - await sleep(5000); + await sleep(10000); let sta1 = bluetooth.getState(); console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta1)); break; @@ -41,7 +46,7 @@ describe('bluetoothhostTest2', function() { break; case 3: bluetooth.enableBluetooth(); - await sleep(3000); + await sleep(10000); let sta2 = bluetooth.getState(); console.info('[bluetooth_js] bt turning off:'+ JSON.stringify(sta2)); break; @@ -49,6 +54,32 @@ describe('bluetoothhostTest2', function() { console.info('[bluetooth_js] enable success'); } } + async function applyPermission() { + let osAccountManager = osaccount.getAccountManager(); + console.info("=== getAccountManager finish"); + let localId = await osAccountManager.getOsAccountLocalIdFromProcess(); + console.info("LocalId is :" + localId); + let appInfo = await bundle.getApplicationInfo('ohos.acts.location.geolocation.function', 0, localId); + let atManager = abilityAccessCtrl.createAtManager(); + if (atManager != null) { + let tokenID = appInfo.accessTokenId; + console.info('[permission] case accessTokenID is ' + tokenID); + let permissionName1 = 'ohos.permission.LOCATION'; + let permissionName2 = 'ohos.permission.LOCATION_IN_BACKGROUND'; + await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); + }); + await atManager.grantUserGrantedPermission(tokenID, permissionName2, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); + }); + } else { + console.info('[permission] case apply permission failed, createAtManager failed'); + } + } beforeAll(function () { console.info('beforeAll called') }) diff --git a/communication/bluetooth_on/src/main/js/test/bluetoothSys.test.js b/communication/bluetooth_on/src/main/js/test/bluetoothSys.test.js index 49d8f375290b02a1a7a3b4ceb9d9373ccec59076..b32d06376e8bf2bb2af04f0807547e48ea2baa87 100644 --- a/communication/bluetooth_on/src/main/js/test/bluetoothSys.test.js +++ b/communication/bluetooth_on/src/main/js/test/bluetoothSys.test.js @@ -15,6 +15,11 @@ import bluetooth from '@ohos.bluetooth'; import bluetoothsys from '@system.bluetooth'; +import geolocation from '@ohos.geolocation'; +import geolocationm from '@ohos.geoLocationManager'; +import abilityAccessCtrl from '@ohos.abilityAccessCtrl'; +import bundle from '@ohos.bundle'; +import osaccount from '@ohos.account.osAccount'; import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' export default function bluetoothhostTest4() { @@ -28,7 +33,7 @@ describe('bluetoothhostTest4', function() { switch(sta){ case 0: bluetooth.enableBluetooth(); - await sleep(5000); + await sleep(10000); let sta1 = bluetooth.getState(); console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta1)); break; @@ -41,7 +46,7 @@ describe('bluetoothhostTest4', function() { break; case 3: bluetooth.enableBluetooth(); - await sleep(3000); + await sleep(10000); let sta2 = bluetooth.getState(); console.info('[bluetooth_js] bt turning off:'+ JSON.stringify(sta2)); break; @@ -49,6 +54,32 @@ describe('bluetoothhostTest4', function() { console.info('[bluetooth_js] enable success'); } } + async function applyPermission() { + let osAccountManager = osaccount.getAccountManager(); + console.info("=== getAccountManager finish"); + let localId = await osAccountManager.getOsAccountLocalIdFromProcess(); + console.info("LocalId is :" + localId); + let appInfo = await bundle.getApplicationInfo('ohos.acts.location.geolocation.function', 0, localId); + let atManager = abilityAccessCtrl.createAtManager(); + if (atManager != null) { + let tokenID = appInfo.accessTokenId; + console.info('[permission] case accessTokenID is ' + tokenID); + let permissionName1 = 'ohos.permission.LOCATION'; + let permissionName2 = 'ohos.permission.LOCATION_IN_BACKGROUND'; + await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); + }); + await atManager.grantUserGrantedPermission(tokenID, permissionName2, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); + }); + } else { + console.info('[permission] case apply permission failed, createAtManager failed'); + } + } beforeAll(function () { console.info('beforeAll called') }) diff --git a/communication/bluetooth_profile/src/main/js/test/BluetoothA2dp.test.js b/communication/bluetooth_profile/src/main/js/test/BluetoothA2dp.test.js index c4b8f2e62203cb0c507de07d7b341dfe86b3ccac..84ece3d748fba764dc9051aaebab8dcc07886e56 100644 --- a/communication/bluetooth_profile/src/main/js/test/BluetoothA2dp.test.js +++ b/communication/bluetooth_profile/src/main/js/test/BluetoothA2dp.test.js @@ -14,8 +14,19 @@ */ import bluetooth from '@ohos.bluetooth'; +import geolocation from '@ohos.geolocation'; +import geolocationm from '@ohos.geoLocationManager'; +import abilityAccessCtrl from '@ohos.abilityAccessCtrl'; +import bundle from '@ohos.bundle'; +import osaccount from '@ohos.account.osAccount'; import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' +let ProfileId = { + PROFILE_A2DP_SOURCE: 1, + PROFILE_HANDS_FREE_AUDIO_GATEWAY: 4, + PROFILE_HID_HOST: 6, + PROFILE_PAN_NETWORK: 7 +}; export default function bluetoothhostTest_host_1() { describe('bluetoothhostTest_host_1', function () { @@ -28,7 +39,7 @@ describe('bluetoothhostTest_host_1', function () { switch(sta){ case 0: bluetooth.enableBluetooth(); - await sleep(5000); + await sleep(10000); let sta1 = bluetooth.getState(); console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta1)); break; @@ -41,7 +52,7 @@ describe('bluetoothhostTest_host_1', function () { break; case 3: bluetooth.enableBluetooth(); - await sleep(3000); + await sleep(10000); let sta2 = bluetooth.getState(); console.info('[bluetooth_js] bt turning off:'+ JSON.stringify(sta2)); break; @@ -49,6 +60,32 @@ describe('bluetoothhostTest_host_1', function () { console.info('[bluetooth_js] enable success'); } } + async function applyPermission() { + let osAccountManager = osaccount.getAccountManager(); + console.info("=== getAccountManager finish"); + let localId = await osAccountManager.getOsAccountLocalIdFromProcess(); + console.info("LocalId is :" + localId); + let appInfo = await bundle.getApplicationInfo('ohos.acts.location.geolocation.function', 0, localId); + let atManager = abilityAccessCtrl.createAtManager(); + if (atManager != null) { + let tokenID = appInfo.accessTokenId; + console.info('[permission] case accessTokenID is ' + tokenID); + let permissionName1 = 'ohos.permission.LOCATION'; + let permissionName2 = 'ohos.permission.LOCATION_IN_BACKGROUND'; + await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); + }); + await atManager.grantUserGrantedPermission(tokenID, permissionName2, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); + }); + } else { + console.info('[permission] case apply permission failed, createAtManager failed'); + } + } beforeAll(function () { console.info('beforeAll called') }) diff --git a/communication/bluetooth_profile/src/main/js/test/BluetoothHfp.test.js b/communication/bluetooth_profile/src/main/js/test/BluetoothHfp.test.js index 9a143b55b11af6e26cda2ca5e12c6fa65fe97b53..a299ea9a7eb6a70a4aaf1ce8602d0d085b8d9593 100644 --- a/communication/bluetooth_profile/src/main/js/test/BluetoothHfp.test.js +++ b/communication/bluetooth_profile/src/main/js/test/BluetoothHfp.test.js @@ -14,6 +14,11 @@ */ import bluetooth from '@ohos.bluetooth'; +import geolocation from '@ohos.geolocation'; +import geolocationm from '@ohos.geoLocationManager'; +import abilityAccessCtrl from '@ohos.abilityAccessCtrl'; +import bundle from '@ohos.bundle'; +import osaccount from '@ohos.account.osAccount'; import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' @@ -28,7 +33,7 @@ describe('bluetoothhostTest_host_3', function () { switch(sta){ case 0: bluetooth.enableBluetooth(); - await sleep(5000); + await sleep(10000); let sta1 = bluetooth.getState(); console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta1)); break; @@ -41,7 +46,7 @@ describe('bluetoothhostTest_host_3', function () { break; case 3: bluetooth.enableBluetooth(); - await sleep(3000); + await sleep(10000); let sta2 = bluetooth.getState(); console.info('[bluetooth_js] bt turning off:'+ JSON.stringify(sta2)); break; @@ -49,6 +54,32 @@ describe('bluetoothhostTest_host_3', function () { console.info('[bluetooth_js] enable success'); } } + async function applyPermission() { + let osAccountManager = osaccount.getAccountManager(); + console.info("=== getAccountManager finish"); + let localId = await osAccountManager.getOsAccountLocalIdFromProcess(); + console.info("LocalId is :" + localId); + let appInfo = await bundle.getApplicationInfo('ohos.acts.location.geolocation.function', 0, localId); + let atManager = abilityAccessCtrl.createAtManager(); + if (atManager != null) { + let tokenID = appInfo.accessTokenId; + console.info('[permission] case accessTokenID is ' + tokenID); + let permissionName1 = 'ohos.permission.LOCATION'; + let permissionName2 = 'ohos.permission.LOCATION_IN_BACKGROUND'; + await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); + }); + await atManager.grantUserGrantedPermission(tokenID, permissionName2, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); + }); + } else { + console.info('[permission] case apply permission failed, createAtManager failed'); + } + } beforeAll(function () { console.info('beforeAll called') }) diff --git a/communication/bluetooth_standard/src/main/js/test/BRDiscovery.test.js b/communication/bluetooth_standard/src/main/js/test/BRDiscovery.test.js index 16f8ea8311584ec4ebfdced79b89479b1706821e..b7bbf20b322d924bb068b07b9e22bb8647695e69 100644 --- a/communication/bluetooth_standard/src/main/js/test/BRDiscovery.test.js +++ b/communication/bluetooth_standard/src/main/js/test/BRDiscovery.test.js @@ -14,6 +14,9 @@ */ import bluetooth from '@ohos.bluetooth'; +import geolocation from '@ohos.geolocation'; +import geolocationm from '@ohos.geoLocationManager'; +import osaccount from '@ohos.account.osAccount'; import abilityAccessCtrl from '@ohos.abilityAccessCtrl' import bundle from '@ohos.bundle' import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' @@ -45,7 +48,7 @@ describe('bluetoothhostTest3', function() { switch(sta){ case 0: bluetooth.enableBluetooth(); - await sleep(5000); + await sleep(10000); let sta1 = bluetooth.getState(); console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta1)); break; @@ -58,7 +61,7 @@ describe('bluetoothhostTest3', function() { break; case 3: bluetooth.enableBluetooth(); - await sleep(3000); + await sleep(10000); let sta2 = bluetooth.getState(); console.info('[bluetooth_js] bt turning off:'+ JSON.stringify(sta2)); break; @@ -66,6 +69,32 @@ describe('bluetoothhostTest3', function() { console.info('[bluetooth_js] enable success'); } } + async function applyPermission() { + let osAccountManager = osaccount.getAccountManager(); + console.info("=== getAccountManager finish"); + let localId = await osAccountManager.getOsAccountLocalIdFromProcess(); + console.info("LocalId is :" + localId); + let appInfo = await bundle.getApplicationInfo('ohos.acts.location.geolocation.function', 0, localId); + let atManager = abilityAccessCtrl.createAtManager(); + if (atManager != null) { + let tokenID = appInfo.accessTokenId; + console.info('[permission] case accessTokenID is ' + tokenID); + let permissionName1 = 'ohos.permission.LOCATION'; + let permissionName2 = 'ohos.permission.LOCATION_IN_BACKGROUND'; + await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); + }); + await atManager.grantUserGrantedPermission(tokenID, permissionName2, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); + }); + } else { + console.info('[permission] case apply permission failed, createAtManager failed'); + } + } beforeAll(async function (done) { console.info('beforeAll called') diff --git a/communication/bluetooth_standard/src/main/js/test/BRScanMode.test.js b/communication/bluetooth_standard/src/main/js/test/BRScanMode.test.js index 865597e37e982b3e20d5169d4c081cc0c35a12bd..432d8a1636fa8981e715ab865858154763f6c612 100644 --- a/communication/bluetooth_standard/src/main/js/test/BRScanMode.test.js +++ b/communication/bluetooth_standard/src/main/js/test/BRScanMode.test.js @@ -14,6 +14,11 @@ */ import bluetooth from '@ohos.bluetooth'; +import geolocation from '@ohos.geolocation'; +import geolocationm from '@ohos.geoLocationManager'; +import abilityAccessCtrl from '@ohos.abilityAccessCtrl'; +import bundle from '@ohos.bundle'; +import osaccount from '@ohos.account.osAccount'; import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' export default function bluetoothhostTest2() { @@ -26,7 +31,7 @@ describe('bluetoothhostTest2', function() { switch(sta){ case 0: bluetooth.enableBluetooth(); - await sleep(5000); + await sleep(10000); let sta1 = bluetooth.getState(); console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta1)); break; @@ -39,7 +44,7 @@ describe('bluetoothhostTest2', function() { break; case 3: bluetooth.enableBluetooth(); - await sleep(3000); + await sleep(10000); let sta2 = bluetooth.getState(); console.info('[bluetooth_js] bt turning off:'+ JSON.stringify(sta2)); break; @@ -47,6 +52,32 @@ describe('bluetoothhostTest2', function() { console.info('[bluetooth_js] enable success'); } } + async function applyPermission() { + let osAccountManager = osaccount.getAccountManager(); + console.info("=== getAccountManager finish"); + let localId = await osAccountManager.getOsAccountLocalIdFromProcess(); + console.info("LocalId is :" + localId); + let appInfo = await bundle.getApplicationInfo('ohos.acts.location.geolocation.function', 0, localId); + let atManager = abilityAccessCtrl.createAtManager(); + if (atManager != null) { + let tokenID = appInfo.accessTokenId; + console.info('[permission] case accessTokenID is ' + tokenID); + let permissionName1 = 'ohos.permission.LOCATION'; + let permissionName2 = 'ohos.permission.LOCATION_IN_BACKGROUND'; + await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); + }); + await atManager.grantUserGrantedPermission(tokenID, permissionName2, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); + }); + } else { + console.info('[permission] case apply permission failed, createAtManager failed'); + } + } beforeAll(function () { console.info('beforeAll called') }) diff --git a/communication/bluetooth_standard/src/main/js/test/BRSetLocalName.test.js b/communication/bluetooth_standard/src/main/js/test/BRSetLocalName.test.js index 1aebc38ba900d07d67bdfacc4eef182e1c4ebfeb..ab90a5d1d64a5f80224cf8492def558e0608fe77 100644 --- a/communication/bluetooth_standard/src/main/js/test/BRSetLocalName.test.js +++ b/communication/bluetooth_standard/src/main/js/test/BRSetLocalName.test.js @@ -14,6 +14,11 @@ */ import bluetooth from '@ohos.bluetooth'; +import geolocation from '@ohos.geolocation'; +import geolocationm from '@ohos.geoLocationManager'; +import abilityAccessCtrl from '@ohos.abilityAccessCtrl'; +import bundle from '@ohos.bundle'; +import osaccount from '@ohos.account.osAccount'; import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' let Btname = { NUM_TEST :'012345678901234567890123456789012345678901234567890123'+ @@ -49,7 +54,7 @@ describe('bluetoothhostTest1', function() { switch(sta){ case 0: bluetooth.enableBluetooth(); - await sleep(5000); + await sleep(10000); let sta1 = bluetooth.getState(); console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta1)); break; @@ -62,7 +67,7 @@ describe('bluetoothhostTest1', function() { break; case 3: bluetooth.enableBluetooth(); - await sleep(3000); + await sleep(10000); let sta2 = bluetooth.getState(); console.info('[bluetooth_js] bt turning off:'+ JSON.stringify(sta2)); break; @@ -70,6 +75,32 @@ describe('bluetoothhostTest1', function() { console.info('[bluetooth_js] enable success'); } } + async function applyPermission() { + let osAccountManager = osaccount.getAccountManager(); + console.info("=== getAccountManager finish"); + let localId = await osAccountManager.getOsAccountLocalIdFromProcess(); + console.info("LocalId is :" + localId); + let appInfo = await bundle.getApplicationInfo('ohos.acts.location.geolocation.function', 0, localId); + let atManager = abilityAccessCtrl.createAtManager(); + if (atManager != null) { + let tokenID = appInfo.accessTokenId; + console.info('[permission] case accessTokenID is ' + tokenID); + let permissionName1 = 'ohos.permission.LOCATION'; + let permissionName2 = 'ohos.permission.LOCATION_IN_BACKGROUND'; + await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); + }); + await atManager.grantUserGrantedPermission(tokenID, permissionName2, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); + }); + } else { + console.info('[permission] case apply permission failed, createAtManager failed'); + } + } beforeAll(function () { console.info('beforeAll called') }) diff --git a/communication/bluetooth_standard/src/main/js/test/BRSpp.test.js b/communication/bluetooth_standard/src/main/js/test/BRSpp.test.js index a9b1974e9517cb326237567dd1cb354e387b46bf..940fff3630f9d0e08e0e21958cc53e9cf70c1189 100644 --- a/communication/bluetooth_standard/src/main/js/test/BRSpp.test.js +++ b/communication/bluetooth_standard/src/main/js/test/BRSpp.test.js @@ -14,6 +14,11 @@ */ import bluetooth from '@ohos.bluetooth'; +import geolocation from '@ohos.geolocation'; +import geolocationm from '@ohos.geoLocationManager'; +import abilityAccessCtrl from '@ohos.abilityAccessCtrl'; +import bundle from '@ohos.bundle'; +import osaccount from '@ohos.account.osAccount'; import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' @@ -29,7 +34,7 @@ describe('bluetoothhostTest4', function() { case 0: console.info('[bluetooth_js] bt turn off:'+ JSON.stringify(sta)); bluetooth.enableBluetooth(); - await sleep(3000); + await sleep(10000); break; case 1: console.info('[bluetooth_js] bt turning on:'+ JSON.stringify(sta)); @@ -41,12 +46,38 @@ describe('bluetoothhostTest4', function() { case 3: console.info('[bluetooth_js] bt turning off:'+ JSON.stringify(sta)); bluetooth.enableBluetooth(); - await sleep(3000); + await sleep(10000); break; default: console.info('[bluetooth_js] enable success'); } } + async function applyPermission() { + let osAccountManager = osaccount.getAccountManager(); + console.info("=== getAccountManager finish"); + let localId = await osAccountManager.getOsAccountLocalIdFromProcess(); + console.info("LocalId is :" + localId); + let appInfo = await bundle.getApplicationInfo('ohos.acts.location.geolocation.function', 0, localId); + let atManager = abilityAccessCtrl.createAtManager(); + if (atManager != null) { + let tokenID = appInfo.accessTokenId; + console.info('[permission] case accessTokenID is ' + tokenID); + let permissionName1 = 'ohos.permission.LOCATION'; + let permissionName2 = 'ohos.permission.LOCATION_IN_BACKGROUND'; + await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); + }); + await atManager.grantUserGrantedPermission(tokenID, permissionName2, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); + }); + } else { + console.info('[permission] case apply permission failed, createAtManager failed'); + } + } beforeAll(function () { console.info('beforeAll called') }) diff --git a/communication/bluetooth_standard/src/main/js/test/BRSwitch.test.js b/communication/bluetooth_standard/src/main/js/test/BRSwitch.test.js index e5566ea1087a5670588aaf4947d62c06291e4079..1bb1fbbac283fb5a0308294d7a71873b7d35721d 100644 --- a/communication/bluetooth_standard/src/main/js/test/BRSwitch.test.js +++ b/communication/bluetooth_standard/src/main/js/test/BRSwitch.test.js @@ -14,8 +14,20 @@ */ import bluetooth from '@ohos.bluetooth'; +import geolocation from '@ohos.geolocation'; +import geolocationm from '@ohos.geoLocationManager'; +import abilityAccessCtrl from '@ohos.abilityAccessCtrl'; +import bundle from '@ohos.bundle'; +import osaccount from '@ohos.account.osAccount'; import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' - + +let BluetoothState = { + STATE_OFF: 0,STATE_TURNING_ON: 1, + STATE_ON: 2,STATE_TURNING_OFF: 3, + STATE_BLE_TURNING_ON: 4, STATE_BLE_ON: 5, + STATE_BLE_ON: 6 +}; + export default function bluetoothhostTest() { describe('bluetoothhostTest', function() { function sleep(delay) { @@ -26,7 +38,7 @@ describe('bluetoothhostTest', function() { switch(sta){ case 0: bluetooth.enableBluetooth(); - await sleep(5000); + await sleep(10000); let sta1 = bluetooth.getState(); console.info('[bluetooth_js] Reacquire bt state:'+ JSON.stringify(sta1)); break; @@ -39,7 +51,7 @@ describe('bluetoothhostTest', function() { break; case 3: bluetooth.enableBluetooth(); - await sleep(3000); + await sleep(10000); let sta2 = bluetooth.getState(); console.info('[bluetooth_js] bt turning off:'+ JSON.stringify(sta2)); break; @@ -47,6 +59,32 @@ describe('bluetoothhostTest', function() { console.info('[bluetooth_js] enable success'); } } + async function applyPermission() { + let osAccountManager = osaccount.getAccountManager(); + console.info("=== getAccountManager finish"); + let localId = await osAccountManager.getOsAccountLocalIdFromProcess(); + console.info("LocalId is :" + localId); + let appInfo = await bundle.getApplicationInfo('ohos.acts.location.geolocation.function', 0, localId); + let atManager = abilityAccessCtrl.createAtManager(); + if (atManager != null) { + let tokenID = appInfo.accessTokenId; + console.info('[permission] case accessTokenID is ' + tokenID); + let permissionName1 = 'ohos.permission.LOCATION'; + let permissionName2 = 'ohos.permission.LOCATION_IN_BACKGROUND'; + await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); + }); + await atManager.grantUserGrantedPermission(tokenID, permissionName2, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); + }); + } else { + console.info('[permission] case apply permission failed, createAtManager failed'); + } + } beforeAll(function () { console.info('beforeAll called') }) @@ -81,7 +119,7 @@ describe('bluetoothhostTest', function() { if(state!=bluetooth.BluetoothState.STATE_ON) { let enable = bluetooth.enableBluetooth(); - await sleep(5000); + await sleep(10000); console.info('[bluetooth_js] bluetooth enable001'+JSON.stringify(enable)); expect(enable).assertTrue(); let state1 = bluetooth.getState(); @@ -109,12 +147,13 @@ describe('bluetoothhostTest', function() { * @tc.level Level 3 */ it('SUB_COMMUNICATION_BLUETOOTH_BR_Switch_0300', 0, async function (done) { + let enable = bluetooth.enableBluetooth(); let state = bluetooth.getState(); console.info('[bluetooth_js] bt open state1 = '+ JSON.stringify(state)); expect(state).assertEqual(bluetooth.BluetoothState.STATE_ON); if(state==bluetooth.BluetoothState.STATE_ON) { let enable1=bluetooth.enableBluetooth(); - await sleep(3000); + await sleep(10000); console.info('[bluetooth_js]enable1 :'+ JSON.stringify(enable1)); expect(enable1).assertFalse(); let state1 = bluetooth.getState();