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 006c6f73b87fbeec52e461da1f5a9fe319fd1b76..b524894531b5b34a400f8ebbc5072fba059793e3 100644 --- a/communication/bluetooth_ble/src/main/js/test/BleAdvertiser.test.js +++ b/communication/bluetooth_ble/src/main/js/test/BleAdvertiser.test.js @@ -15,11 +15,6 @@ */ 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' @@ -54,32 +49,6 @@ describe('bluetoothBLETest2', 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(); 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 f1841e59a25c54167aa944677e23fb7eecd15fca..6e7d25df617baf2a20397ca75677073a6d73a646 100644 --- a/communication/bluetooth_ble/src/main/js/test/BleGattManager.test.js +++ b/communication/bluetooth_ble/src/main/js/test/BleGattManager.test.js @@ -14,11 +14,6 @@ */ 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() { @@ -53,32 +48,6 @@ describe('bluetoothBLETest', 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(); 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 50cd72c51b77f5e76264c197342394aa5c2b388f..3526bc4501a0a227ff03b7047ef7b665cd1cb97a 100644 --- a/communication/bluetooth_ble/src/main/js/test/BleService.test.js +++ b/communication/bluetooth_ble/src/main/js/test/BleService.test.js @@ -14,11 +14,6 @@ */ 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() { @@ -54,32 +49,6 @@ describe('bluetoothBLETest1', 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(); diff --git a/communication/bluetooth_manager/src/main/config.json b/communication/bluetooth_manager/src/main/config.json index 2b3e44f06cc9c61f7c22faec8570caeaebc07f74..14ff4b72c7141fce49e34772c0ead98b28caef76 100644 --- a/communication/bluetooth_manager/src/main/config.json +++ b/communication/bluetooth_manager/src/main/config.json @@ -16,8 +16,8 @@ "package": "ohos.acts.communication.bluetooth.bluetoothhost", "name": ".entry", "deviceType": [ - "tablet", - "default", + "tablet", + "default", "phone" ], "distro": { 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 78f8fa93fe87cd15ce190bda595757159f9e7299..55b36b61a2f22d19ad365e64b98d09e03df46320 100644 --- a/communication/bluetooth_manager/src/main/js/test/BleAdvertiser.test.js +++ b/communication/bluetooth_manager/src/main/js/test/BleAdvertiser.test.js @@ -15,14 +15,8 @@ */ 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 bluetoothBLETest2() { describe('bluetoothBLETest2', function() { let gattServer = null; @@ -54,41 +48,14 @@ describe('bluetoothBLETest2', 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') - await tryToEnableBt() gattServer = bluetooth.BLE.createGattServer(); done() }) beforeEach(async function (done) { console.info('beforeEach called') - await tryToEnableBt() + await tryToEnableBt(); done() }) 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 264422a7a2afb3275b2a35c7d9a79c414b118b00..a9f20b2bab02fcf4fd4a3423fd016d32f8ca2b9b 100644 --- a/communication/bluetooth_manager/src/main/js/test/BleAdvertiser401.test.js +++ b/communication/bluetooth_manager/src/main/js/test/BleAdvertiser401.test.js @@ -14,16 +14,9 @@ * limitations under the License. */ -//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 bluetoothBLETest5() { describe('bluetoothBLETest5', function() { let gattServer = null; @@ -55,41 +48,14 @@ describe('bluetoothBLETest5', 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') - await tryToEnableBt() gattServer = bluetooth.BLE.createGattServer(); done() }) beforeEach(async function (done) { console.info('beforeEach called') - await tryToEnableBt() + await tryToEnableBt(); done() }) afterEach(function () { 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 b9c48a0c630bb42a14299fc8ca2154c8f6695d94..7be72894a586a896f3c20162fac4d4cc9f9bdf7f 100644 --- a/communication/bluetooth_manager/src/main/js/test/BleGattManager.test.js +++ b/communication/bluetooth_manager/src/main/js/test/BleGattManager.test.js @@ -14,11 +14,6 @@ */ 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() { @@ -53,33 +48,7 @@ describe('bluetoothBLETest', 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 () { + beforeAll(function() { console.info('beforeAll called') gattServer = bluetooth.BLE.createGattServer(); gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); 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 089b48922dc725c3c4d633d531dd689d24e07558..56bd87ba0d235ff8a4a806302ddbe96124c128e6 100644 --- a/communication/bluetooth_manager/src/main/js/test/BleGattManager401.test.js +++ b/communication/bluetooth_manager/src/main/js/test/BleGattManager401.test.js @@ -13,13 +13,7 @@ * limitations under the License. */ -//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() { @@ -53,33 +47,7 @@ describe('bluetoothBLETest4', 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 () { + 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 9c657379a1952190abc08eb77d1834b367335f88..e95e46af5a3908e6d45c76d686e10b90b6c3d6c0 100644 --- a/communication/bluetooth_manager/src/main/js/test/BleScanResult.test.js +++ b/communication/bluetooth_manager/src/main/js/test/BleScanResult.test.js @@ -14,12 +14,31 @@ */ 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' +import abilityAccessCtrl from '@ohos.abilityAccessCtrl' +import bundle from '@ohos.bundle' +import osaccount from '@ohos.account.osAccount' + +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.communication.bluetooth.bluetoothhost', 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'; + await atManager.grantUserGrantedPermission(tokenID, permissionName1, 2).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'); + } +} export default function bluetoothBLETest6() { describe('bluetoothBLETest6', function() { @@ -53,38 +72,13 @@ 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 () { + beforeAll(async function(done) { console.info('beforeAll called') + await applyPermission(); }) beforeEach(async function(done) { console.info('beforeEach called') - await tryToEnableBt() + await tryToEnableBt(); done() }) afterEach(function () { 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 fc42fa8591fd9ea9ad02eb884bf6649e43d96381..8aa6be834cd4e6db14cac2965ae1ba191a053dca 100644 --- a/communication/bluetooth_manager/src/main/js/test/BleService.test.js +++ b/communication/bluetooth_manager/src/main/js/test/BleService.test.js @@ -14,18 +14,13 @@ */ 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 + STATE_BLE_TURNING_OFF: 6 }; let SppOption = {uuid: '00001810-0000-1000-8000-00805F9B34FB', @@ -78,8 +73,10 @@ let MajorMinorClass = { HEALTH_KNEE_PROSTHESIS : 0x0930,HEALTH_ANKLE_PROSTHESIS : 0x0934, HEALTH_GENERIC_HEALTH_MANAGER : 0x0938, HEALTH_PERSONAL_MOBILITY_DEVICE : 0x093C, - HEALTH_PERSONAL_MOBILITY_DEVICE : 0x093C + HEALTH_PERSONAL_MOBILITY_DEVICE : 0x093C, + HEALTH_PEAK_FLOW_MONITOR : 0x0928 }; + let MajorClass = { MAJOR_MISC : 0x0000,MAJOR_COMPUTER : 0x0100, MAJOR_PHONE : 0x0200,MAJOR_NETWORKING : 0x0300, @@ -129,42 +126,15 @@ describe('bluetoothBLETest1', 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') - await tryToEnableBt() gattServer = bluetooth.BLE.createGattServer(); gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); done() }) beforeEach(async function(done) { console.info('beforeEach called') - await tryToEnableBt() + await tryToEnableBt(); done() }) afterEach(function () { 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 0bb3bdf7ab93824349cb835495cca64fd872d040..24dd0f7c0d0c634ea12e7b403fb76cf5ddc58a54 100644 --- a/communication/bluetooth_manager/src/main/js/test/SwitchOff003.test.js +++ b/communication/bluetooth_manager/src/main/js/test/SwitchOff003.test.js @@ -14,12 +14,31 @@ */ 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' +import abilityAccessCtrl from '@ohos.abilityAccessCtrl' +import bundle from '@ohos.bundle' +import osaccount from '@ohos.account.osAccount' + +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.communication.bluetooth.bluetoothhost', 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'; + await atManager.grantUserGrantedPermission(tokenID, permissionName1, 2).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'); + } +} export default function bluetoothBLETest3() { describe('bluetoothBLETest3', function() { @@ -51,39 +70,14 @@ 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 () { + beforeAll(function() { console.info('beforeAll called') gattServer = bluetooth.BLE.createGattServer(); gattClient = bluetooth.BLE.createGattClientDevice("11:22:33:44:55:66"); }) beforeEach(async function(done) { console.info('beforeEach called') + await applyPermission(); await tryToDisableBt() done() }) @@ -234,7 +228,7 @@ describe('bluetoothBLETest3', function() { expect(true).assertFalse(); done() } catch (error) { - console.error('[bluetooth_js]getProfileConnectionState error.code:'+JSON.stringify(error.code)+ + console.error('[bluetooth_js]getProfileConnState error.code:'+JSON.stringify(error.code)+ 'error.message:'+JSON.stringify(error.message)); expect(error.code).assertEqual('2900003'); done() @@ -386,8 +380,8 @@ describe('bluetoothBLETest3', function() { */ it('COMMUNICATION_BLUETOOTH_SwitchOff_1600', 0, async function (done) { try { - let hfpSrc = bluetooth.getProfileInstance(bluetooth.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY); - let retArray = hfpSrc.getConnectionDevices(); + let hfpSrc = bluetooth.getProfileInst(bluetooth.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY); + let retArray = hfpSrc.getConnectionDevices(); console.info('[bluetooth_js]hfp getConnectionDevices:' + JSON.stringify(retArray)); expect(true).assertFalse(); done() @@ -602,9 +596,8 @@ describe('bluetoothBLETest3', function() { */ it('COMMUNICATION_BLUETOOTH_SwitchOff_2500', 0, async function (done) { try { - let panSrc = - bluetooth.getProfileInst(bluetooth.ProfileId.PROFILE_PAN_NETWORK); - panSrc.disconnect('11:22:33:44:55:77'); + let panSrc = bluetooth.getProfileInstance(bluetooth.ProfileId.PROFILE_PAN_NETWORK); +// panSrc.disconnect('11:22:33:44:55:77'); expect(true).assertFalse(); done() } catch (error) { @@ -626,9 +619,9 @@ describe('bluetoothBLETest3', function() { */ it('COMMUNICATION_BLUETOOTH_SwitchOff_2600', 0, async function (done) { try { - let panSrc = - bluetooth.getProfileInst(bluetooth.ProfileId.PROFILE_PAN_NETWORK); - panSrc.setTethering(true); + let panSrc = + bluetooth.getProfileInstance(bluetooth.ProfileId.PROFILE_PAN_NETWORK); +// panSrc.setTethering(true); expect(true).assertFalse(); done() } catch (error) { @@ -978,28 +971,28 @@ describe('bluetoothBLETest3', function() { done() }) - /** - * @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_4000 - * @tc.name Test cancelPairedDevice api - * @tc.desc Test 2900003 - Bluetooth switch is off - * @tc.size MEDIUM - * @ since 8 - * @tc.type 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(); - done() - } catch (error) { - console.error('[bluetooth_js]cancelPairedDevice error.code:'+JSON.stringify(error.code)+ - 'error.message:'+JSON.stringify(error.message)); - expect(error.code).assertEqual('2900003'); - done() - } - }) +// /** +// * @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_4000 +// * @tc.name Test cancelPairedDevice api +// * @tc.desc Test 2900003 - Bluetooth switch is off +// * @tc.size MEDIUM +// * @ since 8 +// * @tc.type 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(); +// done() +// } catch (error) { +// console.error('[bluetooth_js]cancelPairedDevice error.code:'+JSON.stringify(error.code)+ +// '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 b96f3a1b4cac34c350b489692caf851baee7b501..be6ce39076f06cb9f28bb47a6d1e525afd9329d1 100644 --- a/communication/bluetooth_on/src/main/js/test/BleScanResult.test.js +++ b/communication/bluetooth_on/src/main/js/test/BleScanResult.test.js @@ -14,12 +14,38 @@ */ 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' +import osaccount from '@ohos.account.osAccount' +import bundle from '@ohos.bundle' +import abilityAccessCtrl from '@ohos.abilityAccessCtrl' + +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.communication.bluetooth.bluetoothhost', 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.DISCOVER_BLUETOOTH'; + 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'); + } +} + export default function bluetoothhostTest() { describe('bluetoothhostTest', function() { @@ -53,33 +79,8 @@ 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 () { + beforeAll(async function (done) { + await applyPermission(); console.info('beforeAll called') }) beforeEach(async function(done) { 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 21d80d82ad6c31da7ad6bd6a194db6b05ab302ed..34a17da321472d4b8944102ac9dea86a3d8a9244 100644 --- a/communication/bluetooth_on/src/main/js/test/BluetoothPair.test.js +++ b/communication/bluetooth_on/src/main/js/test/BluetoothPair.test.js @@ -14,14 +14,8 @@ */ 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() { describe('bluetoothhostTest2', function() { function sleep(delay) { @@ -54,33 +48,7 @@ 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 () { + beforeAll(async function (done) { console.info('beforeAll called') }) beforeEach(async function(done) { 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 b32d06376e8bf2bb2af04f0807547e48ea2baa87..86f7ead97ca86aaf2831347f0af0ab5b554ef663 100644 --- a/communication/bluetooth_on/src/main/js/test/bluetoothSys.test.js +++ b/communication/bluetooth_on/src/main/js/test/bluetoothSys.test.js @@ -15,12 +15,37 @@ 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' +import osaccount from '@ohos.account.osAccount' +import bundle from '@ohos.bundle' +import abilityAccessCtrl from '@ohos.abilityAccessCtrl' + +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.communication.bluetooth.bluetoothhost', 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.DISCOVER_BLUETOOTH'; + 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'); + } +} export default function bluetoothhostTest4() { describe('bluetoothhostTest4', function() { @@ -54,33 +79,8 @@ 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 () { + beforeAll(async function (done) { + await applyPermission(); console.info('beforeAll called') }) beforeEach(async function(done) { 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 84ece3d748fba764dc9051aaebab8dcc07886e56..908b846069a4612007d6387875f8f935a09dd0ab 100644 --- a/communication/bluetooth_profile/src/main/js/test/BluetoothA2dp.test.js +++ b/communication/bluetooth_profile/src/main/js/test/BluetoothA2dp.test.js @@ -14,19 +14,8 @@ */ 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 () { @@ -60,32 +49,6 @@ 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 a299ea9a7eb6a70a4aaf1ce8602d0d085b8d9593..708251f61a2df7dde6c123dd0764e4740b5392e7 100644 --- a/communication/bluetooth_profile/src/main/js/test/BluetoothHfp.test.js +++ b/communication/bluetooth_profile/src/main/js/test/BluetoothHfp.test.js @@ -14,11 +14,6 @@ */ 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' @@ -54,32 +49,6 @@ 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/config.json b/communication/bluetooth_standard/src/main/config.json index 2b3e44f06cc9c61f7c22faec8570caeaebc07f74..2b0e97d8b96c1d5677d7be197d30456b74fe694f 100644 --- a/communication/bluetooth_standard/src/main/config.json +++ b/communication/bluetooth_standard/src/main/config.json @@ -16,8 +16,8 @@ "package": "ohos.acts.communication.bluetooth.bluetoothhost", "name": ".entry", "deviceType": [ - "tablet", - "default", + "tablet", + "default", "phone" ], "distro": { @@ -96,6 +96,16 @@ "when": "inuse" } }, + { + "name": "ohos.permission.DISCOVER_BLUETOOTH'", + "reason": "", + "usedScene": { + "ability": [ + "ohos.acts.communication.bluetooth.bluetoothhost.MainAbility" + ], + "when": "inuse" + } + }, { "name": "ohos.permission.MANAGE_BLUETOOTH", "reason": "", 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 b7bbf20b322d924bb068b07b9e22bb8647695e69..e9a9ccc4c243463faad076e8cd0708e6b3b93260 100644 --- a/communication/bluetooth_standard/src/main/js/test/BRDiscovery.test.js +++ b/communication/bluetooth_standard/src/main/js/test/BRDiscovery.test.js @@ -14,17 +14,43 @@ */ import bluetooth from '@ohos.bluetooth'; -import geolocation from '@ohos.geolocation'; -import geolocationm from '@ohos.geoLocationManager'; -import osaccount from '@ohos.account.osAccount'; +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' import abilityAccessCtrl from '@ohos.abilityAccessCtrl' import bundle from '@ohos.bundle' -import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' +import osaccount from '@ohos.account.osAccount' const PERMISSION_USER_SET = 1; const PERMISSION_USER_NAME1 = "ohos.permission.LOCATION"; const PERMISSION_USER_NAME2 = 'ohos.permission.LOCATION_IN_BACKGROUND'; let tokenID = undefined; + +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.communication.bluetooth.bluetoothhost', 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.DISCOVER_BLUETOOTH'; + 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'); + } +} + async function grantPerm() { console.info("====grant Permission start===="); let appInfo = await bundle.getApplicationInfo('ohos.acts.communication.bluetooth.bluetoothhost', 0, 100); @@ -69,35 +95,10 @@ 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') + await applyPermission(); await grantPerm(); done() }) 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 432d8a1636fa8981e715ab865858154763f6c612..f5c0c674be57e84a29f62d9a7239c49fefa45a1f 100644 --- a/communication/bluetooth_standard/src/main/js/test/BRScanMode.test.js +++ b/communication/bluetooth_standard/src/main/js/test/BRScanMode.test.js @@ -14,11 +14,6 @@ */ 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() { @@ -52,34 +47,9 @@ 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 () { + beforeAll(async function (done) { console.info('beforeAll called') + done() }) beforeEach(async function(done) { console.info('beforeEach 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 ab90a5d1d64a5f80224cf8492def558e0608fe77..a907bb3c9aed3b08b1b8d922240877254cf77d65 100644 --- a/communication/bluetooth_standard/src/main/js/test/BRSetLocalName.test.js +++ b/communication/bluetooth_standard/src/main/js/test/BRSetLocalName.test.js @@ -14,12 +14,8 @@ */ 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'+ '45678901234567890123456789012345678901234567890123456789012345678901234567', @@ -75,34 +71,9 @@ 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 () { + beforeAll(async function (done) { console.info('beforeAll called') + done() }) beforeEach(async function(done) { console.info('beforeEach 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 940fff3630f9d0e08e0e21958cc53e9cf70c1189..126cd71259510ef700fcf36a710af19bdd752177 100644 --- a/communication/bluetooth_standard/src/main/js/test/BRSpp.test.js +++ b/communication/bluetooth_standard/src/main/js/test/BRSpp.test.js @@ -14,13 +14,34 @@ */ 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' +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.communication.bluetooth.bluetoothhost', 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.DISCOVER_BLUETOOTH'; + 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'); + } +} export default function bluetoothhostTest4() { describe('bluetoothhostTest4', function() { @@ -52,34 +73,9 @@ 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 () { + beforeAll(async function (done) { console.info('beforeAll called') + done() }) beforeEach(async function(done) { console.info('beforeEach 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 1bb1fbbac283fb5a0308294d7a71873b7d35721d..6266b4e3e2ef1128135e21195ae8b2dc1162f4a3 100644 --- a/communication/bluetooth_standard/src/main/js/test/BRSwitch.test.js +++ b/communication/bluetooth_standard/src/main/js/test/BRSwitch.test.js @@ -14,18 +14,13 @@ */ 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 + STATE_BLE_TURNING_OFF: 6 }; export default function bluetoothhostTest() { @@ -59,34 +54,9 @@ 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 () { + beforeAll(async function (done) { console.info('beforeAll called') + done() }) beforeEach(async function(done) { console.info('beforeEach called')