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

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

Merge pull request !8185 from 权力/myfeature
......@@ -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();
......
......@@ -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();
......
......@@ -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();
......
......@@ -16,8 +16,8 @@
"package": "ohos.acts.communication.bluetooth.bluetoothhost",
"name": ".entry",
"deviceType": [
"tablet",
"default",
"tablet",
"default",
"phone"
],
"distro": {
......
......@@ -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()
})
......
......@@ -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 () {
......
......@@ -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");
......
......@@ -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");
})
......
......@@ -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 () {
......
......@@ -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 () {
......
......@@ -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()
// }
// })
})
}
......
......@@ -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) {
......
......@@ -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) {
......
......@@ -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) {
......
......@@ -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')
})
......
......@@ -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')
})
......
......@@ -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": "",
......
......@@ -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()
})
......
......@@ -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')
......
......@@ -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')
......
......@@ -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')
......
......@@ -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')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册