提交 a047e6d0 编写于 作者: 梁家熙

change request permission method in medialibrary xts

Signed-off-by: N梁家熙 <liangjiaxi2@huawei.com>
Change-Id: I3cb53c0e2f4ea24bb28d9ff7e21dbb88edf6168f
上级 237e7187
......@@ -235,20 +235,26 @@ const getPermission = async function (name, context) {
console.info("getPermission start", name);
let permissions = ["ohos.permission.MEDIA_LOCATION", "ohos.permission.READ_MEDIA", "ohos.permission.WRITE_MEDIA"];
context.requestPermissionsFromUser(permissions, (data) => {
console.info(`getPermission requestPermissionsFromUser ${JSON.stringify(data)}`);
});
await sleep(200);
let atManager = abilityAccessCtrl.createAtManager();
try {
atManager.requestPermissionsFromUser(context, permissions, (err, data) => {
console.info(`getPermission requestPermissionsFromUser ${JSON.stringify(data)}`);
});
} catch (err) {
console.log(`get permission catch err -> ${JSON.stringify(err)}`);
}
await sleep(1000);
let driver = uitest.Driver.create();
await sleep(200);
await sleep(2000);
let button = await driver.findComponent(uitest.ON.text("允许"));
await button.click();
await sleep(2000);
let appInfo = await bundle.getApplicationInfo(name, 0, 100);
let tokenID = appInfo.accessTokenId;
let atManager = abilityAccessCtrl.createAtManager();
let isGranted1 = await atManager.verifyAccessToken(tokenID, "ohos.permission.MEDIA_LOCATION");
let isGranted2 = await atManager.verifyAccessToken(tokenID, "ohos.permission.READ_MEDIA");
let isGranted3 = await atManager.verifyAccessToken(tokenID, "ohos.permission.WRITE_MEDIA");
......
......@@ -25,21 +25,27 @@ export default function getExifNoLocation(abilityContext) {
describe("getExifNoLocation", function () {
beforeAll(async function () {
console.info("beforeAll case");
let atManager = abilityAccessCtrl.createAtManager();
let permissions = ["ohos.permission.READ_MEDIA"];
abilityContext.requestPermissionsFromUser(permissions, (data) => {
console.info(`getPermission requestPermissionsFromUser ${JSON.stringify(data)}`);
});
await sleep(200);
try {
atManager.requestPermissionsFromUser(abilityContext, permissions, (err, data) => {
console.info(`getPermission requestPermissionsFromUser ${JSON.stringify(data)}`);
});
} catch (err) {
console.log(`get permission catch err -> ${JSON.stringify(err)}`);
}
await sleep(1000);
let driver = uitest.Driver.create();
await sleep(200);
await sleep(2000);
let button = await driver.findComponent(uitest.ON.text("允许"));
await button.click();
await sleep(2000);
let appInfo = await bundle.getApplicationInfo("ohos.acts.multimedia.mediaLibrary", 0, 100);
let tokenID = appInfo.accessTokenId;
let atManager = abilityAccessCtrl.createAtManager();
let isGranted = await atManager.verifyAccessToken(tokenID, "ohos.permission.READ_MEDIA");
if (isGranted != 0) {
console.info("getpermission failed");
......
......@@ -25,22 +25,28 @@ export default function getExifLocation(abilityContext) {
describe("getExifLocation", function () {
beforeAll(async function () {
console.info("beforeAll case");
let atManager = abilityAccessCtrl.createAtManager();
let permissions = ["ohos.permission.MEDIA_LOCATION", "ohos.permission.READ_MEDIA"];
abilityContext.requestPermissionsFromUser(permissions, (data) => {
console.info(`getPermission requestPermissionsFromUser ${JSON.stringify(data)}`);
});
await sleep(200);
try {
atManager.requestPermissionsFromUser(abilityContext, permissions, (err, data) => {
console.info(`getPermission requestPermissionsFromUser ${JSON.stringify(data)}`);
});
} catch (err) {
console.log(`get permission catch err -> ${JSON.stringify(err)}`);
}
await sleep(1000);
let driver = uitest.Driver.create();
await sleep(200);
await sleep(2000);
let button = await driver.findComponent(uitest.ON.text("允许"));
await button.click();
await sleep(2000);
let appInfo = await bundle.getApplicationInfo("ohos.acts.multimedia.mediaLibrary", 0, 100);
let tokenID = appInfo.accessTokenId;
let atManager = abilityAccessCtrl.createAtManager();
let isGranted1 = await atManager.verifyAccessToken(tokenID, "ohos.permission.MEDIA_LOCATION");
let isGranted2 = await atManager.verifyAccessToken(tokenID, "ohos.permission.READ_MEDIA");
if (!(isGranted1 == 0 && isGranted2 == 0)) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册