From f89d8f2ab71d2fb9a9d6c5f9b7fd033da5f72bfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BF=9E=E6=BC=AA?= Date: Sun, 25 May 2025 16:46:39 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=B5=8C=E5=85=A5=E5=BC=8F=E6=96=B0?= =?UTF-8?q?=E5=A2=9Eonreceive=E6=8E=A5=E5=8F=A3&=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E8=A7=84=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 连漪 --- .../interfaces/halfscreenlaunchcomponent.js | 79 +++++++++------ .../source/halfscreenlaunchcomponent.ets | 79 +++++++++------ .../innerfullscreenlaunchcomponent.js | 85 +++++++++++------ .../source/innerfullscreenlaunchcomponent.ets | 95 +++++++++++-------- 4 files changed, 214 insertions(+), 124 deletions(-) diff --git a/halfscreenlaunchcomponent/interfaces/halfscreenlaunchcomponent.js b/halfscreenlaunchcomponent/interfaces/halfscreenlaunchcomponent.js index d1a7933..6aa68e6 100644 --- a/halfscreenlaunchcomponent/interfaces/halfscreenlaunchcomponent.js +++ b/halfscreenlaunchcomponent/interfaces/halfscreenlaunchcomponent.js @@ -20,6 +20,10 @@ const hilog = requireNapi('hilog'); const abilityManager = requireNapi('app.ability.abilityManager'); const commonEventManager = requireNapi('commonEventManager'); const EMBEDDED_HALF_MODE = 2; +const atomicServiceDataTag = 'ohos.atomicService.window'; +const errCodeAbnormal = 100014; +const errCodeCapabilityNotSupported = 801; +const LOG_TAG = 'HalfScreenLaunchComponent'; export class HalfScreenLaunchComponent extends ViewPU { constructor(parent, params, __localStorage, elmtId = -1, paramsLambda = undefined, extraInfo) { super(parent, __localStorage, elmtId, extraInfo); @@ -34,6 +38,7 @@ export class HalfScreenLaunchComponent extends ViewPU { this.subscriber = null; this.onError = undefined; this.onTerminated = undefined; + this.onReceive = undefined; this.setInitiallyProvidedValue(params); this.finalizeConstruction(); } @@ -62,6 +67,9 @@ export class HalfScreenLaunchComponent extends ViewPU { if (params.onTerminated !== undefined) { this.onTerminated = params.onTerminated; } + if (params.onReceive !== undefined) { + this.onReceive = params.onReceive; + } } updateStateVars(params) { } @@ -85,17 +93,17 @@ export class HalfScreenLaunchComponent extends ViewPU { }; commonEventManager.createSubscriber(subscribeInfo, (err, data) => { if (err) { - hilog.error(0x3900, 'HalfScreenLaunchComponent', 'Failed to create subscriber, err: %{public}s.', JSON.stringify(err)); + hilog.error(0x3900, LOG_TAG, 'Failed to create subscriber, err: %{public}s.', JSON.stringify(err)); return; } if (data === null || data === undefined) { - hilog.error(0x3900, 'HalfScreenLaunchComponent', 'Failed to create subscriber, data is null.'); + hilog.error(0x3900, LOG_TAG, 'Failed to create subscriber, data is null.'); return; } this.subscriber = data; commonEventManager.subscribe(this.subscriber, (err, data) => { if (err) { - hilog.error(0x3900, 'HalfScreenLaunchComponent', 'Failed to subscribe common event, err: %{public}s.', JSON.stringify(err)); + hilog.error(0x3900, LOG_TAG, 'Failed to subscribe common event, err: %{public}s.', JSON.stringify(err)); return; } this.isShow = false; @@ -106,10 +114,10 @@ export class HalfScreenLaunchComponent extends ViewPU { if (this.subscriber !== null) { commonEventManager.unsubscribe(this.subscriber, (err) => { if (err) { - hilog.error(0x3900, 'HalfScreenLaunchComponent', 'UnsubscribeCallBack, err: %{public}s.', JSON.stringify(err)); + hilog.error(0x3900, LOG_TAG, 'UnsubscribeCallBack, err: %{public}s.', JSON.stringify(err)); } else { - hilog.info(0x3900, 'HalfScreenLaunchComponent', 'Unsubscribe.'); + hilog.info(0x3900, LOG_TAG, 'Unsubscribe.'); this.subscriber = null; } }); @@ -122,7 +130,7 @@ export class HalfScreenLaunchComponent extends ViewPU { this.options.parameters['ohos.extra.param.key.showMode'] = EMBEDDED_HALF_MODE; this.options.parameters['ability.want.params.IsNotifyOccupiedAreaChange'] = true; this.options.parameters['ability.want.params.IsModal'] = true; - hilog.info(0x3900, 'HalfScreenLaunchComponent', 'replaced options is %{public}s !', JSON.stringify(this.options)); + hilog.info(0x3900, LOG_TAG, 'replaced options is %{public}s !', JSON.stringify(this.options)); } else { this.options = { @@ -136,33 +144,34 @@ export class HalfScreenLaunchComponent extends ViewPU { } async checkAbility() { this.resetOptions(); - try { - const res = await abilityManager.isEmbeddedOpenAllowed(this.context, this.appId); - if (res) { - if (this.isShow) { - this.isShow = false; - hilog.error(0x3900, 'HalfScreenLaunchComponent', ' EmbeddedOpen is already show!'); - return; + abilityManager.queryAtomicServiceStartupRule(this.context, this.appId) + .then((data) => { + if (data.isOpenAllowed) { + if (data.isEmbeddedAllowed) { + this.isShow = true; + hilog.info(0x3900, LOG_TAG, 'EmbeddedOpen is Allowed!'); + } else { + this.popUp(); + hilog.info(0x3900, LOG_TAG, 'popUp is Allowed!'); } - this.isShow = true; - hilog.info(0x3900, 'HalfScreenLaunchComponent', ' EmbeddedOpen is Allowed!'); + } else { + hilog.info(0x3900, LOG_TAG, 'is not allowed open!'); } - else { - this.popUp(); + }).catch((err) => { + hilog.error(0x3900, LOG_TAG, 'queryAtomicServiceStartupRule called error!%{public}s', err.message); + if (errCodeCapabilityNotSupported === err.code) { + this.popUp(); } - } - catch (e) { - hilog.error(0x3900, 'HalfScreenLaunchComponent', 'isEmbeddedOpenAllowed called error!%{public}s', e.message); - } + }); } async popUp() { this.isShow = false; try { const ability = await this.context.openAtomicService(this.appId, this.options); - hilog.info(0x3900, 'HalfScreenLaunchComponent', '%{public}s open service success!', ability.want); + hilog.info(0x3900, LOG_TAG, '%{public}s open service success!', ability.want); } catch (e) { - hilog.error(0x3900, 'HalfScreenLaunchComponent', '%{public}s open service error!', e.message); + hilog.error(0x3900, LOG_TAG, '%{public}s open service error!', e.message); } } initialRender() { @@ -170,7 +179,7 @@ export class HalfScreenLaunchComponent extends ViewPU { Row.create(); Row.justifyContent(FlexAlign.Center); Row.onClick(() => { - hilog.info(0x3900, 'HalfScreenLaunchComponent', 'on start atomicservice'); + hilog.info(0x3900, LOG_TAG, 'on start atomicservice'); this.checkAbility(); }); Row.bindContentCover({ value: this.isShow, changeEvent: newValue => { this.isShow = newValue; } }, { builder: () => { @@ -198,10 +207,12 @@ export class HalfScreenLaunchComponent extends ViewPU { this.onError(err); } this.isShow = false; - hilog.error(0x3900, 'HalfScreenLaunchComponent', 'call up UIExtension error!%{public}s', err.message); - this.getUIContext().showAlertDialog({ - message: err.message - }); + hilog.error(0x3900, LOG_TAG, 'call up UIExtension error!%{public}s', err.message); + if (err.code != errCodeAbnormal) { + this.getUIContext().showAlertDialog({ + message: err.message + }); + } }); UIExtensionComponent.onTerminated(info => { this.isShow = false; @@ -209,6 +220,18 @@ export class HalfScreenLaunchComponent extends ViewPU { this.onTerminated(info); } }); + UIExtensionComponent.onReceive(data => { + if (this.onReceive !== undefined) { + const sourceKeys = Object.keys(data); + let atomicServiceData = {}; + for (let i = 0; i < sourceKeys.length; i++) { + if (sourceKeys[i].includes(atomicServiceDataTag)) { + atomicServiceData[sourceKeys[i]] = data[sourceKeys[i]]; + } + } + this.onReceive(atomicServiceData); + } + }); }, UIExtensionComponent); } rerender() { diff --git a/halfscreenlaunchcomponent/source/halfscreenlaunchcomponent.ets b/halfscreenlaunchcomponent/source/halfscreenlaunchcomponent.ets index 4abb047..a217439 100644 --- a/halfscreenlaunchcomponent/source/halfscreenlaunchcomponent.ets +++ b/halfscreenlaunchcomponent/source/halfscreenlaunchcomponent.ets @@ -21,6 +21,11 @@ import commonEventManager from '@ohos.commonEventManager'; import Base from '@ohos.base'; const EMBEDDED_HALF_MODE = 2; +const atomicServiceDataTag: string = 'ohos.atomicService.window'; +const errCodeAbnormal: number = 100014; +const errCodeCapabilityNotSupported: number = 801; +const LOG_TAG: string = 'HalfScreenLaunchComponent'; + @Component export struct HalfScreenLaunchComponent { @BuilderParam content: Callback = this.doNothingBuilder; @@ -31,6 +36,7 @@ export struct HalfScreenLaunchComponent { private subscriber: commonEventManager.CommonEventSubscriber | null = null; onError?: ErrorCallback; onTerminated?: Callback; + onReceive?: Callback>; aboutToAppear(): void { let subscribeInfo: commonEventManager.CommonEventSubscribeInfo = { @@ -40,13 +46,13 @@ export struct HalfScreenLaunchComponent { commonEventManager.createSubscriber(subscribeInfo, (err: Base.BusinessError, data: commonEventManager.CommonEventSubscriber) => { if (err) { - hilog.error(0x3900, 'HalfScreenLaunchComponent', + hilog.error(0x3900, LOG_TAG, 'Failed to create subscriber, err: %{public}s.', JSON.stringify(err)); return; } if (data === null || data === undefined) { - hilog.error(0x3900, 'HalfScreenLaunchComponent', 'Failed to create subscriber, data is null.'); + hilog.error(0x3900, LOG_TAG, 'Failed to create subscriber, data is null.'); return; } @@ -54,7 +60,7 @@ export struct HalfScreenLaunchComponent { commonEventManager.subscribe(this.subscriber, (err: Base.BusinessError, data: commonEventManager.CommonEventData) => { if (err) { - hilog.error(0x3900, 'HalfScreenLaunchComponent', + hilog.error(0x3900, LOG_TAG, 'Failed to subscribe common event, err: %{public}s.', JSON.stringify(err)); return; } @@ -67,10 +73,10 @@ export struct HalfScreenLaunchComponent { if (this.subscriber !== null) { commonEventManager.unsubscribe(this.subscriber, (err) => { if (err) { - hilog.error(0x3900, 'HalfScreenLaunchComponent', + hilog.error(0x3900, LOG_TAG, 'UnsubscribeCallBack, err: %{public}s.', JSON.stringify(err)); } else { - hilog.info(0x3900, 'HalfScreenLaunchComponent', 'Unsubscribe.'); + hilog.info(0x3900, LOG_TAG, 'Unsubscribe.'); this.subscriber = null; } }) @@ -86,7 +92,7 @@ export struct HalfScreenLaunchComponent { this.options.parameters['ohos.extra.param.key.showMode'] = EMBEDDED_HALF_MODE; this.options.parameters['ability.want.params.IsNotifyOccupiedAreaChange'] = true; this.options.parameters['ability.want.params.IsModal'] = true; - hilog.info(0x3900, 'HalfScreenLaunchComponent', 'replaced options is %{public}s !', JSON.stringify(this.options)); + hilog.info(0x3900, LOG_TAG, 'replaced options is %{public}s !', JSON.stringify(this.options)); } else { this.options = { parameters: { @@ -100,31 +106,34 @@ export struct HalfScreenLaunchComponent { async checkAbility(): void { this.resetOptions(); - try { - const res: boolean = await abilityManager.isEmbeddedOpenAllowed(this.context, this.appId); - if (res) { - if (this.isShow) { - this.isShow = false; - hilog.error(0x3900, 'HalfScreenLaunchComponent', ' EmbeddedOpen is already show!'); - return; + abilityManager.queryAtomicServiceStartupRule(this.context, this.appId) + .then((data: abilityManager.AtomicServiceStartupRule) => { + if (data.isOpenAllowed) { + if (data.isEmbeddedAllowed) { + this.isShow = true; + hilog.info(0x3900, LOG_TAG, 'EmbeddedOpen is Allowed!'); + } else { + this.popUp(); + hilog.info(0x3900, LOG_TAG, 'popUp is Allowed!'); + } + } else { + hilog.info(0x3900, LOG_TAG, 'is not allowed open!'); } - this.isShow = true; - hilog.info(0x3900, 'HalfScreenLaunchComponent', ' EmbeddedOpen is Allowed!'); - } else { - this.popUp(); - } - } catch (e) { - hilog.error(0x3900, 'HalfScreenLaunchComponent', 'isEmbeddedOpenAllowed called error!%{public}s', e.message); - } + }).catch((err: BusinessError) => { + hilog.error(0x3900, LOG_TAG, 'queryAtomicServiceStartupRule called error!%{public}s', err.message); + if (errCodeCapabilityNotSupported === err.code) { + this.popUp(); + } + }); } async popUp(): void { this.isShow = false; try { const ability = await this.context.openAtomicService(this.appId, this.options); - hilog.info(0x3900, 'HalfScreenLaunchComponent', '%{public}s open service success!', ability.want); + hilog.info(0x3900, LOG_TAG, '%{public}s open service success!', ability.want); } catch (e) { - hilog.error(0x3900, 'HalfScreenLaunchComponent', '%{public}s open service error!', e.message); + hilog.error(0x3900, LOG_TAG, '%{public}s open service error!', e.message); } } @@ -134,7 +143,7 @@ export struct HalfScreenLaunchComponent { }.justifyContent(FlexAlign.Center) .onClick( () => { - hilog.info(0x3900, 'HalfScreenLaunchComponent', 'on start atomicservice'); + hilog.info(0x3900, LOG_TAG, 'on start atomicservice'); this.checkAbility(); } ).bindContentCover($$this.isShow, this.uiExtensionBuilder(), { modalTransition: ModalTransition.NONE }); @@ -160,10 +169,12 @@ export struct HalfScreenLaunchComponent { this.onError(err); } this.isShow = false; - hilog.error(0x3900, 'HalfScreenLaunchComponent', 'call up UIExtension error!%{public}s', err.message); - this.getUIContext().showAlertDialog({ - message: err.message - }); + hilog.error(0x3900, LOG_TAG, 'call up UIExtension error!%{public}s', err.message); + if (err.code != errCodeAbnormal) { + this.getUIContext().showAlertDialog({ + message: err.message + }); + } } ) .onTerminated(info => { @@ -172,5 +183,17 @@ export struct HalfScreenLaunchComponent { this.onTerminated(info); } }) + .onReceive(data => { + if (this.onReceive !== undefined) { + const sourceKeys = Object.keys(data); + let atomicServiceData: Record = {}; + for (let i = 0; i < sourceKeys.length; i++) { + if (sourceKeys[i].includes(atomicServiceDataTag)) { + atomicServiceData[sourceKeys[i]] = data[sourceKeys[i]]; + } + } + this.onReceive(atomicServiceData); + } + }) } } \ No newline at end of file diff --git a/innerfullscreenlaunchcomponent/interfaces/innerfullscreenlaunchcomponent.js b/innerfullscreenlaunchcomponent/interfaces/innerfullscreenlaunchcomponent.js index 00a9510..758e047 100644 --- a/innerfullscreenlaunchcomponent/interfaces/innerfullscreenlaunchcomponent.js +++ b/innerfullscreenlaunchcomponent/interfaces/innerfullscreenlaunchcomponent.js @@ -26,6 +26,11 @@ export class LaunchController { } const EMBEDDED_FULL_MODE = 1; +const atomicServiceDataTag = 'ohos.atomicService.window'; +const errCodeAbnormal = 100014; +const errCodeCapabilityNotSupported = 801; +const LOG_TAG = 'InnerFullScreenLaunchComponent'; + export class InnerFullScreenLaunchComponent extends ViewPU { constructor(d1, e1, f1, g1 = -1, h1 = undefined, i1) { super(d1, f1, g1, i1); @@ -39,8 +44,9 @@ export class InnerFullScreenLaunchComponent extends ViewPU { this.options = undefined; this.__isShow = new ObservedPropertySimplePU(false, this, "isShow"); this.subscriber = null; + this.onReceive = undefined; this.launchAtomicService = (k1, l1) => { - hilog.info(0x3900, 'InnerFullScreenLaunchComponent', 'launchAtomicService, appId: %{public}s.', k1); + hilog.info(0x3900, LOG_TAG, 'launchAtomicService, appId: %{public}s.', k1); this.appId = k1; this.options = l1; this.checkAbility(); @@ -73,6 +79,9 @@ export class InnerFullScreenLaunchComponent extends ViewPU { if (c1.launchAtomicService !== undefined) { this.launchAtomicService = c1.launchAtomicService; } + if (c1.onReceive !== undefined) { + this.onReceive = c1.onReceive; + } } updateStateVars(b1) { } @@ -96,20 +105,20 @@ export class InnerFullScreenLaunchComponent extends ViewPU { }; commonEventManager.createSubscriber(s, (u, v) => { if (u) { - hilog.error(0x3900, 'InnerFullScreenLaunchComponent', 'Failed to create subscriber, err: %{public}s.', u.message); + hilog.error(0x3900, LOG_TAG, 'Failed to create subscriber, err: %{public}s.', u.message); return; } if (v == null || v == undefined) { - hilog.error(0x3900, 'InnerFullScreenLaunchComponent', 'Failed to create subscriber, data is null.'); + hilog.error(0x3900, LOG_TAG, 'Failed to create subscriber, data is null.'); return; } this.subscriber = v; commonEventManager.subscribe(this.subscriber, (x, y) => { if (x) { - hilog.error(0x3900, 'InnerFullScreenLaunchComponent', 'Failed to subscribe common event, err: %{public}s.', x.message); + hilog.error(0x3900, LOG_TAG, 'Failed to subscribe common event, err: %{public}s.', x.message); return; } - hilog.info(0x3900, 'InnerFullScreenLaunchComponent', 'Received account logout event.'); + hilog.info(0x3900, LOG_TAG, 'Received account logout event.'); this.isShow = false; }); }); @@ -119,10 +128,10 @@ export class InnerFullScreenLaunchComponent extends ViewPU { if (this.subscriber !== null) { commonEventManager.unsubscribe(this.subscriber, (r) => { if (r) { - hilog.error(0x3900, 'InnerFullScreenLaunchComponent', 'UnsubscribeCallBack, err: %{public}s.', r.message); + hilog.error(0x3900, LOG_TAG, 'UnsubscribeCallBack, err: %{public}s.', r.message); } else { - hilog.info(0x3900, 'InnerFullScreenLaunchComponent', 'Unsubscribe.'); + hilog.info(0x3900, LOG_TAG, 'Unsubscribe.'); this.subscriber = null; } }); @@ -134,7 +143,7 @@ export class InnerFullScreenLaunchComponent extends ViewPU { if (this.options?.parameters) { this.options.parameters['ohos.extra.param.key.showMode'] = EMBEDDED_FULL_MODE; this.options.parameters['ability.want.params.IsNotifyOccupiedAreaChange'] = true; - hilog.info(0x3900, 'InnerFullScreenLaunchComponent', 'replaced options is %{public}s !', JSON.stringify(this.options)); + hilog.info(0x3900, LOG_TAG, 'replaced options is %{public}s !', JSON.stringify(this.options)); } else { this.options = { @@ -147,34 +156,34 @@ export class InnerFullScreenLaunchComponent extends ViewPU { } async checkAbility() { this.resetOptions(); - try { - const o = await abilityManager.isEmbeddedOpenAllowed(this.context, this.appId); - if (o) { - if (this.isShow) { - hilog.error(0x3900, 'InnerFullScreenLaunchComponent', ' EmbeddedAbility already shows'); - this.isShow = false; - return; + abilityManager.queryAtomicServiceStartupRule(this.context, this.appId) + .then((data) => { + if (data.isOpenAllowed) { + if (data.isEmbeddedAllowed) { + this.isShow = true; + hilog.info(0x3900, LOG_TAG, 'EmbeddedOpen is Allowed!'); + } else { + this.popUp(); + hilog.info(0x3900, LOG_TAG, 'popUp is Allowed!'); } - this.isShow = true; - hilog.info(0x3900, 'InnerFullScreenLaunchComponent', ' EmbeddedOpen is Allowed!'); + } else { + hilog.info(0x3900, LOG_TAG, 'is not allowed open!'); } - else { - hilog.info(0x3900, 'InnerFullScreenLaunchComponent', ' EmbeddedOpen is not Allowed!'); - this.popUp(); + }).catch((err) => { + hilog.error(0x3900, LOG_TAG, 'queryAtomicServiceStartupRule called error!%{public}s', err.message); + if (errCodeCapabilityNotSupported === err.code) { + this.popUp(); } - } - catch (n) { - hilog.error(0x3900, 'InnerFullScreenLaunchComponent', 'isEmbeddedOpenAllowed called error!%{public}s', n.message); - } + }); } async popUp() { this.isShow = false; try { const m = await this.context.openAtomicService(this.appId, this.options); - hilog.info(0x3900, 'InnerFullScreenLaunchComponent', '%{public}s open service success!', m.want); + hilog.info(0x3900, LOG_TAG, '%{public}s open service success!', m.want); } catch (l) { - hilog.error(0x3900, 'InnerFullScreenLaunchComponent', '%{public}s open service error!', l.message); + hilog.error(0x3900, LOG_TAG, '%{public}s open service error!', l.message); } } initialRender() { @@ -200,15 +209,29 @@ export class InnerFullScreenLaunchComponent extends ViewPU { UIExtensionComponent.height('100%'); UIExtensionComponent.width('100%'); UIExtensionComponent.onRelease(() => { - hilog.error(0x3900, 'InnerFullScreenLaunchComponent', 'onRelease'); + hilog.error(0x3900, LOG_TAG, 'onRelease'); this.isShow = false; }); UIExtensionComponent.onError(g => { this.isShow = false; - hilog.error(0x3900, 'InnerFullScreenLaunchComponent', 'call up UIExtension error!%{public}s', g.message); - this.getUIContext().showAlertDialog({ - message: g.message - }); + hilog.error(0x3900, LOG_TAG, 'call up UIExtension error!%{public}s', g.message); + if (err.code != errCodeAbnormal) { + this.getUIContext().showAlertDialog({ + message: g.message + }); + } + }); + UIExtensionComponent.onReceive(data => { + if (this.onReceive !== undefined) { + const sourceKeys = Object.keys(data); + let atomicServiceData = {}; + for (let i = 0; i < sourceKeys.length; i++) { + if (sourceKeys[i].includes(atomicServiceDataTag)) { + atomicServiceData[sourceKeys[i]] = data[sourceKeys[i]]; + } + } + this.onReceive(atomicServiceData); + } }); }, UIExtensionComponent); } diff --git a/innerfullscreenlaunchcomponent/source/innerfullscreenlaunchcomponent.ets b/innerfullscreenlaunchcomponent/source/innerfullscreenlaunchcomponent.ets index e5e6d00..17678f8 100644 --- a/innerfullscreenlaunchcomponent/source/innerfullscreenlaunchcomponent.ets +++ b/innerfullscreenlaunchcomponent/source/innerfullscreenlaunchcomponent.ets @@ -25,7 +25,10 @@ export class LaunchController { } const EMBEDDED_FULL_MODE: number = 1; - +const atomicServiceDataTag: string = 'ohos.atomicService.window'; +const errCodeAbnormal: number = 100014; +const errCodeCapabilityNotSupported: number = 801; +const LOG_TAG: string = 'InnerFullScreenLaunchComponent'; @Component export struct InnerFullScreenLaunchComponent { @BuilderParam content: Callback = this.doNothingBuilder; @@ -36,12 +39,12 @@ export struct InnerFullScreenLaunchComponent { @State private isShow: boolean = false; private subscriber: commonEventManager.CommonEventSubscriber | null = null; private launchAtomicService = (appId: string, options?: AtomicServiceOptions) => { - hilog.info(0x3900, 'InnerFullScreenLaunchComponent', - 'launchAtomicService, appId: %{public}s.', appId); + hilog.info(0x3900, LOG_TAG, 'launchAtomicService, appId: %{public}s.', appId); this.appId = appId; this.options = options; this.checkAbility(); } + onReceive?: Callback>; aboutToAppear() { let subscribeInfo: commonEventManager.CommonEventSubscribeInfo = { @@ -51,13 +54,13 @@ export struct InnerFullScreenLaunchComponent { commonEventManager.createSubscriber(subscribeInfo, (err:Base.BusinessError, data: commonEventManager.CommonEventSubscriber) => { if (err) { - hilog.error(0x3900, 'InnerFullScreenLaunchComponent', + hilog.error(0x3900, LOG_TAG, 'Failed to create subscriber, err: %{public}s.', err.message); return; } if (data == null || data == undefined) { - hilog.error(0x3900, 'InnerFullScreenLaunchComponent', 'Failed to create subscriber, data is null.'); + hilog.error(0x3900, LOG_TAG, 'Failed to create subscriber, data is null.'); return; } @@ -65,12 +68,12 @@ export struct InnerFullScreenLaunchComponent { commonEventManager.subscribe(this.subscriber, (err: Base.BusinessError, data: commonEventManager.CommonEventData) => { if (err) { - hilog.error(0x3900, 'InnerFullScreenLaunchComponent', + hilog.error(0x3900, LOG_TAG, 'Failed to subscribe common event, err: %{public}s.', err.message); return; } - hilog.info(0x3900, 'InnerFullScreenLaunchComponent', 'Received account logout event.'); + hilog.info(0x3900, LOG_TAG, 'Received account logout event.'); this.isShow = false; }) }) @@ -81,10 +84,10 @@ export struct InnerFullScreenLaunchComponent { if (this.subscriber !== null) { commonEventManager.unsubscribe(this.subscriber, (err) => { if (err) { - hilog.error(0x3900, 'InnerFullScreenLaunchComponent', + hilog.error(0x3900, LOG_TAG, 'UnsubscribeCallBack, err: %{public}s.', err.message); } else { - hilog.info(0x3900, 'InnerFullScreenLaunchComponent', 'Unsubscribe.'); + hilog.info(0x3900, LOG_TAG, 'Unsubscribe.'); this.subscriber = null; } }) @@ -99,7 +102,7 @@ export struct InnerFullScreenLaunchComponent { if (this.options?.parameters) { this.options.parameters['ohos.extra.param.key.showMode'] = EMBEDDED_FULL_MODE; this.options.parameters['ability.want.params.IsNotifyOccupiedAreaChange'] = true; - hilog.info(0x3900, 'InnerFullScreenLaunchComponent', 'replaced options is %{public}s !', JSON.stringify(this.options)); + hilog.info(0x3900, LOG_TAG, 'replaced options is %{public}s !', JSON.stringify(this.options)); } else { this.options = { parameters: { @@ -112,32 +115,34 @@ export struct InnerFullScreenLaunchComponent { async checkAbility() { this.resetOptions(); - try { - const res: boolean = await abilityManager.isEmbeddedOpenAllowed(this.context, this.appId); - if (res) { - if (this.isShow) { - hilog.error(0x3900, 'InnerFullScreenLaunchComponent', ' EmbeddedAbility already shows'); - this.isShow = false; - return; + abilityManager.queryAtomicServiceStartupRule(this.context, this.appId) + .then((data: abilityManager.AtomicServiceStartupRule) => { + if (data.isOpenAllowed) { + if (data.isEmbeddedAllowed) { + this.isShow = true; + hilog.info(0x3900, LOG_TAG, 'EmbeddedOpen is Allowed!'); + } else { + this.popUp(); + hilog.info(0x3900, LOG_TAG, 'popUp is Allowed!'); + } + } else { + hilog.info(0x3900, LOG_TAG, 'is not allowed open!'); } - this.isShow = true; - hilog.info(0x3900, 'InnerFullScreenLaunchComponent', ' EmbeddedOpen is Allowed!'); - } else { - hilog.info(0x3900, 'InnerFullScreenLaunchComponent', ' EmbeddedOpen is not Allowed!'); - this.popUp(); - } - } catch (e) { - hilog.error(0x3900, 'InnerFullScreenLaunchComponent', 'isEmbeddedOpenAllowed called error!%{public}s', e.message); - } + }).catch((err: BusinessError) => { + hilog.error(0x3900, LOG_TAG, 'queryAtomicServiceStartupRule called error!%{public}s', err.message); + if (errCodeCapabilityNotSupported === err.code) { + this.popUp(); + } + }); } async popUp() { this.isShow = false; try { const ability = await this.context.openAtomicService(this.appId, this.options); - hilog.info(0x3900, 'InnerFullScreenLaunchComponent', '%{public}s open service success!', ability.want); + hilog.info(0x3900, LOG_TAG, '%{public}s open service success!', ability.want); } catch (e) { - hilog.error(0x3900, 'InnerFullScreenLaunchComponent', '%{public}s open service error!', e.message); + hilog.error(0x3900, LOG_TAG, '%{public}s open service error!', e.message); } } @@ -162,17 +167,33 @@ export struct InnerFullScreenLaunchComponent { .width('100%') .onRelease( () => { - hilog.error(0x3900, 'InnerFullScreenLaunchComponent', 'onRelease'); + hilog.error(0x3900, LOG_TAG, 'onRelease'); + this.isShow = false; + } + ) + .onError( + err => { this.isShow = false; + hilog.error(0x3900, LOG_TAG, 'call up UIExtension error! %{public}s', err.message); + if (err.code != errCodeAbnormal) { + this.getUIContext().showAlertDialog({ + message: err.message + }); + } } - ).onError( - err => { - this.isShow = false; - hilog.error(0x3900, 'InnerFullScreenLaunchComponent', 'call up UIExtension error! %{public}s', err.message); - this.getUIContext().showAlertDialog({ - message: err.message - }); - } + ) + .onReceive(data => { + if (this.onReceive !== undefined) { + const sourceKeys = Object.keys(data); + let atomicServiceData: Record = {}; + for (let i = 0; i < sourceKeys.length; i++) { + if (sourceKeys[i].includes(atomicServiceDataTag)) { + atomicServiceData[sourceKeys[i]] = data[sourceKeys[i]]; + } + } + this.onReceive(atomicServiceData); + } + }) ) } } \ No newline at end of file -- Gitee From b5df561c4f00c3026c4e05aa708b746c08a48c76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BF=9E=E6=BC=AA?= Date: Mon, 9 Jun 2025 22:01:18 +0800 Subject: [PATCH 2/2] =?UTF-8?q?asweb=E6=96=B0=E5=A2=9E=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E5=92=8C=E6=94=AF=E4=BB=98=E6=89=93=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 连漪 --- atomicserviceweb/interfaces/atomicserviceweb.js | 2 +- atomicserviceweb/source/atomicserviceweb.ets | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/atomicserviceweb/interfaces/atomicserviceweb.js b/atomicserviceweb/interfaces/atomicserviceweb.js index 0e948d9..a762542 100644 --- a/atomicserviceweb/interfaces/atomicserviceweb.js +++ b/atomicserviceweb/interfaces/atomicserviceweb.js @@ -128,7 +128,7 @@ const LOGIN_STATE_INVALID_ERROR = new AsError(200017, 'Login state is invalid.') const LOGIN_RESPONSE_DATA_NULL_ERROR = new AsError(200018, 'Response data is null.'); const REQUEST_PAYMENT_ORDER_STR_INVALID_ERROR = new AsError(200019, 'orderStr is not type string.'); const NEED_REPORTED_API_LIST = ['has.cameraPicker.pick', 'has.photoViewPicker.select', 'has.filePreview.openPreview', 'has.request.uploadFile', 'has.request.downloadFile', - 'has.connection.getNetworkType', 'has.location.getLocation']; + 'has.connection.getNetworkType', 'has.location.getLocation', 'has.account.login', 'has.payment.requestPayment']; registerJsApi('router.pushUrl', 'pushUrl', '1.0.0', MAX_VERSION, ['url']); registerJsApi('router.replaceUrl', 'replaceUrl', '1.0.0', MAX_VERSION, ['url']); registerJsApi('router.back', 'backUrl', '1.0.0', MAX_VERSION, []); diff --git a/atomicserviceweb/source/atomicserviceweb.ets b/atomicserviceweb/source/atomicserviceweb.ets index 7772793..c1612a1 100644 --- a/atomicserviceweb/source/atomicserviceweb.ets +++ b/atomicserviceweb/source/atomicserviceweb.ets @@ -124,7 +124,7 @@ const LOGIN_RESPONSE_DATA_NULL_ERROR: AsError = new AsError(200018, 'Response da const REQUEST_PAYMENT_ORDER_STR_INVALID_ERROR: AsError = new AsError(200019, 'orderStr is not type string.'); const NEED_REPORTED_API_LIST: string[] = ['has.cameraPicker.pick', 'has.photoViewPicker.select', 'has.filePreview.openPreview', 'has.request.uploadFile', 'has.request.downloadFile', - 'has.connection.getNetworkType', 'has.location.getLocation']; + 'has.connection.getNetworkType', 'has.location.getLocation', 'has.account.login', 'has.payment.requestPayment']; registerJsApi('router.pushUrl', 'pushUrl', '1.0.0', MAX_VERSION, ['url']); registerJsApi('router.replaceUrl', 'replaceUrl', '1.0.0', MAX_VERSION, ['url']); -- Gitee