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

!8829 修复uri临时授权xts

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