未验证 提交 45338c7d 编写于 作者: O openharmony_ci 提交者: Gitee

!8114 【communication】【XTS脚本优化】bt优化脚本

Merge pull request !8114 from 权力/myfeature
......@@ -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();
......
......@@ -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();
......
......@@ -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();
......
......@@ -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()
......
......@@ -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()
......
......@@ -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();
......
......@@ -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");
......
......@@ -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')
})
......
......@@ -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()
......
......@@ -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();
......
......@@ -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')
})
......
......@@ -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')
})
......
......@@ -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')
})
......
......@@ -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')
})
......
......@@ -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')
})
......
......@@ -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')
......
......@@ -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')
})
......
......@@ -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')
})
......
......@@ -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')
})
......
......@@ -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();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册