From 7f1489c73a0d850e9ce693853e5517a4660110c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BF=9E=E6=BC=AA?= Date: Sat, 21 Jun 2025 11:44:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B5=8C=E5=85=A5=E5=BC=8F=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E6=8B=89=E8=B5=B7=E7=AE=A1=E6=8E=A7=E8=83=BD=E5=8A=9B=E5=A2=9E?= =?UTF-8?q?=E5=BC=BA?= 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 | 77 ++++++++++------- .../innerfullscreenlaunchcomponent.js | 75 ++++++++++------- .../source/innerfullscreenlaunchcomponent.ets | 82 +++++++++++-------- 4 files changed, 185 insertions(+), 128 deletions(-) diff --git a/halfscreenlaunchcomponent/interfaces/halfscreenlaunchcomponent.js b/halfscreenlaunchcomponent/interfaces/halfscreenlaunchcomponent.js index 31a5d0f..090492f 100644 --- a/halfscreenlaunchcomponent/interfaces/halfscreenlaunchcomponent.js +++ b/halfscreenlaunchcomponent/interfaces/halfscreenlaunchcomponent.js @@ -21,6 +21,9 @@ const abilityManager = requireNapi('app.ability.abilityManager'); const commonEventManager = requireNapi('commonEventManager'); const EMBEDDED_HALF_MODE = 2; const atomicServiceDataTag = 'ohos.atomicService.window'; +const ERR_CODE_ABNORMAL = 100014; +const ERR_CODE_CAPABILITY_NOT_SUPPORT = 801; +const LOG_TAG = 'HalfScreenLaunchComponent'; export class HalfScreenLaunchComponent extends ViewPU { constructor(parent, params, __localStorage, elmtId = -1, paramsLambda = undefined, extraInfo) { super(parent, __localStorage, elmtId, extraInfo); @@ -90,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; @@ -111,10 +114,9 @@ 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.'); this.subscriber = null; } }); @@ -127,7 +129,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 = { @@ -140,34 +142,43 @@ export class HalfScreenLaunchComponent extends ViewPU { } } async checkAbility() { + if (this.isShow) { + hilog.error(0x3900, LOG_TAG, 'EmbeddedAbility already shows'); + this.isShow = false; + return; + } 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; - } - 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); + 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(); + } + } else { + hilog.info(0x3900, LOG_TAG, 'is not allowed open!'); + } + }).catch((err) => { + hilog.error(0x3900, LOG_TAG, 'queryAtomicServiceStartupRule called error!%{public}s', err.message); + if (ERR_CODE_CAPABILITY_NOT_SUPPORT === err.code) { + this.popUp(); + } + }); + } catch (err) { + hilog.error(0x3900, LOG_TAG, 'AtomicServiceStartupRule failed: %{public}s', err.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); } } handleOnReceiveEvent(data) { @@ -179,7 +190,7 @@ export class HalfScreenLaunchComponent extends ViewPU { let atomicServiceData = {}; for (let i = 0; i < sourceKeys.length; i++) { if (sourceKeys[i].includes(atomicServiceDataTag)) { - atomicServiceData[sourceKeys[i]] = data[sourceKeys[i]]; + atomicServiceData[sourceKeys[i]] = data[sourceKeys[i]]; } } this.onReceive(atomicServiceData); @@ -190,12 +201,14 @@ 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: () => { + Row.bindContentCover({ value: this.isShow, changeEvent: newValue => { this.isShow = newValue; } }, { + builder: () => { this.uiExtensionBuilder.call(this); - } }, { modalTransition: ModalTransition.NONE }); + } + }, { modalTransition: ModalTransition.NONE }); }, Row); this.content.bind(this)(); Row.pop(); @@ -218,10 +231,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 !== ERR_CODE_ABNORMAL) { + this.getUIContext().showAlertDialog({ + message: err.message + }); + } }); UIExtensionComponent.onTerminated(info => { this.isShow = false; diff --git a/halfscreenlaunchcomponent/source/halfscreenlaunchcomponent.ets b/halfscreenlaunchcomponent/source/halfscreenlaunchcomponent.ets index dfd4a3b..45f07ae 100644 --- a/halfscreenlaunchcomponent/source/halfscreenlaunchcomponent.ets +++ b/halfscreenlaunchcomponent/source/halfscreenlaunchcomponent.ets @@ -15,13 +15,16 @@ import hilog from '@ohos.hilog'; import abilityManager from '@ohos.app.ability.abilityManager'; import common from '@ohos.app.ability.common'; -import { ErrorCallback, Callback } from '@ohos.base'; +import { ErrorCallback, Callback, BusinessError } from '@ohos.base'; import AtomicServiceOptions from '@ohos.app.ability.AtomicServiceOptions'; import commonEventManager from '@ohos.commonEventManager'; import Base from '@ohos.base'; const EMBEDDED_HALF_MODE = 2; const atomicServiceDataTag: string = 'ohos.atomicService.window'; +const ERR_CODE_ABNORMAL: number = 100014; +const ERR_CODE_CAPABILITY_NOT_SUPPORT: number = 801; +const LOG_TAG: string = 'HalfScreenLaunchComponent'; @Component export struct HalfScreenLaunchComponent { @BuilderParam content: Callback = this.doNothingBuilder; @@ -42,13 +45,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; } @@ -56,7 +59,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; } @@ -69,10 +72,9 @@ 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.'); this.subscriber = null; } }) @@ -88,7 +90,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,33 +102,44 @@ export struct HalfScreenLaunchComponent { } } - async checkAbility(): void { + async checkAbility(): Promise { + if (this.isShow) { + hilog.error(0x3900, LOG_TAG, 'EmbeddedAbility already shows'); + this.isShow = false; + return; + } 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; - } - 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); - } + 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(); + } + } else { + hilog.info(0x3900, LOG_TAG, 'is not allowed open!'); + } + }).catch((err: BusinessError) => { + hilog.error(0x3900, LOG_TAG, 'queryAtomicServiceStartupRule called error!%{public}s', err.message); + if (ERR_CODE_CAPABILITY_NOT_SUPPORT === err.code) { + this.popUp(); + } + }); + } catch (err: BusinessError) { + hilog.error(0x3900, LOG_TAG, 'AtomicServiceStartupRule failed: %{public}s', err.message); + } } - async popUp(): void { + async popUp(): Promise { 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); } } @@ -152,7 +165,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 }); @@ -178,10 +191,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 !== ERR_CODE_ABNORMAL) { + this.getUIContext().showAlertDialog({ + message: err.message + }); + } } ) .onTerminated(info => { diff --git a/innerfullscreenlaunchcomponent/interfaces/innerfullscreenlaunchcomponent.js b/innerfullscreenlaunchcomponent/interfaces/innerfullscreenlaunchcomponent.js index 6f74e03..b45f5f4 100644 --- a/innerfullscreenlaunchcomponent/interfaces/innerfullscreenlaunchcomponent.js +++ b/innerfullscreenlaunchcomponent/interfaces/innerfullscreenlaunchcomponent.js @@ -20,6 +20,9 @@ const hilog = requireNapi('hilog'); const abilityManager = requireNapi('app.ability.abilityManager'); const commonEventManager = requireNapi('commonEventManager'); const atomicServiceDataTag = 'ohos.atomicService.window'; +const ERR_CODE_ABNORMAL = 100014; +const ERR_CODE_CAPABILITY_NOT_SUPPORT = 801; +const LOG_TAG = 'InnerFullScreenLaunchComponent'; export class LaunchController { constructor() { this.launchAtomicService = (n1, o1) => { }; @@ -42,7 +45,7 @@ export class InnerFullScreenLaunchComponent extends ViewPU { 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(); @@ -101,20 +104,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; }); }); @@ -124,10 +127,9 @@ 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.'); this.subscriber = null; } }); @@ -139,7 +141,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 = { @@ -151,35 +153,44 @@ export class InnerFullScreenLaunchComponent extends ViewPU { } } async checkAbility() { + if (this.isShow) { + hilog.error(0x3900, LOG_TAG, 'EmbeddedAbility already shows'); + this.isShow = false; + return; + } 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; - } - this.isShow = true; - hilog.info(0x3900, 'InnerFullScreenLaunchComponent', ' EmbeddedOpen is Allowed!'); - } - else { - hilog.info(0x3900, 'InnerFullScreenLaunchComponent', ' EmbeddedOpen is not Allowed!'); - this.popUp(); - } + 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(); + } + } else { + hilog.info(0x3900, LOG_TAG, 'is not allowed open!'); + } + }).catch((err) => { + hilog.error(0x3900, LOG_TAG, 'queryAtomicServiceStartupRule called error!%{public}s', err.message); + if (ERR_CODE_CAPABILITY_NOT_SUPPORT === err.code) { + this.popUp(); + } + }); } - catch (n) { - hilog.error(0x3900, 'InnerFullScreenLaunchComponent', 'isEmbeddedOpenAllowed called error!%{public}s', n.message); + catch (err) { + hilog.error(0x3900, LOG_TAG, 'AtomicServiceStartupRule failed: %{public}s', err.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); } } handleOnReceiveEvent(data) { @@ -220,15 +231,17 @@ 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 !== ERR_CODE_ABNORMAL) { + this.getUIContext().showAlertDialog({ + message: g.message + }); + } }); UIExtensionComponent.onReceive(data => { this.handleOnReceiveEvent(data); diff --git a/innerfullscreenlaunchcomponent/source/innerfullscreenlaunchcomponent.ets b/innerfullscreenlaunchcomponent/source/innerfullscreenlaunchcomponent.ets index 23e0623..6fd1e7a 100644 --- a/innerfullscreenlaunchcomponent/source/innerfullscreenlaunchcomponent.ets +++ b/innerfullscreenlaunchcomponent/source/innerfullscreenlaunchcomponent.ets @@ -15,7 +15,7 @@ import hilog from '@ohos.hilog'; import abilityManager from '@ohos.app.ability.abilityManager'; import common from '@ohos.app.ability.common'; -import { Callback } from '@ohos.base'; +import { Callback, BusinessError } from '@ohos.base'; import AtomicServiceOptions from '@ohos.app.ability.AtomicServiceOptions'; import commonEventManager from '@ohos.commonEventManager'; import Base from '@ohos.base'; @@ -26,6 +26,9 @@ export class LaunchController { const EMBEDDED_FULL_MODE: number = 1; const atomicServiceDataTag: string = 'ohos.atomicService.window'; +const ERR_CODE_ABNORMAL: number = 100014; +const ERR_CODE_CAPABILITY_NOT_SUPPORT: number = 801; +const LOG_TAG: string = 'InnerFullScreenLaunchComponent'; @Component export struct InnerFullScreenLaunchComponent { @@ -37,7 +40,7 @@ export struct InnerFullScreenLaunchComponent { @State private isShow: boolean = false; private subscriber: commonEventManager.CommonEventSubscriber | null = null; private launchAtomicService = (appId: string, options?: AtomicServiceOptions) => { - hilog.info(0x3900, 'InnerFullScreenLaunchComponent', + hilog.info(0x3900, LOG_TAG, 'launchAtomicService, appId: %{public}s.', appId); this.appId = appId; this.options = options; @@ -53,13 +56,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; } @@ -67,12 +70,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; }) }) @@ -83,10 +86,9 @@ 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.'); this.subscriber = null; } }) @@ -101,7 +103,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,34 +114,44 @@ export struct InnerFullScreenLaunchComponent { } } - async checkAbility() { + async checkAbility(): Promise { + if (this.isShow) { + hilog.error(0x3900, LOG_TAG, 'EmbeddedAbility already shows'); + this.isShow = false; + return; + } 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; - } - 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); - } + 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(); + } + } else { + hilog.info(0x3900, LOG_TAG, 'is not allowed open!'); + } + }).catch((err: BusinessError) => { + hilog.error(0x3900, LOG_TAG, 'queryAtomicServiceStartupRule called error!%{public}s', err.message); + if (ERR_CODE_CAPABILITY_NOT_SUPPORT === err.code) { + this.popUp(); + } + }); + } catch (err: BusinessError) { + hilog.error(0x3900, LOG_TAG, 'AtomicServiceStartupRule failed: %{public}s', err.message); + } } - async popUp() { + async popUp(): Promise { 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); } } @@ -180,17 +192,19 @@ 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, 'InnerFullScreenLaunchComponent', '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 !== ERR_CODE_ABNORMAL) { + this.getUIContext().showAlertDialog({ + message: err.message + }); + } } ) .onReceive(data => { -- Gitee