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

!8829 修复uri临时授权xts

Merge pull request !8829 from 于文泽/master
......@@ -15,97 +15,101 @@
import Ability from '@ohos.app.ability.UIAbility'
import commonEvent from '@ohos.commonEvent';
function sleep(time) {
return new Promise((resolve) => setTimeout(resolve, time))
}
export default class Hap2MainAbility4 extends Ability {
onCreate(want, launchParam) {
console.log('[Demo] Hap2MainAbility4 onCreate')
}
onCreate(want, launchParam) {
console.log('[Demo] Hap2MainAbility4 onCreate')
}
onDestroy() {
console.log('[Demo] Hap2MainAbility4 onDestroy')
}
onDestroy() {
console.log('[Demo] Hap2MainAbility4 onDestroy')
}
onWindowStageCreate(windowStage) {
console.log('[Demo] Hap2MainAbility4 onWindowStageCreate')
windowStage.setUIContent(this.context, 'pages/Hap2MainAbility4_pages', null)
}
onWindowStageDestroy() {
console.log('[Demo] Hap2MainAbility4 onWindowStageDestroy')
}
onWindowStageCreate(windowStage) {
console.log('[Demo] Hap2MainAbility4 onWindowStageCreate')
windowStage.setUIContent(this.context, 'pages/Hap2MainAbility4_pages', null)
onForeground() {
console.log('[Demo] Hap2MainAbility4 onForeground')
let uri : string = globalThis.abilityWant3.uri;
if (uri == null) {
console.log('[Demo] Hap2MainAbility1 uri is invalid');
return;
}
let eventName1 : string = 'Temp_UriPermissionTest_0300_Read_Successfully';
let eventName2 : string = 'Temp_UriPermissionTest_0300_Read_Failed';
globalThis.fs.open(uri, globalThis.fs.OpenMode.READ_ONLY).then((file) => {
console.info('file fd: ' + file.fd);
commonEvent.publish(eventName1, (err) => {
console.log('Hap2MainAbility4' + eventName1);
});
}).catch((err) => {
console.info('open file failed with error message: ' + err.message + ', error code: ' + err.code);
commonEvent.publish(eventName2, (err) => {
console.log('Hap2MainAbility4' + eventName2);
});
});
onWindowStageDestroy() {
console.log('[Demo] Hap2MainAbility4 onWindowStageDestroy')
let eventName3 : string = 'Temp_UriPermissionTest_0300_Write_Successfully';
let eventName4 : string = 'Temp_UriPermissionTest_0300_Write_Failed';
globalThis.fs.open(uri, globalThis.fs.OpenMode.READ_WRITE).then((file) => {
console.info('file fd: ' + file.fd);
commonEvent.publish(eventName3, (err) => {
console.log('Hap2MainAbility4' + eventName3);
});
}).catch((err) => {
console.info('open file failed with error message: ' + err.message + ', error code: ' + err.code);
commonEvent.publish(eventName4, (err) => {
console.log('Hap2MainAbility4' + eventName4);
});
});
let eventName5 : string = 'TerminateDone_Hap2MainAbility3';
let subscribeInfo = {
events: [eventName5]
}
onForeground() {
console.log('[Demo] Hap2MainAbility4 onForeground')
let uri : string = globalThis.abilityWant3.uri;
if (uri == null) {
console.log('[Demo] Hap2MainAbility1 uri is invalid');
return;
}
let eventName1 : string = 'Temp_UriPermissionTest_0300_Read_Successfully';
let eventName2 : string = 'Temp_UriPermissionTest_0300_Read_Failed';
let eventName6 : string = 'Temp_UriPermissionTest_0300_Read_Successfully_';
let eventName7 : string = 'Temp_UriPermissionTest_0300_Read_Failed_';
async function SubscribeCallBackContext(err, data) {
console.log(' Subscribe CallBack data:' + JSON.stringify(data));
if (data.event === eventName5) {
await sleep(1000);
globalThis.fs.open(uri, globalThis.fs.OpenMode.READ_ONLY).then((file) => {
console.info('file fd: ' + file.fd);
commonEvent.publish(eventName1, (err) => {
console.log('Hap2MainAbility4' + eventName1);
});
}).catch((err) => {
console.info('open file failed with error message: ' + err.message + ', error code: ' + err.code);
commonEvent.publish(eventName2, (err) => {
console.log('Hap2MainAbility4' + eventName2);
});
});
let eventName3 : string = 'Temp_UriPermissionTest_0300_Write_Successfully';
let eventName4 : string = 'Temp_UriPermissionTest_0300_Write_Failed';
globalThis.fs.open(uri, globalThis.fs.OpenMode.READ_WRITE).then((file) => {
console.info('file fd: ' + file.fd);
commonEvent.publish(eventName3, (err) => {
console.log('Hap2MainAbility4' + eventName3);
});
console.info('file fd: ' + file.fd);
commonEvent.publish(eventName6, (err) => {
console.log('Hap2MainAbility4' + eventName6);
});
}).catch((err) => {
console.info('open file failed with error message: ' + err.message + ', error code: ' + err.code);
commonEvent.publish(eventName4, (err) => {
console.log('Hap2MainAbility4' + eventName4);
});
console.info('open file failed with error message: ' + err.message + ', error code: ' + err.code);
commonEvent.publish(eventName7, (err) => {
console.log('Hap2MainAbility4' + eventName7);
});
});
}
}
let eventName5 : string = 'TerminateDone_Hap2MainAbility3';
let subscribeInfo = {
events: [eventName5]
}
let eventName6 : string = 'Temp_UriPermissionTest_0300_Read_Successfully_';
let eventName7 : string = 'Temp_UriPermissionTest_0300_Read_Failed_';
function SubscribeCallBackContext(err, data) {
console.log(' Subscribe CallBack data:' + JSON.stringify(data));
if (data.event === eventName5) {
globalThis.fs.open(uri, globalThis.fs.OpenMode.READ_ONLY).then((file) => {
console.info('file fd: ' + file.fd);
commonEvent.publish(eventName6, (err) => {
console.log('Hap2MainAbility4' + eventName6);
});
}).catch((err) => {
console.info('open file failed with error message: ' + err.message + ', error code: ' + err.code);
commonEvent.publish(eventName7, (err) => {
console.log('Hap2MainAbility4' + eventName7);
});
});
}
}
let subscriber__1;
commonEvent.createSubscriber(subscribeInfo).then(async (data) => {
subscriber__1 = data;
console.debug('====>Create Subscriber====>');
await commonEvent.subscribe(subscriber__1, SubscribeCallBackContext);
});
let subscriber__1;
commonEvent.createSubscriber(subscribeInfo).then(async (data) => {
subscriber__1 = data;
console.debug('====>Create Subscriber====>');
await commonEvent.subscribe(subscriber__1, SubscribeCallBackContext);
});
let eventName : string = 'TerminateSelf_Hap2MainAbility3';
commonEvent.publish(eventName, (err) => {
console.log('Hap2MainAbility4' + eventName);
});
}
let eventName : string = 'TerminateSelf_Hap2MainAbility3';
commonEvent.publish(eventName, (err) => {
console.log('Hap2MainAbility4' + eventName);
});
}
onBackground() {
console.log('[Demo] Hap2MainAbility4 onBackground')
}
onBackground() {
console.log('[Demo] Hap2MainAbility4 onBackground')
}
};
......@@ -17,89 +17,94 @@ import Ability from '@ohos.app.ability.UIAbility'
import commonEvent from '@ohos.commonEvent';
import fs from '@ohos.file.fs'
function sleep(time) {
return new Promise((resolve) => setTimeout(resolve, time))
}
export default class Hap3MainAbility1 extends Ability {
onCreate(want, launchParam) {
console.log('[Demo] Hap3MainAbility1 onCreate')
globalThis.abilityWant = want;
}
onCreate(want, launchParam) {
console.log('[Demo] Hap3MainAbility1 onCreate')
globalThis.abilityWant = want;
}
onDestroy() {
console.log('[Demo] Hap3MainAbility1 onDestroy')
}
onDestroy() {
console.log('[Demo] Hap3MainAbility1 onDestroy')
}
onWindowStageCreate(windowStage) {
console.log('[Demo] Hap3MainAbility1 onWindowStageCreate')
windowStage.setUIContent(this.context, 'pages/Hap3MainAbility1_pages', null)
}
onWindowStageCreate(windowStage) {
console.log('[Demo] Hap3MainAbility1 onWindowStageCreate')
windowStage.setUIContent(this.context, 'pages/Hap3MainAbility1_pages', null)
}
onWindowStageDestroy() {
console.log('[Demo] Hap3MainAbility1 onWindowStageDestroy')
}
onForeground() {
console.log('[Demo] Hap3MainAbility1 onForeground')
let eventName : string = 'TerminateNotify_Hap3MainAbility1';
let subscribeInfo = {
events: [eventName]
}
let subscriber_1;
function UnSubscribeInfoCallback_1(err, data) {
console.info("Hap2MainAbility1 ===UnSubscribeInfoCallback_1===")
}
onWindowStageDestroy() {
console.log('[Demo] Hap3MainAbility1 onWindowStageDestroy')
}
function SubscribeCallBackContext(err, data) {
console.log('Hap3MainAbility1 Subscribe CallBack data:' + JSON.stringify(data));
if (data.event === eventName) {
let uri : string = globalThis.abilityWant.uri;
if (uri == null) {
console.log('[Demo] Hap3MainAbility1 uri is invalid');
return;
}
console.info('[Demo] Hap3MainAbility1 uri is ' + JSON.stringify(uri));
let eventName13_1 : string = 'Temp_UriPermissionTest_1300_Read_Successfully';
let eventName13_2 : string = 'Temp_UriPermissionTest_1300_Read_Failed';
fs.open(uri, fs.OpenMode.READ_ONLY).then((file) => {
console.info('file fd: ' + file.fd);
commonEvent.publish(eventName13_1, (err) => {
console.log('Hap3MainAbility1' + eventName13_1);
});
}).catch((err) => {
console.info('open file failed with error message: ' + err.message + ', error code: ' + err.code);
commonEvent.publish(eventName13_2, (err) => {
console.log('Hap3MainAbility1' + eventName13_2);
});
});
onForeground() {
console.log('[Demo] Hap3MainAbility1 onForeground')
let eventName : string = 'TerminateNotify_Hap3MainAbility1';
let subscribeInfo = {
events: [eventName]
}
let subscriber_1;
function UnSubscribeInfoCallback_1(err, data) {
console.info("Hap2MainAbility1 ===UnSubscribeInfoCallback_1===")
}
let eventName13_3 : string = 'Temp_UriPermissionTest_1300_Write_Successfully';
let eventName13_4 : string = 'Temp_UriPermissionTest_1300_Write_Failed';
fs.open(uri, fs.OpenMode.READ_WRITE).then((file) => {
console.info('file fd: ' + file.fd);
commonEvent.publish(eventName13_3, (err) => {
console.log('Hap3MainAbility1' + eventName13_3);
});
}).catch((err) => {
console.info('open file failed with error message: ' + err.message + ', error code: ' + err.code);
commonEvent.publish(eventName13_4, (err) => {
console.log('Hap3MainAbility1' + eventName13_4);
});
});
}
commonEvent.unsubscribe(subscriber_1, UnSubscribeInfoCallback_1)
async function SubscribeCallBackContext(err, data) {
console.log('Hap3MainAbility1 Subscribe CallBack data:' + JSON.stringify(data));
if (data.event === eventName) {
await sleep(1000);
let uri : string = globalThis.abilityWant.uri;
if (uri == null) {
console.log('[Demo] Hap3MainAbility1 uri is invalid');
return;
}
commonEvent.createSubscriber(subscribeInfo).then(async (data) => {
subscriber_1 = data;
console.debug('====>Create Subscriber====>');
await commonEvent.subscribe(subscriber_1, SubscribeCallBackContext);
console.info('[Demo] Hap3MainAbility1 uri is ' + JSON.stringify(uri));
let eventName13_1 : string = 'Temp_UriPermissionTest_1300_Read_Successfully';
let eventName13_2 : string = 'Temp_UriPermissionTest_1300_Read_Failed';
fs.open(uri, fs.OpenMode.READ_ONLY).then((file) => {
console.info('file fd: ' + file.fd);
commonEvent.publish(eventName13_1, (err) => {
console.log('Hap3MainAbility1' + eventName13_1);
});
}).catch((err) => {
console.info('open file failed with error message: ' + err.message + ', error code: ' + err.code);
commonEvent.publish(eventName13_2, (err) => {
console.log('Hap3MainAbility1' + eventName13_2);
});
});
let eventName1 : string = 'RevicedFrom_Hap3MainAbility1';
commonEvent.publish(eventName1, (err) => {
console.log('Hap3MainAbility1' + eventName1);
let eventName13_3 : string = 'Temp_UriPermissionTest_1300_Write_Successfully';
let eventName13_4 : string = 'Temp_UriPermissionTest_1300_Write_Failed';
fs.open(uri, fs.OpenMode.READ_WRITE).then((file) => {
console.info('file fd: ' + file.fd);
commonEvent.publish(eventName13_3, (err) => {
console.log('Hap3MainAbility1' + eventName13_3);
});
}).catch((err) => {
console.info('open file failed with error message: ' + err.message + ', error code: ' + err.code);
commonEvent.publish(eventName13_4, (err) => {
console.log('Hap3MainAbility1' + eventName13_4);
});
});
}
commonEvent.unsubscribe(subscriber_1, UnSubscribeInfoCallback_1)
}
onBackground() {
console.log('[Demo] Hap3MainAbility1 onBackground')
}
commonEvent.createSubscriber(subscribeInfo).then(async (data) => {
subscriber_1 = data;
console.debug('====>Create Subscriber====>');
await commonEvent.subscribe(subscriber_1, SubscribeCallBackContext);
});
let eventName1 : string = 'RevicedFrom_Hap3MainAbility1';
commonEvent.publish(eventName1, (err) => {
console.log('Hap3MainAbility1' + eventName1);
});
}
onBackground() {
console.log('[Demo] Hap3MainAbility1 onBackground')
}
};
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册