diff --git a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhost/entry/src/main/ets/MainAbility/pages/FormViewModel.ets b/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhost/entry/src/main/ets/MainAbility/pages/FormViewModel.ets deleted file mode 100644 index cb25732d908c6cc580d69de1ae9984cde6230774..0000000000000000000000000000000000000000 --- a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhost/entry/src/main/ets/MainAbility/pages/FormViewModel.ets +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import formManager from '@ohos.ability.formmanager'; -import bundleManager from '@ohos.bundle'; -import abilityManager from '@ohos.app.abilityManager'; - -export default class FormViewModel { - private static sFormViewModel: FormViewModel = null; - - public static getInstance(): FormViewModel { - if (FormViewModel.sFormViewModel == null) { - FormViewModel.sFormViewModel = new FormViewModel(); - } - return FormViewModel.sFormViewModel; - } - - public async castTempFormToNormal(formId: string) { - formManager.castTempForm(formId) - .then((data) => { - console.info('[FormComponent] castTempForm result:' + data); - }); - } - - public async requestForm(formId: string) { - formManager.requestForm(formId) - .then((data) => { - console.info('[FormComponent] requestForm result:' + data); - }); - } - - public async deleteCard(formId: string) { - formManager.deleteForm(formId) - .then((data) => { - console.info('[FormComponent] deleteForm result:' + data); - }); - } - - public async releaseCard(formId: string) { - formManager.releaseForm(formId) - .then((data) => { - console.info('[FormComponent] releaseForm result:' + data); - }); - } - - public async enableCard(formId: string) { - formManager.enableFormsUpdate([formId]) - .then((data) => { - console.info('[FormComponent] enableFormsUpdate result:' + data); - }); - } - - public async disableCard(formId: string) { - formManager.disableFormsUpdate([formId]) - .then((data) => { - console.info('[FormComponent] disableCard result:' + data); - }); - } - - public async changeCardVisible(formId: string, isVisible: boolean) { - if (isVisible) { - formManager.notifyVisibleForms([formId]) - .then((data) => { - console.info('[FormComponent] changeCardVisible result:' + data + ', isVisible:' + isVisible); - }); - } else { - formManager.notifyInvisibleForms([formId]) - .then((data) => { - console.info('[FormComponent] changeCardVisible result:' + data + ', isVisible:' + isVisible); - }); - } - } - - public async isFmsReady() { - formManager.isSystemReady() - .then((data) => { - console.info('[FormComponent] isFmsReady result:' + data); - }); - } - - public async getAllFormsInfo() { - formManager.getAllFormsInfo() - .then((data) => { - console.info('[FormComponent] getAllFormsInfo result:' + JSON.stringify(data)); - }); - } - - public async getFormsInfoByApp(bundle: string) { - formManager.getFormsInfo(bundle) - .then((data) => { - console.info('[FormComponent] getFormsInfoByApp result:' + JSON.stringify(data)); - }); - } - - public async getFormsInfoByModule(bundle: string, moduleName: string) { - formManager.getFormsInfo(bundle, moduleName) - .then((data) => { - console.info('[FormComponent] getFormsInfoByModule result:' + JSON.stringify(data)); - }); - } - - public async clearFormUserCache() { - abilityManager.clearUpApplicationData('com.ohos.myapplicationform') - .then((data) => { - console.info('[FormComponent] cleanBundleCacheFiles result:' + JSON.stringify(data)); - }); - } - - public async clearFormProviderCache(bundle: string) { - abilityManager.clearUpApplicationData(bundle) - .then((data) => { - console.info('[FormComponent] cleanBundleCacheFiles result:' + JSON.stringify(data)); - }); - } -} \ No newline at end of file diff --git a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhost/entry/src/main/ets/MainAbility/pages/index.ets b/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhost/entry/src/main/ets/MainAbility/pages/index.ets index ac0ed6c4e0970dd39cb8cba27bd829274ec70bc9..178d3f1f3e9a63e1ae8fe06792bfef738a5805f2 100644 --- a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhost/entry/src/main/ets/MainAbility/pages/index.ets +++ b/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhost/entry/src/main/ets/MainAbility/pages/index.ets @@ -13,11 +13,10 @@ * limitations under the License. */ -import FormViewModel from './FormViewModel.ets'; -import router from '@system.router'; -import featureAbility from "@ohos.ability.featureAbility"; -import formManager from '@ohos.application.formHost' import commonEvent from '@ohos.commonEvent'; +import featureAbility from "@ohos.ability.featureAbility"; +import formManager from '@ohos.application.formHost'; + @Entry @Component struct Index { @@ -26,10 +25,7 @@ struct Index { @State ability: string = "com.form.formsystemtestservicea.hmservice.MainAbility"; @State moduleName: string = "entry"; @State name: string = "Form_Js001"; - @State width: number = 300; - @State height: number = 200; @State allowUpate: boolean = true; - @State onAcquireResult: string = ""; @State isShowing: boolean = true; @State canCreateForm: boolean = false; private dimension: FormDimension = FormDimension.Dimension_1_2; @@ -38,12 +34,7 @@ struct Index { private deleteId = "-1"; private temporaryId = "-1"; private temporary = false; - private mFormViewModel: FormViewModel; - private isVisible = false; - private mMargin = 15; - private BTN_BG_COLOR: string = '#0D9FFB'; private castForm = false; - private tempFormId: number = 0; private formOnAcquiredEvent = "FMS_FormOnAcquired_commonEvent"; private formCastEvent = "FMS_FormCast_commonEvent"; @@ -84,16 +75,7 @@ struct Index { console.info("!!!====>formsystemhost deleteCallBack end ====>"); } - private unSubscribeDeleteCallback() { - console.debug("====>formsystemhost unSubscribeDeleteCallback_1100 CallBack====>"); - } - private aboutToAppear() { - - const TAG = "[FormComponent.host]" - - this.mFormViewModel = FormViewModel.getInstance(); - commonEvent.createSubscriber(this.subscriberFormDeleteEvent).then(async (data) => { console.info("====>formsystemhost Subscriber FormDelete data:====>", JSON.stringify(data)); this.subscriberDel = data; @@ -297,9 +279,6 @@ struct Index { .onError((error) => { console.log("[FormComponent.host] error code:" + error.errcode); console.log("[FormComponent.host] error msg:" + error.msg); - this.onAcquireResult += error.errcode; - this.onAcquireResult += " "; - this.onAcquireResult += error.msg; if (this.deleteForm && this.deleteId) { let commonEventPublishData = { data: error.msg, diff --git a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostb/entry/src/main/ets/MainAbility/pages/FormViewModel.ets b/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostb/entry/src/main/ets/MainAbility/pages/FormViewModel.ets deleted file mode 100644 index cb25732d908c6cc580d69de1ae9984cde6230774..0000000000000000000000000000000000000000 --- a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostb/entry/src/main/ets/MainAbility/pages/FormViewModel.ets +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import formManager from '@ohos.ability.formmanager'; -import bundleManager from '@ohos.bundle'; -import abilityManager from '@ohos.app.abilityManager'; - -export default class FormViewModel { - private static sFormViewModel: FormViewModel = null; - - public static getInstance(): FormViewModel { - if (FormViewModel.sFormViewModel == null) { - FormViewModel.sFormViewModel = new FormViewModel(); - } - return FormViewModel.sFormViewModel; - } - - public async castTempFormToNormal(formId: string) { - formManager.castTempForm(formId) - .then((data) => { - console.info('[FormComponent] castTempForm result:' + data); - }); - } - - public async requestForm(formId: string) { - formManager.requestForm(formId) - .then((data) => { - console.info('[FormComponent] requestForm result:' + data); - }); - } - - public async deleteCard(formId: string) { - formManager.deleteForm(formId) - .then((data) => { - console.info('[FormComponent] deleteForm result:' + data); - }); - } - - public async releaseCard(formId: string) { - formManager.releaseForm(formId) - .then((data) => { - console.info('[FormComponent] releaseForm result:' + data); - }); - } - - public async enableCard(formId: string) { - formManager.enableFormsUpdate([formId]) - .then((data) => { - console.info('[FormComponent] enableFormsUpdate result:' + data); - }); - } - - public async disableCard(formId: string) { - formManager.disableFormsUpdate([formId]) - .then((data) => { - console.info('[FormComponent] disableCard result:' + data); - }); - } - - public async changeCardVisible(formId: string, isVisible: boolean) { - if (isVisible) { - formManager.notifyVisibleForms([formId]) - .then((data) => { - console.info('[FormComponent] changeCardVisible result:' + data + ', isVisible:' + isVisible); - }); - } else { - formManager.notifyInvisibleForms([formId]) - .then((data) => { - console.info('[FormComponent] changeCardVisible result:' + data + ', isVisible:' + isVisible); - }); - } - } - - public async isFmsReady() { - formManager.isSystemReady() - .then((data) => { - console.info('[FormComponent] isFmsReady result:' + data); - }); - } - - public async getAllFormsInfo() { - formManager.getAllFormsInfo() - .then((data) => { - console.info('[FormComponent] getAllFormsInfo result:' + JSON.stringify(data)); - }); - } - - public async getFormsInfoByApp(bundle: string) { - formManager.getFormsInfo(bundle) - .then((data) => { - console.info('[FormComponent] getFormsInfoByApp result:' + JSON.stringify(data)); - }); - } - - public async getFormsInfoByModule(bundle: string, moduleName: string) { - formManager.getFormsInfo(bundle, moduleName) - .then((data) => { - console.info('[FormComponent] getFormsInfoByModule result:' + JSON.stringify(data)); - }); - } - - public async clearFormUserCache() { - abilityManager.clearUpApplicationData('com.ohos.myapplicationform') - .then((data) => { - console.info('[FormComponent] cleanBundleCacheFiles result:' + JSON.stringify(data)); - }); - } - - public async clearFormProviderCache(bundle: string) { - abilityManager.clearUpApplicationData(bundle) - .then((data) => { - console.info('[FormComponent] cleanBundleCacheFiles result:' + JSON.stringify(data)); - }); - } -} \ No newline at end of file diff --git a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostb/entry/src/main/ets/MainAbility/pages/index.ets b/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostb/entry/src/main/ets/MainAbility/pages/index.ets index 0c040626d267ffee0ad9c5e16b756a2cce64854c..02459b19d0916cf6ae988712c167d2160976e0ca 100644 --- a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostb/entry/src/main/ets/MainAbility/pages/index.ets +++ b/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostb/entry/src/main/ets/MainAbility/pages/index.ets @@ -13,11 +13,9 @@ * limitations under the License. */ -import FormViewModel from './FormViewModel.ets'; -import router from '@system.router'; -import featureAbility from "@ohos.ability.featureAbility"; -import formManager from '@ohos.application.formHost' import commonEvent from '@ohos.commonEvent'; +import featureAbility from "@ohos.ability.featureAbility"; +import formManager from '@ohos.application.formHost'; @Entry @Component @@ -26,11 +24,8 @@ struct Index { @State bundle: string = "com.form.formsystemtestservicea.hmservice"; @State ability: string = "com.form.formsystemtestservicea.hmservice.MainAbility"; @State moduleName: string = "entry"; - @State name: string = "Form_Js001"; - @State width: number = 300; - @State height: number = 200; + @State name: string = "Form_Js001"; @State allowUpate: boolean = true; - @State onAcquireResult: string = ""; @State isShowing: boolean = true; @State canCreateForm: boolean = false; @@ -40,12 +35,7 @@ struct Index { private deleteId = "-1"; private temporaryId="-1"; private temporary = false; - private mFormViewModel: FormViewModel; - private isVisible = false; - private mMargin = 15; - private BTN_BG_COLOR: string = '#0D9FFB'; private castForm = false; - private tempFormId: number = 0; private formOnAcquiredEvent = "FMS_FormOnAcquired_commonEvent"; private formCastEvent = "FMS_FormCast_commonEvent"; @@ -80,16 +70,7 @@ struct Index { console.info("!!!====>formsystemhost deleteCallBack end ====>"); } - private unSubscribeDeleteCallback() { - console.debug("====>formsystemhost unSubscribeDeleteCallback_1100 CallBack====>"); - } - private aboutToAppear() { - - const TAG = "[FormComponent.host]" - - this.mFormViewModel = FormViewModel.getInstance(); - commonEvent.createSubscriber(this.subscriberFormDeleteEvent).then(async (data) => { console.info("====>formsystemhost Subscriber FormDelete data:====>", JSON.stringify(data)); this.subscriberDle = data; @@ -255,9 +236,6 @@ struct Index { .onError((error) => { console.log("[FormComponent.host] error code:" + error.errcode); console.log("[FormComponent.host] error msg:" + error.msg); - this.onAcquireResult += error.errcode; - this.onAcquireResult += " "; - this.onAcquireResult += error.msg; if(this.deleteForm && this.deleteId) { let commonEventPublishData = { data: error.msg, diff --git a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostc/entry/src/main/ets/MainAbility/pages/FormViewModel.ets b/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostc/entry/src/main/ets/MainAbility/pages/FormViewModel.ets deleted file mode 100644 index 9b09225070d8baf4062cf466a595a441993ae53b..0000000000000000000000000000000000000000 --- a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostc/entry/src/main/ets/MainAbility/pages/FormViewModel.ets +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import formManager from '@ohos.ability.formmanager'; -import bundleManager from '@ohos.bundle'; -import abilityManager from '@ohos.app.abilityManager'; - -export default class FormViewModel { - private static sFormViewModel: FormViewModel = null; - - public static getInstance(): FormViewModel { - if (FormViewModel.sFormViewModel == null) { - FormViewModel.sFormViewModel = new FormViewModel(); - } - return FormViewModel.sFormViewModel; - } - - public async castTempFormToNormal(formId: string) { - formManager.castTempForm(formId) - .then((data) => { - console.info('[FormComponent] castTempForm result:' + data); - }); - } - - public async requestForm(formId: string) { - formManager.requestForm(formId) - .then((data) => { - console.info('[FormComponent] requestForm result:' + data); - }); - } - - public async deleteCard(formId: string) { - formManager.deleteForm(formId) - .then((data) => { - console.info('[FormComponent] deleteForm result:' + data); - }); - } - - public async releaseCard(formId: string) { - formManager.releaseForm(formId) - .then((data) => { - console.info('[FormComponent] releaseForm result:' + data); - }); - } - - public async enableCard(formId: string) { - formManager.enableFormsUpdate([formId]) - .then((data) => { - console.info('[FormComponent] enableFormsUpdate result:' + data); - }); - } - - public async disableCard(formId: string) { - formManager.disableFormsUpdate([formId]) - .then((data) => { - console.info('[FormComponent] disableCard result:' + data); - }); - } - - public async changeCardVisible(formId: string, isVisible: boolean) { - if (isVisible) { - formManager.notifyVisibleForms([formId]) - .then((data) => { - console.info('[FormComponent] changeCardVisible result:' + data + ', isVisible:' + isVisible); - }); - } else { - formManager.notifyInvisibleForms([formId]) - .then((data) => { - console.info('[FormComponent] changeCardVisible result:' + data + ', isVisible:' + isVisible); - }); - } - } - - public async isFmsReady() { - formManager.isSystemReady() - .then((data) => { - console.info('[FormComponent] isFmsReady result:' + data); - }); - } - - public async getAllFormsInfo() { - formManager.getAllFormsInfo() - .then((data) => { - console.info('[FormComponent] getAllFormsInfo result:' + JSON.stringify(data)); - }); - } - - public async getFormsInfoByApp(bundle: string) { - formManager.getFormsInfo(bundle) - .then((data) => { - console.info('[FormComponent] getFormsInfoByApp result:' + JSON.stringify(data)); - }); - } - - public async getFormsInfoByModule(bundle: string, moduleName: string) { - formManager.getFormsInfo(bundle, moduleName) - .then((data) => { - console.info('[FormComponent] getFormsInfoByModule result:' + JSON.stringify(data)); - }); - } - - public async clearFormUserCache() { - abilityManager.clearUpApplicationData('com.ohos.myapplicationform') - .then((data) => { - console.info('[FormComponent] cleanBundleCacheFiles result:' + JSON.stringify(data)); - }); - } - - public async clearFormProviderCache(bundle: string) { - abilityManager.clearUpApplicationData(bundle) - .then((data) => { - console.info('[FormComponent] cleanBundleCacheFiles result:' + JSON.stringify(data)); - }); - } -} \ No newline at end of file diff --git a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostc/entry/src/main/ets/MainAbility/pages/index.ets b/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostc/entry/src/main/ets/MainAbility/pages/index.ets index ac305cb199e0cc574a1d77ee054393dbf3470251..53e70af0509205329d499f84cf1d5211e84354ac 100644 --- a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostc/entry/src/main/ets/MainAbility/pages/index.ets +++ b/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostc/entry/src/main/ets/MainAbility/pages/index.ets @@ -1,429 +1,404 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import FormViewModel from './FormViewModel.ets'; -import router from '@system.router'; -import featureAbility from "@ohos.ability.featureAbility"; -import formManager from '@ohos.application.formHost' -import commonEvent from '@ohos.commonEvent'; -import systemTime from '@ohos.systemTime'; - -@Entry -@Component -struct Index { - @State formId: number = 0; - @State bundle: string = "com.form.formsystemtestservicea.hmservice"; - @State ability: string = "com.form.formsystemtestservicea.hmservice.MainAbility"; - @State moduleName: string = "entry"; - @State name: string = "Form_Js001"; - @State width: number = 300; - @State height: number = 200; - @State allowUpate: boolean = true; - @State onAcquireResult: string = ""; - @State isShowing: boolean = true; - @State canCreateForm: boolean = false; - - private dimension: FormDimension = FormDimension.Dimension_1_2; - - private releaseForm = false; - private releaseId = "-1"; - private deleteForm = false; - private deleteId = "-1"; - private temporaryId="-1"; - private temporary = false; - private mFormViewModel: FormViewModel; - private isVisible = false; - private mMargin = 15; - private BTN_BG_COLOR: string = '#0D9FFB'; - private castForm = false; - private tempFormId: number = 0; - private sendCastForm = false; - private sendCastFormMsg; - - private formOnAcquiredEvent = "FMS_FormOnAcquired_commonEvent"; - private formCastEvent = "FMS_FormCast_commonEvent"; - private formOnErrorEvent = "FMS_FormOnError_commonEvent"; - private formOnDeletedEvent = "FMS_FormOnDeleted_commonEvent"; - private formOnReleasedEvent = "FMS_FormOnReleased_commonEvent"; - - private subscriberDel; - private subscriberFormDeleteEvent = { - events: ["FMS_FormDelete_commonEvent"], - }; - private subscriberTimeChange; - private subscriberTimeChangeEvent = { - events: ["FMS_TimeChange_commonEvent"], - }; - - private publishOnErrorCallBack() { - this.canCreateForm = false; - console.debug("====>formsystemhostc formOnErrorEventCallBack ====>"); - } - private publishOnDeletedCallBack() { - this.canCreateForm = false; - console.debug("====>formsystemhostc publishOnDeletedCallBack ====>"); - } - private publishOnReleasedCallBack() { - this.canCreateForm = false; - console.debug("====>formsystemhostc publishOnReleasedCallBackk ====>"); - } - private publishOnAcquiredCallBack() { - console.debug("====>formsystemhostc formOnAcquiredEventCallBack ====>"); - } - private publishCastCallBack() { - console.debug("====>formsystemhostc formCastEventCallBack ====>"); - } - - private deleteCallBack(err, data) { - console.info("!!!====>[FormComponent] deleteCallBack start:====>" + JSON.stringify(data)); - if(data.bundleName && data.bundleName != "com.ohos.st.formsystemhostc") { - return; - } - formManager.deleteForm(data.data) - .then((data2) => { - console.info('[FormComponent] deleteForm result:' + data2); - }); - - this.canCreateForm = false; - console.info("!!!====>[FormComponent] deleteCallBack end ====>"); - } - - private unSubscribeDeleteCallback() { - console.debug("====>[FormComponent] unSubscribeDeleteCallback_1100 CallBack====>"); - } - - private timeChangeCallBack(err, data) { - console.info("!!!====>[FormComponent] timeChangeCallBack start:====>" + JSON.stringify(data)); - if(data.bundleName && data.bundleName != "com.ohos.st.formsystemhostc") { - return; - } - this.changeTime(data.parameters.hour, data.parameters.min, data.parameters.second); - console.info("!!!====>[FormComponent] timeChangeCallBack end ====>"); - } - - private unSubscribeTimeChangeCallback() { - console.debug("====>[FormComponent] unSubscribeTimeChangeCallback CallBack====>"); - } - /** - * - * @param hour hour of 24H clock - * @param min minute - * @param second second - */ - private changeTime(hour: number, min: number, second: number): void { - let datetime = new Date(); - let year = datetime.getFullYear(); - let month = datetime.getMonth() + 1; - let day = datetime.getDate(); - let formatTime = year + '-' + this.fill(month) + '-' + this.fill(day) - + 'T' + this.fill(hour) + ':' + this.fill(min) + ':' + this.fill(second); - let s = (new Date(formatTime)).getTime(); - - systemTime.setTime(s).then(data => { - console.log(`set time success: ${formatTime}, result:${data}`); - }).catch(error => { - console.log(`set time failure: ${error}`); - }) - } - - private fill(value: number): string { - return (value > 9 ? "" : "0") + value; - } - private aboutToAppear() { - - const TAG = "[FormComponent.host]" - - this.mFormViewModel = FormViewModel.getInstance(); - - commonEvent.createSubscriber(this.subscriberFormDeleteEvent).then(async (data) => { - console.info("====>[FormComponent] Subscriber FormDelete data:====>", JSON.stringify(data)); - this.subscriberDel = data; - await commonEvent.subscribe(this.subscriberDel, this.deleteCallBack); - }) - - commonEvent.createSubscriber(this.subscriberTimeChangeEvent).then(async (data) => { - console.info("====>[FormComponent] Subscriber TimeChange data:====>", JSON.stringify(data)); - this.subscriberTimeChange = data; - await commonEvent.subscribe(this.subscriberTimeChange, this.timeChangeCallBack); - }) - - console.error('[FormComponent] getWant'); - featureAbility.getWant() - .then((want: any) => { - this.formId = parseInt(want.parameters.formId); - this.name = want.parameters.name; - this.bundle = want.parameters.bundle; - this.ability = want.parameters.ability; - if(want.parameters.moduleName) { - this.moduleName = want.parameters.moduleName; - } - if(want.parameters.temporary) { - this.temporary = want.parameters.temporary; - } - if(want.parameters.dimension) { - this.dimension = want.parameters.dimension; - } - if(!this.dimension) { - this.dimension = FormDimension.Dimension_1_2; - } - if(want.parameters.castForm) { - this.castForm = want.parameters.castForm; - } - if(want.parameters.temporaryId) { - this.temporaryId = want.parameters.temporaryId; - } - if(want.parameters.deleteForm) { - this.deleteForm = want.parameters.deleteForm; - } - if(want.parameters.deleteId) { - this.deleteId = want.parameters.deleteId; - } - if(want.parameters.releaseForm) { - this.releaseForm = want.parameters.releaseForm; - } - if(want.parameters.releaseId) { - this.releaseId = want.parameters.releaseId; - } - - if(want.parameters.sendCastForm) { - this.sendCastForm = want.parameters.sendCastForm; - } - if(want.parameters.sendCastFormMsg) { - this.sendCastFormMsg = want.parameters.sendCastFormMsg; - } - - setTimeout(() => { - this.canCreateForm = want.parameters.isCreate ? true : false; - console.error('[FormComponent] getWant canCreateForm:'+ this.canCreateForm); - }, 10); - console.error('[FormComponent] getWant end'+ JSON.stringify(want)); - if(!want.parameters.isCreate && this.sendCastForm) { - console.log("[FormComponent.host] sendCastForm start"); - setTimeout(() => { - let commonEventPublishData = { - data: sendCastFormMsg, - parameters: { - "formId" : "" - } - }; - commonEvent.publish(this.formCastEvent, commonEventPublishData, this.publishCastCallBack); - }, 5); - console.log("[FormComponent.host] sendCastForm end"); - } - if(!want.parameters.isCreate && this.deleteForm) { - console.log("[FormComponent] deleteForm start"); - formManager.deleteForm(this.deleteId) - .then((data) => { - console.info('[FormComponent] deleteForm result:' + data); - let commonEventPublishData = { - data: "0", - parameters: { - "formId" : this.deleteId - } - }; - commonEvent.publish(this.formOnDeletedEvent, commonEventPublishData, this.publishOnDeletedCallBack); - }) - .catch((error) => { - console.info('[FormComponent] deleteForm error:' + error); - let commonEventPublishData = { - data: error.code.toString(), - parameters: { - "formId" : this.deleteId.toString() - } - }; - commonEvent.publish(this.formOnDeletedEvent, commonEventPublishData, this.publishOnDeletedCallBack); - }); - - console.log("[FormComponent] deleteForm end"); - } - if(!want.parameters.isCreate && this.releaseForm) { - console.log("[FormComponent] releaseForm start"); - formManager.releaseForm(this.releaseId, true) - .then((data) => { - console.info('[FormComponent] releaseForm result:' + data); - let commonEventPublishData = { - data: "0", - parameters: { - "formId" : this.releaseId - } - }; - commonEvent.publish(this.formOnReleasedEvent, commonEventPublishData, this.publishOnReleasedCallBack); - }) - .catch((error) => { - console.info('[FormComponent] releaseForm error:' + error); - let commonEventPublishData = { - data: error.code.toString(), - parameters: { - "formId" : this.releaseId - } - }; - commonEvent.publish(this.formOnReleasedEvent, commonEventPublishData, this.publishOnReleasedCallBack); - }); - - console.log("[FormComponent] releaseForm end"); - } - }) - .catch((error: any) => { - console.error('[FormComponent] Operation failed. Cause: ' + JSON.stringify(error)); - }) - console.log(`[FormComponent.host] aboutToAppear end`); - } - - build() { - Column() { - Text('form component test begin') - Column() { - if (this.canCreateForm) { - FormComponent({ - id: this.formId, - name: this.name, - bundle: this.bundle, - ability: this.ability, - module: this.moduleName, - dimension: this.dimension, - temporary: this.temporary, - }) - .allowUpdate(this.allowUpate) - .visibility(this.isShowing ? Visibility.Visible : Visibility.Hidden) - .onAcquired((form) => { - console.log("[FormComponent.host] get form, form id:" + form.id); - this.formId = form.id; - if(this.castForm) { - console.log("[FormComponent.host] castTempForm start"); - formManager.castTempForm(this.temporaryId) - .then((data) => { - console.info('[FormComponent] castTempForm result:' + data); - setTimeout(() => { - let commonEventPublishData = { - data: "0", - parameters: { - "formId" : this.formId.toString() - } - }; - commonEvent.publish(this.formCastEvent, commonEventPublishData, this.publishCastCallBack); - }, 5); - }) - .catch((error) => { - console.info('[FormComponent] castTempForm error:' + error); - setTimeout(() => { - let commonEventPublishData = { - data: error.code.toString(), - parameters: { - "formId" : this.formId.toString() - } - }; - commonEvent.publish(this.formCastEvent, commonEventPublishData, this.publishCastCallBack); - }, 5); - }); - console.log("[FormComponent.host] castTempForm end"); - } else if(this.deleteForm) { - console.log("[FormComponent.host] deleteForm start"); - if(this.deleteId == "self") { - this.deleteId = this.formId.toString(); - } - setTimeout(() => { - formManager.deleteForm(this.deleteId) - .then((data) => { - console.info('[FormComponent] deleteForm result:' + data); - var commonEventPublishData = { - data: "0", - parameters: { - "formId" : this.deleteId - } - }; - commonEvent.publish(this.formOnDeletedEvent, commonEventPublishData, this.publishOnDeletedCallBack); - }) - .catch((error) => { - console.info('[FormComponent] deleteForm error:' + error); - var commonEventPublishData = { - data: error.code.toString(), - parameters: { - "formId" : this.deleteId - } - }; - commonEvent.publish(this.formOnDeletedEvent, commonEventPublishData, this.publishOnDeletedCallBack); - }); - - console.log("[FormComponent.host] deleteForm end"); - }, 1000); - } else if(this.releaseForm) { - console.log("[FormComponent.host] releaseForm start"); - if(this.releaseId == "self") { - this.releaseId = this.formId.toString(); - } - setTimeout(() => { - formManager.releaseForm(this.releaseId, true) - .then((data) => { - console.info('[FormComponent] releaseForm result:' + data); - var commonEventPublishData = { - data: "0", - parameters: { - "formId" : this.releaseId - } - }; - commonEvent.publish(this.formOnReleasedEvent, commonEventPublishData, this.publishOnReleasedCallBack); - }) - .catch((error) => { - console.info('[FormComponent] releaseForm error:' + error); - let commonEventPublishData = { - data: error.code.toString(), - parameters: { - "formId" : this.releaseId - } - }; - commonEvent.publish(this.formOnReleasedEvent, commonEventPublishData, this.publishOnReleasedCallBack); - }); - - console.log("[FormComponent.host] releaseForm end"); - }, 1000); - } else { - var commonEventPublishData = { - data: this.formId.toString() - }; - commonEvent.publish(this.formOnAcquiredEvent, commonEventPublishData, this.publishOnAcquiredCallBack); - } - }) - // .onUninstall((info) => { - // console.log("[FormComponent] onUninstall:" + JSON.stringify(info)); - // }) - .onError((error) => { - console.log("[FormComponent.host] error code:" + error.errcode); - console.log("[FormComponent.host] error msg:" + error.msg); - this.onAcquireResult += error.errcode; - this.onAcquireResult += " "; - this.onAcquireResult += error.msg; - if(this.deleteForm && this.deleteId) { - let commonEventPublishData = { - data: error.msg, - parameters: { - "formId" : this.formId.toString() - } - }; - commonEvent.publish(this.formOnDeletedEvent, commonEventPublishData, this.publishOnDeletedCallBack); - } else { - let commonEventPublishData = { - data: error.msg - }; - commonEvent.publish(this.formOnErrorEvent, commonEventPublishData, this.publishOnErrorCallBack); - } - }) - } - } - .backgroundColor(Color.White) - Text('form component test end') - } - .backgroundColor(Color.White) - } +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import commonEvent from '@ohos.commonEvent'; +import featureAbility from "@ohos.ability.featureAbility"; +import formManager from '@ohos.application.formHost'; +import systemTime from '@ohos.systemTime'; + +@Entry +@Component +struct Index { + @State formId: number = 0; + @State bundle: string = "com.form.formsystemtestservicea.hmservice"; + @State ability: string = "com.form.formsystemtestservicea.hmservice.MainAbility"; + @State moduleName: string = "entry"; + @State name: string = "Form_Js001"; + @State allowUpate: boolean = true; + @State isShowing: boolean = true; + @State canCreateForm: boolean = false; + + private dimension: FormDimension = FormDimension.Dimension_1_2; + + private releaseForm = false; + private releaseId = "-1"; + private deleteForm = false; + private deleteId = "-1"; + private temporaryId="-1"; + private temporary = false; + private castForm = false; + private sendCastForm = false; + private sendCastFormMsg; + + private formOnAcquiredEvent = "FMS_FormOnAcquired_commonEvent"; + private formCastEvent = "FMS_FormCast_commonEvent"; + private formOnErrorEvent = "FMS_FormOnError_commonEvent"; + private formOnDeletedEvent = "FMS_FormOnDeleted_commonEvent"; + private formOnReleasedEvent = "FMS_FormOnReleased_commonEvent"; + + private subscriberDel; + private subscriberFormDeleteEvent = { + events: ["FMS_FormDelete_commonEvent"], + }; + private subscriberTimeChange; + private subscriberTimeChangeEvent = { + events: ["FMS_TimeChange_commonEvent"], + }; + + private publishOnErrorCallBack() { + this.canCreateForm = false; + console.debug("====>formsystemhostc formOnErrorEventCallBack ====>"); + } + private publishOnDeletedCallBack() { + this.canCreateForm = false; + console.debug("====>formsystemhostc publishOnDeletedCallBack ====>"); + } + private publishOnReleasedCallBack() { + this.canCreateForm = false; + console.debug("====>formsystemhostc publishOnReleasedCallBackk ====>"); + } + private publishOnAcquiredCallBack() { + console.debug("====>formsystemhostc formOnAcquiredEventCallBack ====>"); + } + private publishCastCallBack() { + console.debug("====>formsystemhostc formCastEventCallBack ====>"); + } + + private deleteCallBack(err, data) { + console.info("!!!====>[FormComponent] deleteCallBack start:====>" + JSON.stringify(data)); + if(data.bundleName && data.bundleName != "com.ohos.st.formsystemhostc") { + return; + } + formManager.deleteForm(data.data) + .then((data2) => { + console.info('[FormComponent] deleteForm result:' + data2); + }); + + this.canCreateForm = false; + console.info("!!!====>[FormComponent] deleteCallBack end ====>"); + } + + private timeChangeCallBack(err, data) { + console.info("!!!====>[FormComponent] timeChangeCallBack start:====>" + JSON.stringify(data)); + if(data.bundleName && data.bundleName != "com.ohos.st.formsystemhostc") { + return; + } + this.changeTime(data.parameters.hour, data.parameters.min, data.parameters.second); + console.info("!!!====>[FormComponent] timeChangeCallBack end ====>"); + } + + /** + * + * @param hour hour of 24H clock + * @param min minute + * @param second second + */ + private changeTime(hour: number, min: number, second: number): void { + let datetime = new Date(); + let year = datetime.getFullYear(); + let month = datetime.getMonth() + 1; + let day = datetime.getDate(); + let formatTime = year + '-' + this.fill(month) + '-' + this.fill(day) + + 'T' + this.fill(hour) + ':' + this.fill(min) + ':' + this.fill(second); + let s = (new Date(formatTime)).getTime(); + + systemTime.setTime(s).then(data => { + console.log(`set time success: ${formatTime}, result:${data}`); + }).catch(error => { + console.log(`set time failure: ${error}`); + }) + } + + private fill(value: number): string { + return (value > 9 ? "" : "0") + value; + } + private aboutToAppear() { + commonEvent.createSubscriber(this.subscriberFormDeleteEvent).then(async (data) => { + console.info("====>[FormComponent] Subscriber FormDelete data:====>", JSON.stringify(data)); + this.subscriberDel = data; + await commonEvent.subscribe(this.subscriberDel, this.deleteCallBack); + }) + + commonEvent.createSubscriber(this.subscriberTimeChangeEvent).then(async (data) => { + console.info("====>[FormComponent] Subscriber TimeChange data:====>", JSON.stringify(data)); + this.subscriberTimeChange = data; + await commonEvent.subscribe(this.subscriberTimeChange, this.timeChangeCallBack); + }) + + console.error('[FormComponent] getWant'); + featureAbility.getWant() + .then((want: any) => { + this.formId = parseInt(want.parameters.formId); + this.name = want.parameters.name; + this.bundle = want.parameters.bundle; + this.ability = want.parameters.ability; + if(want.parameters.moduleName) { + this.moduleName = want.parameters.moduleName; + } + if(want.parameters.temporary) { + this.temporary = want.parameters.temporary; + } + if(want.parameters.dimension) { + this.dimension = want.parameters.dimension; + } + if(!this.dimension) { + this.dimension = FormDimension.Dimension_1_2; + } + if(want.parameters.castForm) { + this.castForm = want.parameters.castForm; + } + if(want.parameters.temporaryId) { + this.temporaryId = want.parameters.temporaryId; + } + if(want.parameters.deleteForm) { + this.deleteForm = want.parameters.deleteForm; + } + if(want.parameters.deleteId) { + this.deleteId = want.parameters.deleteId; + } + if(want.parameters.releaseForm) { + this.releaseForm = want.parameters.releaseForm; + } + if(want.parameters.releaseId) { + this.releaseId = want.parameters.releaseId; + } + + if(want.parameters.sendCastForm) { + this.sendCastForm = want.parameters.sendCastForm; + } + if(want.parameters.sendCastFormMsg) { + this.sendCastFormMsg = want.parameters.sendCastFormMsg; + } + + setTimeout(() => { + this.canCreateForm = want.parameters.isCreate ? true : false; + console.error('[FormComponent] getWant canCreateForm:'+ this.canCreateForm); + }, 10); + console.error('[FormComponent] getWant end'+ JSON.stringify(want)); + if(!want.parameters.isCreate && this.sendCastForm) { + console.log("[FormComponent.host] sendCastForm start"); + setTimeout(() => { + let commonEventPublishData = { + data: sendCastFormMsg, + parameters: { + "formId" : "" + } + }; + commonEvent.publish(this.formCastEvent, commonEventPublishData, this.publishCastCallBack); + }, 5); + console.log("[FormComponent.host] sendCastForm end"); + } + if(!want.parameters.isCreate && this.deleteForm) { + console.log("[FormComponent] deleteForm start"); + formManager.deleteForm(this.deleteId) + .then((data) => { + console.info('[FormComponent] deleteForm result:' + data); + let commonEventPublishData = { + data: "0", + parameters: { + "formId" : this.deleteId + } + }; + commonEvent.publish(this.formOnDeletedEvent, commonEventPublishData, this.publishOnDeletedCallBack); + }) + .catch((error) => { + console.info('[FormComponent] deleteForm error:' + error); + let commonEventPublishData = { + data: error.code.toString(), + parameters: { + "formId" : this.deleteId.toString() + } + }; + commonEvent.publish(this.formOnDeletedEvent, commonEventPublishData, this.publishOnDeletedCallBack); + }); + + console.log("[FormComponent] deleteForm end"); + } + if(!want.parameters.isCreate && this.releaseForm) { + console.log("[FormComponent] releaseForm start"); + formManager.releaseForm(this.releaseId, true) + .then((data) => { + console.info('[FormComponent] releaseForm result:' + data); + let commonEventPublishData = { + data: "0", + parameters: { + "formId" : this.releaseId + } + }; + commonEvent.publish(this.formOnReleasedEvent, commonEventPublishData, this.publishOnReleasedCallBack); + }) + .catch((error) => { + console.info('[FormComponent] releaseForm error:' + error); + let commonEventPublishData = { + data: error.code.toString(), + parameters: { + "formId" : this.releaseId + } + }; + commonEvent.publish(this.formOnReleasedEvent, commonEventPublishData, this.publishOnReleasedCallBack); + }); + + console.log("[FormComponent] releaseForm end"); + } + }) + .catch((error: any) => { + console.error('[FormComponent] Operation failed. Cause: ' + JSON.stringify(error)); + }) + console.log(`[FormComponent.host] aboutToAppear end`); + } + + build() { + Column() { + Text('form component test begin') + Column() { + if (this.canCreateForm) { + FormComponent({ + id: this.formId, + name: this.name, + bundle: this.bundle, + ability: this.ability, + module: this.moduleName, + dimension: this.dimension, + temporary: this.temporary, + }) + .allowUpdate(this.allowUpate) + .visibility(this.isShowing ? Visibility.Visible : Visibility.Hidden) + .onAcquired((form) => { + console.log("[FormComponent.host] get form, form id:" + form.id); + this.formId = form.id; + if(this.castForm) { + console.log("[FormComponent.host] castTempForm start"); + formManager.castTempForm(this.temporaryId) + .then((data) => { + console.info('[FormComponent] castTempForm result:' + data); + setTimeout(() => { + let commonEventPublishData = { + data: "0", + parameters: { + "formId" : this.formId.toString() + } + }; + commonEvent.publish(this.formCastEvent, commonEventPublishData, this.publishCastCallBack); + }, 5); + }) + .catch((error) => { + console.info('[FormComponent] castTempForm error:' + error); + setTimeout(() => { + let commonEventPublishData = { + data: error.code.toString(), + parameters: { + "formId" : this.formId.toString() + } + }; + commonEvent.publish(this.formCastEvent, commonEventPublishData, this.publishCastCallBack); + }, 5); + }); + console.log("[FormComponent.host] castTempForm end"); + } else if(this.deleteForm) { + console.log("[FormComponent.host] deleteForm start"); + if(this.deleteId == "self") { + this.deleteId = this.formId.toString(); + } + setTimeout(() => { + formManager.deleteForm(this.deleteId) + .then((data) => { + console.info('[FormComponent] deleteForm result:' + data); + var commonEventPublishData = { + data: "0", + parameters: { + "formId" : this.deleteId + } + }; + commonEvent.publish(this.formOnDeletedEvent, commonEventPublishData, this.publishOnDeletedCallBack); + }) + .catch((error) => { + console.info('[FormComponent] deleteForm error:' + error); + var commonEventPublishData = { + data: error.code.toString(), + parameters: { + "formId" : this.deleteId + } + }; + commonEvent.publish(this.formOnDeletedEvent, commonEventPublishData, this.publishOnDeletedCallBack); + }); + + console.log("[FormComponent.host] deleteForm end"); + }, 1000); + } else if(this.releaseForm) { + console.log("[FormComponent.host] releaseForm start"); + if(this.releaseId == "self") { + this.releaseId = this.formId.toString(); + } + setTimeout(() => { + formManager.releaseForm(this.releaseId, true) + .then((data) => { + console.info('[FormComponent] releaseForm result:' + data); + var commonEventPublishData = { + data: "0", + parameters: { + "formId" : this.releaseId + } + }; + commonEvent.publish(this.formOnReleasedEvent, commonEventPublishData, this.publishOnReleasedCallBack); + }) + .catch((error) => { + console.info('[FormComponent] releaseForm error:' + error); + let commonEventPublishData = { + data: error.code.toString(), + parameters: { + "formId" : this.releaseId + } + }; + commonEvent.publish(this.formOnReleasedEvent, commonEventPublishData, this.publishOnReleasedCallBack); + }); + + console.log("[FormComponent.host] releaseForm end"); + }, 1000); + } else { + var commonEventPublishData = { + data: this.formId.toString() + }; + commonEvent.publish(this.formOnAcquiredEvent, commonEventPublishData, this.publishOnAcquiredCallBack); + } + }) + // .onUninstall((info) => { + // console.log("[FormComponent] onUninstall:" + JSON.stringify(info)); + // }) + .onError((error) => { + console.log("[FormComponent.host] error code:" + error.errcode); + console.log("[FormComponent.host] error msg:" + error.msg); + if(this.deleteForm && this.deleteId) { + let commonEventPublishData = { + data: error.msg, + parameters: { + "formId" : this.formId.toString() + } + }; + commonEvent.publish(this.formOnDeletedEvent, commonEventPublishData, this.publishOnDeletedCallBack); + } else { + let commonEventPublishData = { + data: error.msg + }; + commonEvent.publish(this.formOnErrorEvent, commonEventPublishData, this.publishOnErrorCallBack); + } + }) + } + } + .backgroundColor(Color.White) + Text('form component test end') + } + .backgroundColor(Color.White) + } } \ No newline at end of file diff --git a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostd/entry/src/main/ets/MainAbility/pages/FormViewModel.ets b/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostd/entry/src/main/ets/MainAbility/pages/FormViewModel.ets deleted file mode 100644 index cb25732d908c6cc580d69de1ae9984cde6230774..0000000000000000000000000000000000000000 --- a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostd/entry/src/main/ets/MainAbility/pages/FormViewModel.ets +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import formManager from '@ohos.ability.formmanager'; -import bundleManager from '@ohos.bundle'; -import abilityManager from '@ohos.app.abilityManager'; - -export default class FormViewModel { - private static sFormViewModel: FormViewModel = null; - - public static getInstance(): FormViewModel { - if (FormViewModel.sFormViewModel == null) { - FormViewModel.sFormViewModel = new FormViewModel(); - } - return FormViewModel.sFormViewModel; - } - - public async castTempFormToNormal(formId: string) { - formManager.castTempForm(formId) - .then((data) => { - console.info('[FormComponent] castTempForm result:' + data); - }); - } - - public async requestForm(formId: string) { - formManager.requestForm(formId) - .then((data) => { - console.info('[FormComponent] requestForm result:' + data); - }); - } - - public async deleteCard(formId: string) { - formManager.deleteForm(formId) - .then((data) => { - console.info('[FormComponent] deleteForm result:' + data); - }); - } - - public async releaseCard(formId: string) { - formManager.releaseForm(formId) - .then((data) => { - console.info('[FormComponent] releaseForm result:' + data); - }); - } - - public async enableCard(formId: string) { - formManager.enableFormsUpdate([formId]) - .then((data) => { - console.info('[FormComponent] enableFormsUpdate result:' + data); - }); - } - - public async disableCard(formId: string) { - formManager.disableFormsUpdate([formId]) - .then((data) => { - console.info('[FormComponent] disableCard result:' + data); - }); - } - - public async changeCardVisible(formId: string, isVisible: boolean) { - if (isVisible) { - formManager.notifyVisibleForms([formId]) - .then((data) => { - console.info('[FormComponent] changeCardVisible result:' + data + ', isVisible:' + isVisible); - }); - } else { - formManager.notifyInvisibleForms([formId]) - .then((data) => { - console.info('[FormComponent] changeCardVisible result:' + data + ', isVisible:' + isVisible); - }); - } - } - - public async isFmsReady() { - formManager.isSystemReady() - .then((data) => { - console.info('[FormComponent] isFmsReady result:' + data); - }); - } - - public async getAllFormsInfo() { - formManager.getAllFormsInfo() - .then((data) => { - console.info('[FormComponent] getAllFormsInfo result:' + JSON.stringify(data)); - }); - } - - public async getFormsInfoByApp(bundle: string) { - formManager.getFormsInfo(bundle) - .then((data) => { - console.info('[FormComponent] getFormsInfoByApp result:' + JSON.stringify(data)); - }); - } - - public async getFormsInfoByModule(bundle: string, moduleName: string) { - formManager.getFormsInfo(bundle, moduleName) - .then((data) => { - console.info('[FormComponent] getFormsInfoByModule result:' + JSON.stringify(data)); - }); - } - - public async clearFormUserCache() { - abilityManager.clearUpApplicationData('com.ohos.myapplicationform') - .then((data) => { - console.info('[FormComponent] cleanBundleCacheFiles result:' + JSON.stringify(data)); - }); - } - - public async clearFormProviderCache(bundle: string) { - abilityManager.clearUpApplicationData(bundle) - .then((data) => { - console.info('[FormComponent] cleanBundleCacheFiles result:' + JSON.stringify(data)); - }); - } -} \ No newline at end of file diff --git a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostd/entry/src/main/ets/MainAbility/pages/index.ets b/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostd/entry/src/main/ets/MainAbility/pages/index.ets index 58ba454811b2b034a89391e86718a37c8f912b64..f511c9847045d37b78a4efb559b798f544e0135e 100644 --- a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostd/entry/src/main/ets/MainAbility/pages/index.ets +++ b/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostd/entry/src/main/ets/MainAbility/pages/index.ets @@ -13,11 +13,9 @@ * limitations under the License. */ -import FormViewModel from './FormViewModel.ets'; -import router from '@system.router'; -import featureAbility from "@ohos.ability.featureAbility"; -import formManager from '@ohos.application.formHost' import commonEvent from '@ohos.commonEvent'; +import featureAbility from "@ohos.ability.featureAbility"; +import formManager from '@ohos.application.formHost'; @Entry @Component @@ -26,11 +24,8 @@ struct Index { @State bundle: string = "com.form.formsystemtestservicea.hmservice"; @State ability: string = "com.form.formsystemtestservicea.hmservice.MainAbility"; @State moduleName: string = "entry"; - @State name: string = "Form_Js001"; - @State width: number = 300; - @State height: number = 200; + @State name: string = "Form_Js001"; @State allowUpate: boolean = true; - @State onAcquireResult: string = ""; @State isShowing: boolean = true; @State canCreateForm: boolean = false; @@ -42,12 +37,7 @@ struct Index { private deleteId = "-1"; private temporaryId="-1"; private temporary = false; - private mFormViewModel: FormViewModel; - private isVisible = false; - private mMargin = 15; - private BTN_BG_COLOR: string = '#0D9FFB'; private castForm = false; - private tempFormId: number = 0; private formOnAcquiredEvent = "FMS_FormOnAcquired_commonEvent"; private formCastEvent = "FMS_FormCast_commonEvent"; @@ -93,16 +83,7 @@ struct Index { console.info("!!!====>formsystemhost deleteCallBack end ====>"); } - private unSubscribeDeleteCallback() { - console.debug("====>formsystemhost unSubscribeDeleteCallback_1100 CallBack====>"); - } - private aboutToAppear() { - - const TAG = "[FormComponent.host]" - - this.mFormViewModel = FormViewModel.getInstance(); - commonEvent.createSubscriber(this.subscriberFormDeleteEvent).then(async (data) => { console.info("====>formsystemhost Subscriber FormDelete data:====>", JSON.stringify(data)); this.subscriberDel = data; @@ -327,9 +308,6 @@ struct Index { .onError((error) => { console.log("[FormComponent.host] error code:" + error.errcode); console.log("[FormComponent.host] error msg:" + error.msg); - this.onAcquireResult += error.errcode; - this.onAcquireResult += " "; - this.onAcquireResult += error.msg; if(this.deleteForm && this.deleteId) { let commonEventPublishData = { data: error.msg, diff --git a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhoste/entry/src/main/ets/MainAbility/pages/FormViewModel.ets b/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhoste/entry/src/main/ets/MainAbility/pages/FormViewModel.ets deleted file mode 100644 index cb25732d908c6cc580d69de1ae9984cde6230774..0000000000000000000000000000000000000000 --- a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhoste/entry/src/main/ets/MainAbility/pages/FormViewModel.ets +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import formManager from '@ohos.ability.formmanager'; -import bundleManager from '@ohos.bundle'; -import abilityManager from '@ohos.app.abilityManager'; - -export default class FormViewModel { - private static sFormViewModel: FormViewModel = null; - - public static getInstance(): FormViewModel { - if (FormViewModel.sFormViewModel == null) { - FormViewModel.sFormViewModel = new FormViewModel(); - } - return FormViewModel.sFormViewModel; - } - - public async castTempFormToNormal(formId: string) { - formManager.castTempForm(formId) - .then((data) => { - console.info('[FormComponent] castTempForm result:' + data); - }); - } - - public async requestForm(formId: string) { - formManager.requestForm(formId) - .then((data) => { - console.info('[FormComponent] requestForm result:' + data); - }); - } - - public async deleteCard(formId: string) { - formManager.deleteForm(formId) - .then((data) => { - console.info('[FormComponent] deleteForm result:' + data); - }); - } - - public async releaseCard(formId: string) { - formManager.releaseForm(formId) - .then((data) => { - console.info('[FormComponent] releaseForm result:' + data); - }); - } - - public async enableCard(formId: string) { - formManager.enableFormsUpdate([formId]) - .then((data) => { - console.info('[FormComponent] enableFormsUpdate result:' + data); - }); - } - - public async disableCard(formId: string) { - formManager.disableFormsUpdate([formId]) - .then((data) => { - console.info('[FormComponent] disableCard result:' + data); - }); - } - - public async changeCardVisible(formId: string, isVisible: boolean) { - if (isVisible) { - formManager.notifyVisibleForms([formId]) - .then((data) => { - console.info('[FormComponent] changeCardVisible result:' + data + ', isVisible:' + isVisible); - }); - } else { - formManager.notifyInvisibleForms([formId]) - .then((data) => { - console.info('[FormComponent] changeCardVisible result:' + data + ', isVisible:' + isVisible); - }); - } - } - - public async isFmsReady() { - formManager.isSystemReady() - .then((data) => { - console.info('[FormComponent] isFmsReady result:' + data); - }); - } - - public async getAllFormsInfo() { - formManager.getAllFormsInfo() - .then((data) => { - console.info('[FormComponent] getAllFormsInfo result:' + JSON.stringify(data)); - }); - } - - public async getFormsInfoByApp(bundle: string) { - formManager.getFormsInfo(bundle) - .then((data) => { - console.info('[FormComponent] getFormsInfoByApp result:' + JSON.stringify(data)); - }); - } - - public async getFormsInfoByModule(bundle: string, moduleName: string) { - formManager.getFormsInfo(bundle, moduleName) - .then((data) => { - console.info('[FormComponent] getFormsInfoByModule result:' + JSON.stringify(data)); - }); - } - - public async clearFormUserCache() { - abilityManager.clearUpApplicationData('com.ohos.myapplicationform') - .then((data) => { - console.info('[FormComponent] cleanBundleCacheFiles result:' + JSON.stringify(data)); - }); - } - - public async clearFormProviderCache(bundle: string) { - abilityManager.clearUpApplicationData(bundle) - .then((data) => { - console.info('[FormComponent] cleanBundleCacheFiles result:' + JSON.stringify(data)); - }); - } -} \ No newline at end of file diff --git a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhoste/entry/src/main/ets/MainAbility/pages/index.ets b/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhoste/entry/src/main/ets/MainAbility/pages/index.ets index d0adfc1a6caaf1e43837a7e54e9529b2b0bf3df0..4471833c674de2e02777f7f828c95b6e4fbcfad1 100644 --- a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhoste/entry/src/main/ets/MainAbility/pages/index.ets +++ b/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhoste/entry/src/main/ets/MainAbility/pages/index.ets @@ -13,12 +13,10 @@ * limitations under the License. */ -import FormViewModel from './FormViewModel.ets'; -import router from '@system.router'; -import featureAbility from '@ohos.ability.featureAbility'; -import formManager from '@ohos.application.formHost' -import formProvider from '@ohos.application.formProvider' import commonEvent from '@ohos.commonEvent'; +import featureAbility from '@ohos.ability.featureAbility'; +import formManager from '@ohos.application.formHost'; +import formProvider from '@ohos.application.formProvider'; @Entry @Component @@ -28,10 +26,7 @@ struct Index { @State ability: string = "com.form.formsystemtestservicea.hmservice.MainAbility"; @State moduleName: string = "entry"; @State name: string = "Form_Js001"; - @State width: number = 300; - @State height: number = 200; @State allowUpate: boolean = true; - @State onAcquireResult: string = ""; @State isShowing: boolean = true; @State canCreateForm: boolean = false; @@ -48,11 +43,6 @@ struct Index { private deleteId = "-1"; private temporaryId = "-1"; private temporary = false; - private mFormViewModel: FormViewModel; - private isVisible = false; - private mMargin = 15; - private BTN_BG_COLOR: string = '#0D9FFB'; - private tempFormId: number = 0; private formOnAcquiredEvent = "FMS_FormOnAcquired_commonEvent"; private formOnErrorEvent = "FMS_FormOnError_commonEvent"; @@ -77,10 +67,6 @@ struct Index { this.canCreateForm = false; console.debug("====>formsystemhostc formOnDynamicRefreshEventk ====>"); } - private formOnNotifyVisibleFormsCallBack() { - this.canCreateForm = false; - console.debug("====>formsystemhostc formOnDynamicRefreshEventk ====>"); - } private formOnRequestCallBack() { this.canCreateForm = false; console.debug("====>formsystemhostc formOnRequestCallBack ====>"); @@ -103,16 +89,7 @@ struct Index { console.info("!!!====>formsystemhost deleteCallBack end ====>"); } - private unSubscribeDeleteCallback() { - console.debug("====>formsystemhost unSubscribeDeleteCallback_1100 CallBack====>"); - } - private aboutToAppear() { - - const TAG = "[FormComponent.host]" - - this.mFormViewModel = FormViewModel.getInstance(); - commonEvent.createSubscriber(this.subscriberFormDeleteEvent).then(async (data) => { console.info("====>formsystemhost Subscriber FormDelete data:====>", JSON.stringify(data)); this.subscriberDel = data; @@ -414,9 +391,6 @@ struct Index { .onError((error) => { console.log("[FormComponent.host] error code:" + error.errcode); console.log("[FormComponent.host] error msg:" + error.msg); - this.onAcquireResult += error.errcode; - this.onAcquireResult += " "; - this.onAcquireResult += error.msg; if (this.deleteForm && this.deleteId) { let commonEventPublishData = { data: error.msg, diff --git a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostf/entry/src/main/ets/MainAbility/pages/FormViewModel.ets b/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostf/entry/src/main/ets/MainAbility/pages/FormViewModel.ets deleted file mode 100644 index 9b09225070d8baf4062cf466a595a441993ae53b..0000000000000000000000000000000000000000 --- a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostf/entry/src/main/ets/MainAbility/pages/FormViewModel.ets +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import formManager from '@ohos.ability.formmanager'; -import bundleManager from '@ohos.bundle'; -import abilityManager from '@ohos.app.abilityManager'; - -export default class FormViewModel { - private static sFormViewModel: FormViewModel = null; - - public static getInstance(): FormViewModel { - if (FormViewModel.sFormViewModel == null) { - FormViewModel.sFormViewModel = new FormViewModel(); - } - return FormViewModel.sFormViewModel; - } - - public async castTempFormToNormal(formId: string) { - formManager.castTempForm(formId) - .then((data) => { - console.info('[FormComponent] castTempForm result:' + data); - }); - } - - public async requestForm(formId: string) { - formManager.requestForm(formId) - .then((data) => { - console.info('[FormComponent] requestForm result:' + data); - }); - } - - public async deleteCard(formId: string) { - formManager.deleteForm(formId) - .then((data) => { - console.info('[FormComponent] deleteForm result:' + data); - }); - } - - public async releaseCard(formId: string) { - formManager.releaseForm(formId) - .then((data) => { - console.info('[FormComponent] releaseForm result:' + data); - }); - } - - public async enableCard(formId: string) { - formManager.enableFormsUpdate([formId]) - .then((data) => { - console.info('[FormComponent] enableFormsUpdate result:' + data); - }); - } - - public async disableCard(formId: string) { - formManager.disableFormsUpdate([formId]) - .then((data) => { - console.info('[FormComponent] disableCard result:' + data); - }); - } - - public async changeCardVisible(formId: string, isVisible: boolean) { - if (isVisible) { - formManager.notifyVisibleForms([formId]) - .then((data) => { - console.info('[FormComponent] changeCardVisible result:' + data + ', isVisible:' + isVisible); - }); - } else { - formManager.notifyInvisibleForms([formId]) - .then((data) => { - console.info('[FormComponent] changeCardVisible result:' + data + ', isVisible:' + isVisible); - }); - } - } - - public async isFmsReady() { - formManager.isSystemReady() - .then((data) => { - console.info('[FormComponent] isFmsReady result:' + data); - }); - } - - public async getAllFormsInfo() { - formManager.getAllFormsInfo() - .then((data) => { - console.info('[FormComponent] getAllFormsInfo result:' + JSON.stringify(data)); - }); - } - - public async getFormsInfoByApp(bundle: string) { - formManager.getFormsInfo(bundle) - .then((data) => { - console.info('[FormComponent] getFormsInfoByApp result:' + JSON.stringify(data)); - }); - } - - public async getFormsInfoByModule(bundle: string, moduleName: string) { - formManager.getFormsInfo(bundle, moduleName) - .then((data) => { - console.info('[FormComponent] getFormsInfoByModule result:' + JSON.stringify(data)); - }); - } - - public async clearFormUserCache() { - abilityManager.clearUpApplicationData('com.ohos.myapplicationform') - .then((data) => { - console.info('[FormComponent] cleanBundleCacheFiles result:' + JSON.stringify(data)); - }); - } - - public async clearFormProviderCache(bundle: string) { - abilityManager.clearUpApplicationData(bundle) - .then((data) => { - console.info('[FormComponent] cleanBundleCacheFiles result:' + JSON.stringify(data)); - }); - } -} \ No newline at end of file diff --git a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostf/entry/src/main/ets/MainAbility/pages/index.ets b/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostf/entry/src/main/ets/MainAbility/pages/index.ets index d9b8ad574b6be5bde708fb539e2f39876ad92358..02404deccbe974f4bfdd4d55d40299755fc3308b 100644 --- a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostf/entry/src/main/ets/MainAbility/pages/index.ets +++ b/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostf/entry/src/main/ets/MainAbility/pages/index.ets @@ -1,449 +1,427 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import FormViewModel from './FormViewModel.ets'; -import router from '@system.router'; -import featureAbility from '@ohos.ability.featureAbility'; -import formManager from '@ohos.application.formHost'; -import formProvider from '@ohos.application.formProvider'; -import commonEvent from '@ohos.commonEvent'; -import formBindingData from '@ohos.application.formBindingData'; - -@Entry -@Component -struct Index { - @State formId: number = 0; - @State bundle: string = "com.form.formsystemtestservicea.hmservice"; - @State ability: string = "com.form.formsystemtestservicea.hmservice.MainAbility"; - @State moduleName: string = "entry"; - @State name: string = "Form_Js001"; - @State width: number = 300; - @State height: number = 200; - @State allowUpate: boolean = true; - @State onAcquireResult: string = ""; - @State isShowing: boolean = true; - @State canCreateForm: boolean = false; - - private dimension: FormDimension = FormDimension.Dimension_1_2; - - private updateForm = false; - private updateId = "-1"; - private jsonEmpty = false; - private releaseForm = false; - private releaseId = "-1"; - private deleteForm = false; - private deleteId = "-1"; - private temporaryId="-1"; - private temporary = false; - private mFormViewModel: FormViewModel; - private isVisible = false; - private mMargin = 15; - private BTN_BG_COLOR: string = '#0D9FFB'; - private tempFormId: number = 0; - - private isStartOtherApp = false; - private otherAppState = "visible"; - - private formOnAcquiredEvent = "FMS_FormOnAcquired_commonEvent"; - private formOnErrorEvent = "FMS_FormOnError_commonEvent"; - private formOnDeletedEvent = "FMS_FormOnDeleted_commonEvent"; - private formOnReleasedEvent = "FMS_FormOnReleased_commonEvent"; - private formOnUpdatedEvent = "FMS_FormUpdateRefresh_commonEvent"; - - private subscriberDel; - private subscriberFormDeleteEvent = { - events: ["FMS_FormDelete_commonEvent"], - }; - - private publishOnErrorCallBack() { - this.canCreateForm = false; - console.debug("====>formsystemhostc formOnErrorEventCallBack ====>"); - } - private publishOnDeletedCallBack() { - this.canCreateForm = false; - console.debug("====>formsystemhostc publishOnDeletedCallBack ====>"); - } - private publishOnReleasedCallBack() { - this.canCreateForm = false; - console.debug("====>formsystemhostc publishOnReleasedCallBackk ====>"); - } - private publishOnAcquiredCallBack() { - console.debug("====>formsystemhostc formOnAcquiredEventCallBack ====>"); - } - private publishOnUpdatedCallBack() { - this.canCreateForm = false; - console.debug("====>formsystemhostc publishOnUpdatedCallBack ====>"); - } - private deleteCallBack(err, data) { - console.info("!!!====>formsystemhost deleteCallBack start:====>" + JSON.stringify(data)); - if(data.bundleName && data.bundleName != "com.ohos.st.formsystemhostf") { - return; - } - formManager.deleteForm(data.data) - .then((data2) => { - console.info('[FormComponent] deleteForm result:' + data2); - }); - - this.canCreateForm = false; - console.info("!!!====>formsystemhost deleteCallBack end ====>"); - } - - private unSubscribeDeleteCallback() { - console.debug("====>formsystemhost unSubscribeDeleteCallback_1100 CallBack====>"); - } - - private aboutToAppear() { - - const TAG = "[FormComponent.host]" - - this.mFormViewModel = FormViewModel.getInstance(); - - commonEvent.createSubscriber(this.subscriberFormDeleteEvent).then(async (data) => { - console.info("====>formsystemhost Subscriber FormDelete data:====>", JSON.stringify(data)); - this.subscriberDel = data; - await commonEvent.subscribe(this.subscriberDel, this.deleteCallBack); - }) - - console.error('[FormComponent] getWant'); - featureAbility.getWant() - .then((want: any) => { - this.formId = parseInt(want.parameters.formId); - this.name = want.parameters.name; - this.bundle = want.parameters.bundle; - this.ability = want.parameters.ability; - if(want.parameters.moduleName) { - this.moduleName = want.parameters.moduleName; - } - if(want.parameters.temporary) { - this.temporary = want.parameters.temporary; - } - if(want.parameters.dimension) { - this.dimension = want.parameters.dimension; - } - if(!this.dimension) { - this.dimension = FormDimension.Dimension_1_2; - } - if(want.parameters.temporaryId) { - this.temporaryId = want.parameters.temporaryId; - } - if(want.parameters.deleteForm) { - this.deleteForm = want.parameters.deleteForm; - } - if(want.parameters.deleteId) { - this.deleteId = want.parameters.deleteId; - } - if(want.parameters.releaseForm) { - this.releaseForm = want.parameters.releaseForm; - } - if(want.parameters.releaseId) { - this.releaseId = want.parameters.releaseId; - } - if(want.parameters.updateForm) { - this.updateForm = want.parameters.updateForm; - } - if(want.parameters.updateId) { - this.updateId = want.parameters.updateId; - } - if(want.parameters.jsonEmpty) { - this.jsonEmpty = want.parameters.jsonEmpty; - } - if(want.parameters.isStartOtherApp) { - this.isStartOtherApp = true; - if(want.parameters.otherAppState) { - this.otherAppState = want.parameters.otherAppState; - } - } - - setTimeout(() => { - this.canCreateForm = want.parameters.isCreate ? true : false; - console.error('[FormComponent] getWant canCreateForm:'+ this.canCreateForm); - }, 10); - console.error('[FormComponent] getWant end'+ JSON.stringify(want)); - - if(!want.parameters.isCreate && this.deleteForm) { - console.log("formsystemhost deleteForm start"); - formManager.deleteForm(this.deleteId) - .then((data) => { - console.info('formsystemhost deleteForm result:' + data); - let commonEventPublishData = { - data: "0", - parameters: { - "formId" : this.deleteId.toString() - } - }; - commonEvent.publish(this.formOnDeletedEvent, commonEventPublishData, this.publishOnDeletedCallBack); - }) - .catch((error) => { - console.info('formsystemhost deleteForm error:' + error); - let commonEventPublishData = { - data: error.code.toString(), - parameters: { - "formId" : this.deleteId.toString() - } - }; - commonEvent.publish(this.formOnDeletedEvent, commonEventPublishData, this.publishOnDeletedCallBack); - }); - - console.log("formsystemhost deleteForm end"); - } - - if(!want.parameters.isCreate && this.releaseForm) { - console.log("formsystemhost releaseForm start"); - formManager.releaseForm(this.releaseId) - .then((data) => { - console.info('formsystemhost releaseForm result:' + data); - let commonEventPublishData = { - data: "0", - parameters: { - "formId" : this.releaseId.toString() - } - }; - commonEvent.publish(this.formOnReleasedEvent, commonEventPublishData, this.publishOnReleasedCallBack); - }) - .catch((error) => { - console.info('formsystemhost releaseForm error:' + error); - let commonEventPublishData = { - data: error.code.toString(), - parameters: { - "formId" : this.releaseId.toString() - } - }; - commonEvent.publish(this.formOnReleasedEvent, commonEventPublishData, this.publishOnReleasedCallBack); - }); - - console.log("formsystemhost releaseForm end"); - } - - if(!want.parameters.isCreate && this.updateForm) { - console.log("formsystemhost updateForm start"); - let formData = { - temperature: "11°", - time: "11:00", - area: "Shenyang", - epidemic: true, - count: 10 - }; - if(this.jsonEmpty) { - formData = {}; - } - let bindingData = formBindingData.createFormBindingData(formData); - formProvider.updateForm(this.updateId, bindingData) - .then((data) => { - console.info('formsystemhost updateForm result:' + data); - let commonEventPublishData = { - data: "0", - parameters: { - "formId" : this.updateId - } - }; - commonEvent.publish(this.formOnUpdatedEvent, commonEventPublishData, this.publishOnUpdatedCallBack); - }) - .catch((error) => { - console.info('formsystemhost updateForm error:' + error); - let commonEventPublishData = { - data: error.code.toString(), - parameters: { - "formId" : this.updateId - } - }; - commonEvent.publish(this.formOnUpdatedEvent, commonEventPublishData, this.publishOnUpdatedCallBack); - }); - - console.log("formsystemhost releaseForm end"); - } - - }) - .catch((error: any) => { - console.error('[FormComponent] Operation failed. Cause: ' + JSON.stringify(error)); - }) - console.log(`[FormComponent.host] aboutToAppear end`); - } - - build() { - Column() { - Text('form component test begin') - Column() { - if (this.canCreateForm) { - FormComponent({ - id: this.formId, - name: this.name, - bundle: this.bundle, - ability: this.ability, - module: this.moduleName, - dimension: this.dimension, - temporary: this.temporary, - }) - .allowUpdate(this.allowUpate) - .visibility(this.isShowing ? Visibility.Visible : Visibility.Hidden) - .onAcquired((form) => { - console.log("[FormComponent.host] get form, form id:" + form.id); - this.formId = form.id; - if(this.deleteForm) { - console.log("[FormComponent.host] deleteForm start"); - if(this.deleteId == "self") { - this.deleteId = this.formId.toString(); - } - setTimeout(() => { - formManager.deleteForm(this.deleteId) - .then((data) => { - console.info('[FormComponent] deleteForm result:' + data); - var commonEventPublishData = { - data: "0", - parameters: { - "formId" : this.deleteId.toString() - } - }; - commonEvent.publish(this.formOnDeletedEvent, commonEventPublishData, this.publishOnDeletedCallBack); - }) - .catch((error) => { - console.info('formsystemhost deleteForm error:' + error); - let commonEventPublishData = { - data: error.code.toString(), - parameters: { - "formId" : this.deleteId.toString() - } - }; - commonEvent.publish(this.formOnDeletedEvent, commonEventPublishData, this.publishOnDeletedCallBack); - }); - console.log("[FormComponent.host] deleteForm end"); - }, 500); - } else if(this.releaseForm) { - console.log("[FormComponent.host] releaseForm start"); - if(this.releaseId == "self") { - this.releaseId = this.formId.toString(); - } - setTimeout(() => { - formManager.releaseForm(this.releaseId) - .then((data) => { - console.info('[FormComponent] releaseForm result:' + data); - var commonEventPublishData = { - data: "0", - parameters: { - "formId" : this.releaseId.toString() - } - }; - commonEvent.publish(this.formOnReleasedEvent, commonEventPublishData, this.publishOnReleasedCallBack); - }) - .catch((error) => { - console.info('formsystemhost releaseForm error:' + error); - let commonEventPublishData = { - data: error.code.toString(), - parameters: { - "formId" : this.releaseId.toString() - } - }; - commonEvent.publish(this.formOnReleasedEvent, commonEventPublishData, this.publishOnReleasedCallBack); - }); - - console.log("[FormComponent.host] releaseForm end"); - }, 500); - } else if (this.updateForm) { - console.log("formsystemhost updateForm start"); - let formData = { - temperature: "11°", - time: "11:00", - area: "Shenyang", - epidemic: true, - count: 10 - }; - if(this.jsonEmpty) { - formData = {}; - } - let bindingData = formBindingData.createFormBindingData(formData); - formProvider.updateForm(this.updateId, bindingData) - .then((data) => { - console.info('formsystemhost updateForm result:' + data); - let commonEventPublishData = { - data: "0", - parameters: { - "formId" : this.updateId - } - }; - commonEvent.publish(this.formOnUpdatedEvent, commonEventPublishData, this.publishOnUpdatedCallBack); - }) - .catch((error) => { - console.info('formsystemhost updateForm error:' + error); - let commonEventPublishData = { - data: error.code.toString(), - parameters: { - "formId" : this.updateId - } - }; - commonEvent.publish(this.formOnUpdatedEvent, commonEventPublishData, this.publishOnUpdatedCallBack); - }); - - console.log("formsystemhost releaseForm end"); - } else if (this.isStartOtherApp) { - console.log("formsystemhost app G start"); - featureAbility.startAbility({ - want: { - bundleName: "com.ohos.st.formsystemhostg", - abilityName: "com.ohos.st.formsystemhostg.MainAbility", - parameters: { - "formId" : "0", - "name" : "name", - "bundle" : "bundle", - "ability" : "ability", - "moduleName" : "entry", - "temporary" : false, - "stateForm" : this.otherAppState, - "stateIds" : [this.formId.toString()], - "isCreate" : false - } - } - }).then((res: any) => { - console.log(`formsystemhost featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); - }).catch((err: any) => { - console.log(`formsystemhost featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); - }); - } else { - var commonEventPublishData = { - data: this.formId.toString() - }; - commonEvent.publish(this.formOnAcquiredEvent, commonEventPublishData, this.publishOnAcquiredCallBack); - } - }) - // .onUninstall((info) => { - // console.log("[FormComponent] onUninstall:" + JSON.stringify(info)); - // }) - .onError((error) => { - console.log("[FormComponent.host] error code:" + error.errcode); - console.log("[FormComponent.host] error msg:" + error.msg); - this.onAcquireResult += error.errcode; - this.onAcquireResult += " "; - this.onAcquireResult += error.msg; - if(this.deleteForm && this.deleteId) { - let commonEventPublishData = { - data: error.msg, - parameters: { - "formId" : this.formId.toString() - } - }; - commonEvent.publish(this.formOnDeletedEvent, commonEventPublishData, this.publishOnDeletedCallBack); - } else { - let commonEventPublishData = { - data: error.msg - }; - commonEvent.publish(this.formOnErrorEvent, commonEventPublishData, this.publishOnErrorCallBack); - } - }) - } - } - .backgroundColor(Color.White) - Text('form component test end') - } - .backgroundColor(Color.White) - } +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import commonEvent from '@ohos.commonEvent'; +import featureAbility from '@ohos.ability.featureAbility'; +import formBindingData from '@ohos.application.formBindingData'; +import formManager from '@ohos.application.formHost'; +import formProvider from '@ohos.application.formProvider'; + +@Entry +@Component +struct Index { + @State formId: number = 0; + @State bundle: string = "com.form.formsystemtestservicea.hmservice"; + @State ability: string = "com.form.formsystemtestservicea.hmservice.MainAbility"; + @State moduleName: string = "entry"; + @State name: string = "Form_Js001"; + @State allowUpate: boolean = true; + @State isShowing: boolean = true; + @State canCreateForm: boolean = false; + + private dimension: FormDimension = FormDimension.Dimension_1_2; + + private updateForm = false; + private updateId = "-1"; + private jsonEmpty = false; + private releaseForm = false; + private releaseId = "-1"; + private deleteForm = false; + private deleteId = "-1"; + private temporaryId="-1"; + private temporary = false; + + private isStartOtherApp = false; + private otherAppState = "visible"; + + private formOnAcquiredEvent = "FMS_FormOnAcquired_commonEvent"; + private formOnErrorEvent = "FMS_FormOnError_commonEvent"; + private formOnDeletedEvent = "FMS_FormOnDeleted_commonEvent"; + private formOnReleasedEvent = "FMS_FormOnReleased_commonEvent"; + private formOnUpdatedEvent = "FMS_FormUpdateRefresh_commonEvent"; + + private subscriberDel; + private subscriberFormDeleteEvent = { + events: ["FMS_FormDelete_commonEvent"], + }; + + private publishOnErrorCallBack() { + this.canCreateForm = false; + console.debug("====>formsystemhostc formOnErrorEventCallBack ====>"); + } + private publishOnDeletedCallBack() { + this.canCreateForm = false; + console.debug("====>formsystemhostc publishOnDeletedCallBack ====>"); + } + private publishOnReleasedCallBack() { + this.canCreateForm = false; + console.debug("====>formsystemhostc publishOnReleasedCallBackk ====>"); + } + private publishOnAcquiredCallBack() { + console.debug("====>formsystemhostc formOnAcquiredEventCallBack ====>"); + } + private publishOnUpdatedCallBack() { + this.canCreateForm = false; + console.debug("====>formsystemhostc publishOnUpdatedCallBack ====>"); + } + private deleteCallBack(err, data) { + console.info("!!!====>formsystemhost deleteCallBack start:====>" + JSON.stringify(data)); + if(data.bundleName && data.bundleName != "com.ohos.st.formsystemhostf") { + return; + } + formManager.deleteForm(data.data) + .then((data2) => { + console.info('[FormComponent] deleteForm result:' + data2); + }); + + this.canCreateForm = false; + console.info("!!!====>formsystemhost deleteCallBack end ====>"); + } + + private aboutToAppear() { + commonEvent.createSubscriber(this.subscriberFormDeleteEvent).then(async (data) => { + console.info("====>formsystemhost Subscriber FormDelete data:====>", JSON.stringify(data)); + this.subscriberDel = data; + await commonEvent.subscribe(this.subscriberDel, this.deleteCallBack); + }) + + console.error('[FormComponent] getWant'); + featureAbility.getWant() + .then((want: any) => { + this.formId = parseInt(want.parameters.formId); + this.name = want.parameters.name; + this.bundle = want.parameters.bundle; + this.ability = want.parameters.ability; + if(want.parameters.moduleName) { + this.moduleName = want.parameters.moduleName; + } + if(want.parameters.temporary) { + this.temporary = want.parameters.temporary; + } + if(want.parameters.dimension) { + this.dimension = want.parameters.dimension; + } + if(!this.dimension) { + this.dimension = FormDimension.Dimension_1_2; + } + if(want.parameters.temporaryId) { + this.temporaryId = want.parameters.temporaryId; + } + if(want.parameters.deleteForm) { + this.deleteForm = want.parameters.deleteForm; + } + if(want.parameters.deleteId) { + this.deleteId = want.parameters.deleteId; + } + if(want.parameters.releaseForm) { + this.releaseForm = want.parameters.releaseForm; + } + if(want.parameters.releaseId) { + this.releaseId = want.parameters.releaseId; + } + if(want.parameters.updateForm) { + this.updateForm = want.parameters.updateForm; + } + if(want.parameters.updateId) { + this.updateId = want.parameters.updateId; + } + if(want.parameters.jsonEmpty) { + this.jsonEmpty = want.parameters.jsonEmpty; + } + if(want.parameters.isStartOtherApp) { + this.isStartOtherApp = true; + if(want.parameters.otherAppState) { + this.otherAppState = want.parameters.otherAppState; + } + } + + setTimeout(() => { + this.canCreateForm = want.parameters.isCreate ? true : false; + console.error('[FormComponent] getWant canCreateForm:'+ this.canCreateForm); + }, 10); + console.error('[FormComponent] getWant end'+ JSON.stringify(want)); + + if(!want.parameters.isCreate && this.deleteForm) { + console.log("formsystemhost deleteForm start"); + formManager.deleteForm(this.deleteId) + .then((data) => { + console.info('formsystemhost deleteForm result:' + data); + let commonEventPublishData = { + data: "0", + parameters: { + "formId" : this.deleteId.toString() + } + }; + commonEvent.publish(this.formOnDeletedEvent, commonEventPublishData, this.publishOnDeletedCallBack); + }) + .catch((error) => { + console.info('formsystemhost deleteForm error:' + error); + let commonEventPublishData = { + data: error.code.toString(), + parameters: { + "formId" : this.deleteId.toString() + } + }; + commonEvent.publish(this.formOnDeletedEvent, commonEventPublishData, this.publishOnDeletedCallBack); + }); + + console.log("formsystemhost deleteForm end"); + } + + if(!want.parameters.isCreate && this.releaseForm) { + console.log("formsystemhost releaseForm start"); + formManager.releaseForm(this.releaseId) + .then((data) => { + console.info('formsystemhost releaseForm result:' + data); + let commonEventPublishData = { + data: "0", + parameters: { + "formId" : this.releaseId.toString() + } + }; + commonEvent.publish(this.formOnReleasedEvent, commonEventPublishData, this.publishOnReleasedCallBack); + }) + .catch((error) => { + console.info('formsystemhost releaseForm error:' + error); + let commonEventPublishData = { + data: error.code.toString(), + parameters: { + "formId" : this.releaseId.toString() + } + }; + commonEvent.publish(this.formOnReleasedEvent, commonEventPublishData, this.publishOnReleasedCallBack); + }); + + console.log("formsystemhost releaseForm end"); + } + + if(!want.parameters.isCreate && this.updateForm) { + console.log("formsystemhost updateForm start"); + let formData = { + temperature: "11°", + time: "11:00", + area: "Shenyang", + epidemic: true, + count: 10 + }; + if(this.jsonEmpty) { + formData = {}; + } + let bindingData = formBindingData.createFormBindingData(formData); + formProvider.updateForm(this.updateId, bindingData) + .then((data) => { + console.info('formsystemhost updateForm result:' + data); + let commonEventPublishData = { + data: "0", + parameters: { + "formId" : this.updateId + } + }; + commonEvent.publish(this.formOnUpdatedEvent, commonEventPublishData, this.publishOnUpdatedCallBack); + }) + .catch((error) => { + console.info('formsystemhost updateForm error:' + error); + let commonEventPublishData = { + data: error.code.toString(), + parameters: { + "formId" : this.updateId + } + }; + commonEvent.publish(this.formOnUpdatedEvent, commonEventPublishData, this.publishOnUpdatedCallBack); + }); + + console.log("formsystemhost releaseForm end"); + } + + }) + .catch((error: any) => { + console.error('[FormComponent] Operation failed. Cause: ' + JSON.stringify(error)); + }) + console.log(`[FormComponent.host] aboutToAppear end`); + } + + build() { + Column() { + Text('form component test begin') + Column() { + if (this.canCreateForm) { + FormComponent({ + id: this.formId, + name: this.name, + bundle: this.bundle, + ability: this.ability, + module: this.moduleName, + dimension: this.dimension, + temporary: this.temporary, + }) + .allowUpdate(this.allowUpate) + .visibility(this.isShowing ? Visibility.Visible : Visibility.Hidden) + .onAcquired((form) => { + console.log("[FormComponent.host] get form, form id:" + form.id); + this.formId = form.id; + if(this.deleteForm) { + console.log("[FormComponent.host] deleteForm start"); + if(this.deleteId == "self") { + this.deleteId = this.formId.toString(); + } + setTimeout(() => { + formManager.deleteForm(this.deleteId) + .then((data) => { + console.info('[FormComponent] deleteForm result:' + data); + var commonEventPublishData = { + data: "0", + parameters: { + "formId" : this.deleteId.toString() + } + }; + commonEvent.publish(this.formOnDeletedEvent, commonEventPublishData, this.publishOnDeletedCallBack); + }) + .catch((error) => { + console.info('formsystemhost deleteForm error:' + error); + let commonEventPublishData = { + data: error.code.toString(), + parameters: { + "formId" : this.deleteId.toString() + } + }; + commonEvent.publish(this.formOnDeletedEvent, commonEventPublishData, this.publishOnDeletedCallBack); + }); + console.log("[FormComponent.host] deleteForm end"); + }, 500); + } else if(this.releaseForm) { + console.log("[FormComponent.host] releaseForm start"); + if(this.releaseId == "self") { + this.releaseId = this.formId.toString(); + } + setTimeout(() => { + formManager.releaseForm(this.releaseId) + .then((data) => { + console.info('[FormComponent] releaseForm result:' + data); + var commonEventPublishData = { + data: "0", + parameters: { + "formId" : this.releaseId.toString() + } + }; + commonEvent.publish(this.formOnReleasedEvent, commonEventPublishData, this.publishOnReleasedCallBack); + }) + .catch((error) => { + console.info('formsystemhost releaseForm error:' + error); + let commonEventPublishData = { + data: error.code.toString(), + parameters: { + "formId" : this.releaseId.toString() + } + }; + commonEvent.publish(this.formOnReleasedEvent, commonEventPublishData, this.publishOnReleasedCallBack); + }); + + console.log("[FormComponent.host] releaseForm end"); + }, 500); + } else if (this.updateForm) { + console.log("formsystemhost updateForm start"); + let formData = { + temperature: "11°", + time: "11:00", + area: "Shenyang", + epidemic: true, + count: 10 + }; + if(this.jsonEmpty) { + formData = {}; + } + let bindingData = formBindingData.createFormBindingData(formData); + formProvider.updateForm(this.updateId, bindingData) + .then((data) => { + console.info('formsystemhost updateForm result:' + data); + let commonEventPublishData = { + data: "0", + parameters: { + "formId" : this.updateId + } + }; + commonEvent.publish(this.formOnUpdatedEvent, commonEventPublishData, this.publishOnUpdatedCallBack); + }) + .catch((error) => { + console.info('formsystemhost updateForm error:' + error); + let commonEventPublishData = { + data: error.code.toString(), + parameters: { + "formId" : this.updateId + } + }; + commonEvent.publish(this.formOnUpdatedEvent, commonEventPublishData, this.publishOnUpdatedCallBack); + }); + + console.log("formsystemhost releaseForm end"); + } else if (this.isStartOtherApp) { + console.log("formsystemhost app G start"); + featureAbility.startAbility({ + want: { + bundleName: "com.ohos.st.formsystemhostg", + abilityName: "com.ohos.st.formsystemhostg.MainAbility", + parameters: { + "formId" : "0", + "name" : "name", + "bundle" : "bundle", + "ability" : "ability", + "moduleName" : "entry", + "temporary" : false, + "stateForm" : this.otherAppState, + "stateIds" : [this.formId.toString()], + "isCreate" : false + } + } + }).then((res: any) => { + console.log(`formsystemhost featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); + }).catch((err: any) => { + console.log(`formsystemhost featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); + }); + } else { + var commonEventPublishData = { + data: this.formId.toString() + }; + commonEvent.publish(this.formOnAcquiredEvent, commonEventPublishData, this.publishOnAcquiredCallBack); + } + }) + // .onUninstall((info) => { + // console.log("[FormComponent] onUninstall:" + JSON.stringify(info)); + // }) + .onError((error) => { + console.log("[FormComponent.host] error code:" + error.errcode); + console.log("[FormComponent.host] error msg:" + error.msg); + if(this.deleteForm && this.deleteId) { + let commonEventPublishData = { + data: error.msg, + parameters: { + "formId" : this.formId.toString() + } + }; + commonEvent.publish(this.formOnDeletedEvent, commonEventPublishData, this.publishOnDeletedCallBack); + } else { + let commonEventPublishData = { + data: error.msg + }; + commonEvent.publish(this.formOnErrorEvent, commonEventPublishData, this.publishOnErrorCallBack); + } + }) + } + } + .backgroundColor(Color.White) + Text('form component test end') + } + .backgroundColor(Color.White) + } } \ No newline at end of file diff --git a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostg/entry/src/main/ets/MainAbility/pages/FormViewModel.ets b/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostg/entry/src/main/ets/MainAbility/pages/FormViewModel.ets deleted file mode 100644 index 9b09225070d8baf4062cf466a595a441993ae53b..0000000000000000000000000000000000000000 --- a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostg/entry/src/main/ets/MainAbility/pages/FormViewModel.ets +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import formManager from '@ohos.ability.formmanager'; -import bundleManager from '@ohos.bundle'; -import abilityManager from '@ohos.app.abilityManager'; - -export default class FormViewModel { - private static sFormViewModel: FormViewModel = null; - - public static getInstance(): FormViewModel { - if (FormViewModel.sFormViewModel == null) { - FormViewModel.sFormViewModel = new FormViewModel(); - } - return FormViewModel.sFormViewModel; - } - - public async castTempFormToNormal(formId: string) { - formManager.castTempForm(formId) - .then((data) => { - console.info('[FormComponent] castTempForm result:' + data); - }); - } - - public async requestForm(formId: string) { - formManager.requestForm(formId) - .then((data) => { - console.info('[FormComponent] requestForm result:' + data); - }); - } - - public async deleteCard(formId: string) { - formManager.deleteForm(formId) - .then((data) => { - console.info('[FormComponent] deleteForm result:' + data); - }); - } - - public async releaseCard(formId: string) { - formManager.releaseForm(formId) - .then((data) => { - console.info('[FormComponent] releaseForm result:' + data); - }); - } - - public async enableCard(formId: string) { - formManager.enableFormsUpdate([formId]) - .then((data) => { - console.info('[FormComponent] enableFormsUpdate result:' + data); - }); - } - - public async disableCard(formId: string) { - formManager.disableFormsUpdate([formId]) - .then((data) => { - console.info('[FormComponent] disableCard result:' + data); - }); - } - - public async changeCardVisible(formId: string, isVisible: boolean) { - if (isVisible) { - formManager.notifyVisibleForms([formId]) - .then((data) => { - console.info('[FormComponent] changeCardVisible result:' + data + ', isVisible:' + isVisible); - }); - } else { - formManager.notifyInvisibleForms([formId]) - .then((data) => { - console.info('[FormComponent] changeCardVisible result:' + data + ', isVisible:' + isVisible); - }); - } - } - - public async isFmsReady() { - formManager.isSystemReady() - .then((data) => { - console.info('[FormComponent] isFmsReady result:' + data); - }); - } - - public async getAllFormsInfo() { - formManager.getAllFormsInfo() - .then((data) => { - console.info('[FormComponent] getAllFormsInfo result:' + JSON.stringify(data)); - }); - } - - public async getFormsInfoByApp(bundle: string) { - formManager.getFormsInfo(bundle) - .then((data) => { - console.info('[FormComponent] getFormsInfoByApp result:' + JSON.stringify(data)); - }); - } - - public async getFormsInfoByModule(bundle: string, moduleName: string) { - formManager.getFormsInfo(bundle, moduleName) - .then((data) => { - console.info('[FormComponent] getFormsInfoByModule result:' + JSON.stringify(data)); - }); - } - - public async clearFormUserCache() { - abilityManager.clearUpApplicationData('com.ohos.myapplicationform') - .then((data) => { - console.info('[FormComponent] cleanBundleCacheFiles result:' + JSON.stringify(data)); - }); - } - - public async clearFormProviderCache(bundle: string) { - abilityManager.clearUpApplicationData(bundle) - .then((data) => { - console.info('[FormComponent] cleanBundleCacheFiles result:' + JSON.stringify(data)); - }); - } -} \ No newline at end of file diff --git a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostg/entry/src/main/ets/MainAbility/pages/index.ets b/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostg/entry/src/main/ets/MainAbility/pages/index.ets index 792ce411807e1c1038bf5ce55b7f9ac9860a8a43..411f282e3147ba3adc7b7ab24f181dd82cb7da0c 100644 --- a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostg/entry/src/main/ets/MainAbility/pages/index.ets +++ b/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostg/entry/src/main/ets/MainAbility/pages/index.ets @@ -1,524 +1,502 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import FormViewModel from './FormViewModel.ets'; -import router from '@system.router'; -import featureAbility from "@ohos.ability.featureAbility"; -import formManager from '@ohos.application.formHost' -import commonEvent from '@ohos.commonEvent'; - -@Entry -@Component -struct Index { - @State formId: number = 0; - @State bundle: string = "com.form.formsystemtestservicea.hmservice"; - @State ability: string = "com.form.formsystemtestservicea.hmservice.MainAbility"; - @State moduleName: string = "entry"; - @State name: string = "Form_Js001"; - @State width: number = 300; - @State height: number = 200; - @State allowUpate: boolean = true; - @State onAcquireResult: string = ""; - @State isShowing: boolean = true; - @State canCreateForm: boolean = false; - - private dimension: FormDimension = FormDimension.Dimension_1_2; - - private stateForm = "visible"; - private doStateForm = false; - private stateIds = []; - private deleteForm = false; - private deleteId = "-1"; - private temporaryId="-1"; - private temporary = false; - private mFormViewModel: FormViewModel; - private isVisible = false; - private mMargin = 15; - private BTN_BG_COLOR: string = '#0D9FFB'; - private tempFormId: number = 0; - - private formOnAcquiredEvent = "FMS_FormOnAcquired_commonEvent"; - private formOnErrorEvent = "FMS_FormOnError_commonEvent"; - private formOnDeletedEvent = "FMS_FormOnDeleted_commonEvent"; - private formOnStateEvent = "FMS_FormOnState_commonEvent"; - - private subscriberDel; - private subscriberFormDeleteEvent = { - events: ["FMS_FormDelete_commonEvent"], - }; - - private publishOnErrorCallBack() { - this.canCreateForm = false; - console.debug("====>[FormComponent.host] formOnErrorEventCallBack ====>"); - } - private publishOnDeletedCallBack() { - this.canCreateForm = false; - console.debug("====>[FormComponent.host] publishOnDeletedCallBack ====>"); - } - private publishOnStateCallBack() { - this.canCreateForm = false; - console.debug("====>[FormComponent.host] publishOnStateCallBack ====>"); - } - private publishOnAcquiredCallBack() { - console.debug("====>[FormComponent.host] formOnAcquiredEventCallBack ====>"); - } - private deleteCallBack(err, data) { - console.info("!!!====>[FormComponent.host] deleteCallBack start:====>" + JSON.stringify(data)); - if(data.bundleName && data.bundleName != "com.ohos.st.formsystemhostg") { - return; - } - formManager.deleteForm(data.data) - .then((data2) => { - console.info('[FormComponent] deleteForm result:' + data2); - }); - - this.canCreateForm = false; - console.info("!!!====>[FormComponent.host] deleteCallBack end ====>"); - } - - private unSubscribeDeleteCallback() { - console.debug("====>[FormComponent.host] unSubscribeDeleteCallback_1100 CallBack====>"); - } - - private aboutToAppear() { - - const TAG = "[FormComponent.host]" - - this.mFormViewModel = FormViewModel.getInstance(); - - commonEvent.createSubscriber(this.subscriberFormDeleteEvent).then(async (data) => { - console.info("====>[FormComponent.host] Subscriber FormDelete data:====>", JSON.stringify(data)); - this.subscriberDel = data; - await commonEvent.subscribe(this.subscriberDel, this.deleteCallBack); - }) - - console.error('[FormComponent] getWant'); - featureAbility.getWant() - .then((want: any) => { - this.formId = parseInt(want.parameters.formId); - this.name = want.parameters.name; - this.bundle = want.parameters.bundle; - this.ability = want.parameters.ability; - if(want.parameters.moduleName) { - this.moduleName = want.parameters.moduleName; - } - if(want.parameters.temporary) { - this.temporary = want.parameters.temporary; - } - if(want.parameters.dimension) { - this.dimension = want.parameters.dimension; - } - if(!this.dimension) { - this.dimension = FormDimension.Dimension_1_2; - } - if(want.parameters.temporaryId) { - this.temporaryId = want.parameters.temporaryId; - } - if(want.parameters.deleteForm) { - this.deleteForm = want.parameters.deleteForm; - } - if(want.parameters.deleteId) { - this.deleteId = want.parameters.deleteId; - } - if(want.parameters.stateForm) { - this.stateForm = want.parameters.stateForm; - this.doStateForm = true; - } - if(want.parameters.stateIds) { - this.stateIds = want.parameters.stateIds; - } - setTimeout(() => { - this.canCreateForm = want.parameters.isCreate ? true : false; - console.error('[FormComponent] getWant canCreateForm:'+ this.canCreateForm); - }, 10); - console.error('[FormComponent] getWant end'+ JSON.stringify(want)); - - if(!want.parameters.isCreate && this.deleteForm) { - console.log("[FormComponent.host] deleteForm start"); - formManager.deleteForm(this.deleteId) - .then((data) => { - console.info('[FormComponent.host] deleteForm result:' + data); - let commonEventPublishData = { - data: "0", - parameters: { - "formId" : this.deleteId; - } - }; - commonEvent.publish(this.formOnDeletedEvent, commonEventPublishData, this.publishOnDeletedCallBack); - }) - .catch((error) => { - console.info('[FormComponent.host] deleteForm error:' + error); - let commonEventPublishData = { - data: error.code.toString(), - parameters: { - "formId" : this.deleteId; - } - }; - commonEvent.publish(this.formOnDeletedEvent, commonEventPublishData, this.publishOnDeletedCallBack); - }); - - console.log("[FormComponent.host] deleteForm end"); - } - - if(!want.parameters.isCreate && this.stateForm) { - if(this.stateForm == "visible") { - console.log("[FormComponent.host] notifyVisibleForm start"); - formManager.notifyVisibleForms(this.stateIds) - .then((data) => { - console.info('[FormComponent.host] notifyVisibleForm result:' + data); - console.info('[FormComponent.host] notifyVisibleForm formId:' + this.stateIds[0]); - let commonEventPublishData = { - data: "0", - parameters: { - "kind": "visible", - "formId" : this.stateIds[0] - } - }; - commonEvent.publish(this.formOnStateEvent, commonEventPublishData, this.publishOnStateCallBack); - }) - .catch((error) => { - console.info('[FormComponent.host] notifyVisibleForm error:' + error); - let commonEventPublishData = { - data: error.code.toString(), - parameters: { - "kind": "visible", - "formId" : this.stateIds[0] - } - }; - commonEvent.publish(this.formOnStateEvent, commonEventPublishData, this.publishOnStateCallBack); - }); - console.log("[FormComponent.host] notifyVisibleForm end"); - } else if(this.stateForm == "invisible") { - console.log("[FormComponent.host] notifyInvisibleForm start"); - formManager.notifyInvisibleForms(this.stateIds) - .then((data) => { - console.info('[FormComponent.host] notifyInvisibleForm result:' + data); - console.info('[FormComponent.host] notifyInvisibleForm formId:' + this.stateIds[0]); - let commonEventPublishData = { - data: "0", - parameters: { - "kind": "invisible", - "formId" : this.stateIds[0] - } - }; - commonEvent.publish(this.formOnStateEvent, commonEventPublishData, this.publishOnStateCallBack); - }) - .catch((error) => { - console.info('[FormComponent.host] notifyInvisibleForm error:' + error); - let commonEventPublishData = { - data: error.code.toString(), - parameters: { - "kind": "invisible", - "formId" : this.stateIds[0] - } - }; - commonEvent.publish(this.formOnStateEvent, commonEventPublishData, this.publishOnStateCallBack); - }); - console.log("[FormComponent.host] notifyInvisibleForm end"); - } else if(this.stateForm == "enable") { - console.log("[FormComponent.host] enableFormsUpdate start"); - formManager.enableFormsUpdate(this.stateIds) - .then((data) => { - console.info('[FormComponent.host] enableFormsUpdate result:' + data); - let commonEventPublishData = { - data: "0", - parameters: { - "kind": "enable", - "formId" : this.stateIds[0] - } - }; - commonEvent.publish(this.formOnStateEvent, commonEventPublishData, this.publishOnStateCallBack); - }) - .catch((error) => { - console.info('[FormComponent.host] enableFormsUpdate error:' + error); - let commonEventPublishData = { - data: error.code.toString(), - parameters: { - "kind": "enable", - "formId" : this.stateIds[0] - } - }; - commonEvent.publish(this.formOnStateEvent, commonEventPublishData, this.publishOnStateCallBack); - }); - console.log("[FormComponent.host] enableFormsUpdate end"); - } else { - console.log("[FormComponent.host] disableFormsUpdate start"); - formManager.disableFormsUpdate(this.stateIds) - .then((data) => { - console.info('[FormComponent.host] disableFormsUpdate result:' + data); - let commonEventPublishData = { - data: "0", - parameters: { - "kind": "disable", - "formId" : this.stateIds[0] - } - }; - commonEvent.publish(this.formOnStateEvent, commonEventPublishData, this.publishOnStateCallBack); - }) - .catch((error) => { - console.info('[FormComponent.host] disableFormsUpdate error:' + error); - let commonEventPublishData = { - data: error.code.toString(), - parameters: { - "kind": "disable", - "formId" : this.stateIds[0] - } - }; - commonEvent.publish(this.formOnStateEvent, commonEventPublishData, this.publishOnStateCallBack); - }); - console.log("[FormComponent.host] disableFormsUpdate end"); - } - } - - }) - .catch((error: any) => { - console.error('[FormComponent] Operation failed. Cause: ' + JSON.stringify(error)); - }) - console.log(`[FormComponent.host] aboutToAppear end`); - } - - build() { - Column() { - Text('form component test begin') - Column() { - if (this.canCreateForm) { - FormComponent({ - id: this.formId, - name: this.name, - bundle: this.bundle, - ability: this.ability, - module: this.moduleName, - dimension: this.dimension, - temporary: this.temporary, - }) - .allowUpdate(this.allowUpate) - .visibility(this.isShowing ? Visibility.Visible : Visibility.Hidden) - .onAcquired((form) => { - console.log("[FormComponent.host] get form, form id:" + form.id); - this.formId = form.id; - if(this.deleteForm) { - console.log("[FormComponent.host] deleteForm start"); - if(this.deleteId == "self") { - this.deleteId = this.formId.toString(); - } - setTimeout(() => { - formManager.deleteForm(this.deleteId) - .then((data) => { - console.info('[FormComponent] deleteForm result:' + data); - let commonEventPublishData = { - data: "0", - parameters: { - "formId" : this.deleteId; - } - }; - commonEvent.publish(this.formOnDeletedEvent, commonEventPublishData, this.publishOnDeletedCallBack); - }) - .catch((error) => { - console.info('[FormComponent.host] deleteForm error:' + error); - let commonEventPublishData = { - data: error.code.toString(), - parameters: { - "formId" : this.deleteId - } - }; - commonEvent.publish(this.formOnDeletedEvent, commonEventPublishData, this.publishOnDeletedCallBack); - }); - - console.log("[FormComponent.host] deleteForm end"); - }, 500); - } else if(this.doStateForm) { - console.log("[FormComponent.host] state start"); - if((this.stateIds.length != 0) && (this.stateIds[0] == "self")) { - this.stateIds = [this.formId.toString()]; - } - console.info('[FormComponent.host] notifyVisibleForm stateIds:' + this.stateIds); - setTimeout(() => { - if(this.stateForm == "visible") { - console.log("[FormComponent.host] notifyVisibleForm start"); - formManager.notifyVisibleForms(this.stateIds) - .then((data) => { - console.info('[FormComponent.host] notifyVisibleForm result:' + data); - console.info('[FormComponent.host] notifyVisibleForm formId:' + this.stateIds[0]); - if(this.stateIds.length == 0) { - this.stateIds = ["-1"]; - } - let commonEventPublishData = { - data: "0", - parameters: { - "kind": "visible", - "formId" : this.stateIds[0] - } - }; - commonEvent.publish(this.formOnStateEvent, commonEventPublishData, this.publishOnStateCallBack); - }) - .catch((error) => { - console.info('[FormComponent.host] notifyVisibleForm error:' + error); - if(this.stateIds.length == 0) { - this.stateIds = ["-1"]; - } - let commonEventPublishData = { - data: error.code.toString(), - parameters: { - "kind": "visible", - "formId" : this.stateIds[0] - } - }; - commonEvent.publish(this.formOnStateEvent, commonEventPublishData, this.publishOnStateCallBack); - }); - console.log("[FormComponent.host] notifyVisibleForm end"); - } else if(this.stateForm == "invisible") { - console.log("[FormComponent.host] notifyInvisibleForm start"); - formManager.notifyInvisibleForms(this.stateIds) - .then((data) => { - console.info('[FormComponent.host] notifyInvisibleForm result:' + data); - if(this.stateIds.length == 0) { - this.stateIds = ["-1"]; - } - console.info('[FormComponent.host] notifyInvisibleForm formId:' + this.stateIds[0]); - let commonEventPublishData = { - data: "0", - parameters: { - "kind": "invisible", - "formId" : this.stateIds[0] - } - }; - commonEvent.publish(this.formOnStateEvent, commonEventPublishData, this.publishOnStateCallBack); - }) - .catch((error) => { - console.info('[FormComponent.host] notifyInvisibleForm error:' + error.code); - if(this.stateIds.length == 0) { - this.stateIds = ["-1"]; - } - let commonEventPublishData = { - data: error.code.toString(), - parameters: { - "kind": "invisible", - "formId" : this.stateIds[0] - } - }; - commonEvent.publish(this.formOnStateEvent, commonEventPublishData, this.publishOnStateCallBack); - }); - console.log("[FormComponent.host] notifyInvisibleForm end"); - } else if(this.stateForm == "enable") { - console.log("[FormComponent.host] enableFormsUpdate start"); - formManager.enableFormsUpdate(this.stateIds) - .then((data) => { - console.info('[FormComponent.host] enableFormsUpdate result:' + data); - if(this.stateIds.length == 0) { - this.stateIds = ["-1"]; - } - let commonEventPublishData = { - data: "0", - parameters: { - "kind": "enable", - "formId" : this.stateIds[0] - } - }; - commonEvent.publish(this.formOnStateEvent, commonEventPublishData, this.publishOnStateCallBack); - }) - .catch((error) => { - console.info('[FormComponent.host] enableFormsUpdate error:' + error); - if(this.stateIds.length == 0) { - this.stateIds = ["-1"]; - } - let commonEventPublishData = { - data: error.code.toString(), - parameters: { - "kind": "enable", - "formId" : this.stateIds[0] - } - }; - commonEvent.publish(this.formOnStateEvent, commonEventPublishData, this.publishOnStateCallBack); - }); - console.log("[FormComponent.host] enableFormsUpdate end"); - } else { - console.log("[FormComponent.host] disableFormsUpdate start"); - formManager.disableFormsUpdate(this.stateIds) - .then((data) => { - console.info('[FormComponent.host] disableFormsUpdate result:' + data); - if(this.stateIds.length == 0) { - this.stateIds = ["-1"]; - } - let commonEventPublishData = { - data: "0", - parameters: { - "kind": "disable", - "formId" : this.stateIds[0] - } - }; - commonEvent.publish(this.formOnStateEvent, commonEventPublishData, this.publishOnStateCallBack); - }) - .catch((error) => { - console.info('[FormComponent.host] disableFormsUpdate error:' + error); - if(this.stateIds.length == 0) { - this.stateIds = ["-1"]; - } - let commonEventPublishData = { - data: error.code.toString(), - parameters: { - "kind": "disable", - "formId" : this.stateIds[0] - } - }; - commonEvent.publish(this.formOnStateEvent, commonEventPublishData, this.publishOnStateCallBack); - }); - console.log("[FormComponent.host] disableFormsUpdate end"); - } - }, 1000); - } else { - let commonEventPublishData = { - data: this.formId.toString(), - parameters: { - "formId" : this.formId.toString() - } - }; - commonEvent.publish(this.formOnAcquiredEvent, commonEventPublishData, this.publishOnAcquiredCallBack); - } - }) - .onUninstall((info) => { - console.log("[FormComponent] onUninstall:" + JSON.stringify(info)); - }) - .onError((error) => { - console.log("[FormComponent.host] error code:" + error.errcode); - console.log("[FormComponent.host] error msg:" + error.msg); - this.onAcquireResult += error.errcode; - this.onAcquireResult += " "; - this.onAcquireResult += error.msg; - if(this.deleteForm && this.deleteId) { - let commonEventPublishData = { - data: error.msg, - parameters: { - "formId" : this.formId.toString() - } - }; - commonEvent.publish(this.formOnDeletedEvent, commonEventPublishData, this.publishOnDeletedCallBack); - } else { - let commonEventPublishData = { - data: error.msg, - parameters: { - "formId" : "-1" - } - }; - commonEvent.publish(this.formOnErrorEvent, commonEventPublishData, this.publishOnErrorCallBack); - } - }) - } - } - .backgroundColor(Color.White) - Text('form component test end') - } - .backgroundColor(Color.White) - } +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import commonEvent from '@ohos.commonEvent'; +import featureAbility from "@ohos.ability.featureAbility"; +import formManager from '@ohos.application.formHost'; + +@Entry +@Component +struct Index { + @State formId: number = 0; + @State bundle: string = "com.form.formsystemtestservicea.hmservice"; + @State ability: string = "com.form.formsystemtestservicea.hmservice.MainAbility"; + @State moduleName: string = "entry"; + @State name: string = "Form_Js001"; + @State allowUpate: boolean = true; + @State isShowing: boolean = true; + @State canCreateForm: boolean = false; + + private dimension: FormDimension = FormDimension.Dimension_1_2; + + private stateForm = "visible"; + private doStateForm = false; + private stateIds = []; + private deleteForm = false; + private deleteId = "-1"; + private temporaryId="-1"; + private temporary = false; + + private formOnAcquiredEvent = "FMS_FormOnAcquired_commonEvent"; + private formOnErrorEvent = "FMS_FormOnError_commonEvent"; + private formOnDeletedEvent = "FMS_FormOnDeleted_commonEvent"; + private formOnStateEvent = "FMS_FormOnState_commonEvent"; + + private subscriberDel; + private subscriberFormDeleteEvent = { + events: ["FMS_FormDelete_commonEvent"], + }; + + private publishOnErrorCallBack() { + this.canCreateForm = false; + console.debug("====>[FormComponent.host] formOnErrorEventCallBack ====>"); + } + private publishOnDeletedCallBack() { + this.canCreateForm = false; + console.debug("====>[FormComponent.host] publishOnDeletedCallBack ====>"); + } + private publishOnStateCallBack() { + this.canCreateForm = false; + console.debug("====>[FormComponent.host] publishOnStateCallBack ====>"); + } + private publishOnAcquiredCallBack() { + console.debug("====>[FormComponent.host] formOnAcquiredEventCallBack ====>"); + } + private deleteCallBack(err, data) { + console.info("!!!====>[FormComponent.host] deleteCallBack start:====>" + JSON.stringify(data)); + if(data.bundleName && data.bundleName != "com.ohos.st.formsystemhostg") { + return; + } + formManager.deleteForm(data.data) + .then((data2) => { + console.info('[FormComponent] deleteForm result:' + data2); + }); + + this.canCreateForm = false; + console.info("!!!====>[FormComponent.host] deleteCallBack end ====>"); + } + + private aboutToAppear() { + commonEvent.createSubscriber(this.subscriberFormDeleteEvent).then(async (data) => { + console.info("====>[FormComponent.host] Subscriber FormDelete data:====>", JSON.stringify(data)); + this.subscriberDel = data; + await commonEvent.subscribe(this.subscriberDel, this.deleteCallBack); + }) + + console.error('[FormComponent] getWant'); + featureAbility.getWant() + .then((want: any) => { + this.formId = parseInt(want.parameters.formId); + this.name = want.parameters.name; + this.bundle = want.parameters.bundle; + this.ability = want.parameters.ability; + if(want.parameters.moduleName) { + this.moduleName = want.parameters.moduleName; + } + if(want.parameters.temporary) { + this.temporary = want.parameters.temporary; + } + if(want.parameters.dimension) { + this.dimension = want.parameters.dimension; + } + if(!this.dimension) { + this.dimension = FormDimension.Dimension_1_2; + } + if(want.parameters.temporaryId) { + this.temporaryId = want.parameters.temporaryId; + } + if(want.parameters.deleteForm) { + this.deleteForm = want.parameters.deleteForm; + } + if(want.parameters.deleteId) { + this.deleteId = want.parameters.deleteId; + } + if(want.parameters.stateForm) { + this.stateForm = want.parameters.stateForm; + this.doStateForm = true; + } + if(want.parameters.stateIds) { + this.stateIds = want.parameters.stateIds; + } + setTimeout(() => { + this.canCreateForm = want.parameters.isCreate ? true : false; + console.error('[FormComponent] getWant canCreateForm:'+ this.canCreateForm); + }, 10); + console.error('[FormComponent] getWant end'+ JSON.stringify(want)); + + if(!want.parameters.isCreate && this.deleteForm) { + console.log("[FormComponent.host] deleteForm start"); + formManager.deleteForm(this.deleteId) + .then((data) => { + console.info('[FormComponent.host] deleteForm result:' + data); + let commonEventPublishData = { + data: "0", + parameters: { + "formId" : this.deleteId; + } + }; + commonEvent.publish(this.formOnDeletedEvent, commonEventPublishData, this.publishOnDeletedCallBack); + }) + .catch((error) => { + console.info('[FormComponent.host] deleteForm error:' + error); + let commonEventPublishData = { + data: error.code.toString(), + parameters: { + "formId" : this.deleteId; + } + }; + commonEvent.publish(this.formOnDeletedEvent, commonEventPublishData, this.publishOnDeletedCallBack); + }); + + console.log("[FormComponent.host] deleteForm end"); + } + + if(!want.parameters.isCreate && this.stateForm) { + if(this.stateForm == "visible") { + console.log("[FormComponent.host] notifyVisibleForm start"); + formManager.notifyVisibleForms(this.stateIds) + .then((data) => { + console.info('[FormComponent.host] notifyVisibleForm result:' + data); + console.info('[FormComponent.host] notifyVisibleForm formId:' + this.stateIds[0]); + let commonEventPublishData = { + data: "0", + parameters: { + "kind": "visible", + "formId" : this.stateIds[0] + } + }; + commonEvent.publish(this.formOnStateEvent, commonEventPublishData, this.publishOnStateCallBack); + }) + .catch((error) => { + console.info('[FormComponent.host] notifyVisibleForm error:' + error); + let commonEventPublishData = { + data: error.code.toString(), + parameters: { + "kind": "visible", + "formId" : this.stateIds[0] + } + }; + commonEvent.publish(this.formOnStateEvent, commonEventPublishData, this.publishOnStateCallBack); + }); + console.log("[FormComponent.host] notifyVisibleForm end"); + } else if(this.stateForm == "invisible") { + console.log("[FormComponent.host] notifyInvisibleForm start"); + formManager.notifyInvisibleForms(this.stateIds) + .then((data) => { + console.info('[FormComponent.host] notifyInvisibleForm result:' + data); + console.info('[FormComponent.host] notifyInvisibleForm formId:' + this.stateIds[0]); + let commonEventPublishData = { + data: "0", + parameters: { + "kind": "invisible", + "formId" : this.stateIds[0] + } + }; + commonEvent.publish(this.formOnStateEvent, commonEventPublishData, this.publishOnStateCallBack); + }) + .catch((error) => { + console.info('[FormComponent.host] notifyInvisibleForm error:' + error); + let commonEventPublishData = { + data: error.code.toString(), + parameters: { + "kind": "invisible", + "formId" : this.stateIds[0] + } + }; + commonEvent.publish(this.formOnStateEvent, commonEventPublishData, this.publishOnStateCallBack); + }); + console.log("[FormComponent.host] notifyInvisibleForm end"); + } else if(this.stateForm == "enable") { + console.log("[FormComponent.host] enableFormsUpdate start"); + formManager.enableFormsUpdate(this.stateIds) + .then((data) => { + console.info('[FormComponent.host] enableFormsUpdate result:' + data); + let commonEventPublishData = { + data: "0", + parameters: { + "kind": "enable", + "formId" : this.stateIds[0] + } + }; + commonEvent.publish(this.formOnStateEvent, commonEventPublishData, this.publishOnStateCallBack); + }) + .catch((error) => { + console.info('[FormComponent.host] enableFormsUpdate error:' + error); + let commonEventPublishData = { + data: error.code.toString(), + parameters: { + "kind": "enable", + "formId" : this.stateIds[0] + } + }; + commonEvent.publish(this.formOnStateEvent, commonEventPublishData, this.publishOnStateCallBack); + }); + console.log("[FormComponent.host] enableFormsUpdate end"); + } else { + console.log("[FormComponent.host] disableFormsUpdate start"); + formManager.disableFormsUpdate(this.stateIds) + .then((data) => { + console.info('[FormComponent.host] disableFormsUpdate result:' + data); + let commonEventPublishData = { + data: "0", + parameters: { + "kind": "disable", + "formId" : this.stateIds[0] + } + }; + commonEvent.publish(this.formOnStateEvent, commonEventPublishData, this.publishOnStateCallBack); + }) + .catch((error) => { + console.info('[FormComponent.host] disableFormsUpdate error:' + error); + let commonEventPublishData = { + data: error.code.toString(), + parameters: { + "kind": "disable", + "formId" : this.stateIds[0] + } + }; + commonEvent.publish(this.formOnStateEvent, commonEventPublishData, this.publishOnStateCallBack); + }); + console.log("[FormComponent.host] disableFormsUpdate end"); + } + } + + }) + .catch((error: any) => { + console.error('[FormComponent] Operation failed. Cause: ' + JSON.stringify(error)); + }) + console.log(`[FormComponent.host] aboutToAppear end`); + } + + build() { + Column() { + Text('form component test begin') + Column() { + if (this.canCreateForm) { + FormComponent({ + id: this.formId, + name: this.name, + bundle: this.bundle, + ability: this.ability, + module: this.moduleName, + dimension: this.dimension, + temporary: this.temporary, + }) + .allowUpdate(this.allowUpate) + .visibility(this.isShowing ? Visibility.Visible : Visibility.Hidden) + .onAcquired((form) => { + console.log("[FormComponent.host] get form, form id:" + form.id); + this.formId = form.id; + if(this.deleteForm) { + console.log("[FormComponent.host] deleteForm start"); + if(this.deleteId == "self") { + this.deleteId = this.formId.toString(); + } + setTimeout(() => { + formManager.deleteForm(this.deleteId) + .then((data) => { + console.info('[FormComponent] deleteForm result:' + data); + let commonEventPublishData = { + data: "0", + parameters: { + "formId" : this.deleteId; + } + }; + commonEvent.publish(this.formOnDeletedEvent, commonEventPublishData, this.publishOnDeletedCallBack); + }) + .catch((error) => { + console.info('[FormComponent.host] deleteForm error:' + error); + let commonEventPublishData = { + data: error.code.toString(), + parameters: { + "formId" : this.deleteId + } + }; + commonEvent.publish(this.formOnDeletedEvent, commonEventPublishData, this.publishOnDeletedCallBack); + }); + + console.log("[FormComponent.host] deleteForm end"); + }, 500); + } else if(this.doStateForm) { + console.log("[FormComponent.host] state start"); + if((this.stateIds.length != 0) && (this.stateIds[0] == "self")) { + this.stateIds = [this.formId.toString()]; + } + console.info('[FormComponent.host] notifyVisibleForm stateIds:' + this.stateIds); + setTimeout(() => { + if(this.stateForm == "visible") { + console.log("[FormComponent.host] notifyVisibleForm start"); + formManager.notifyVisibleForms(this.stateIds) + .then((data) => { + console.info('[FormComponent.host] notifyVisibleForm result:' + data); + console.info('[FormComponent.host] notifyVisibleForm formId:' + this.stateIds[0]); + if(this.stateIds.length == 0) { + this.stateIds = ["-1"]; + } + let commonEventPublishData = { + data: "0", + parameters: { + "kind": "visible", + "formId" : this.stateIds[0] + } + }; + commonEvent.publish(this.formOnStateEvent, commonEventPublishData, this.publishOnStateCallBack); + }) + .catch((error) => { + console.info('[FormComponent.host] notifyVisibleForm error:' + error); + if(this.stateIds.length == 0) { + this.stateIds = ["-1"]; + } + let commonEventPublishData = { + data: error.code.toString(), + parameters: { + "kind": "visible", + "formId" : this.stateIds[0] + } + }; + commonEvent.publish(this.formOnStateEvent, commonEventPublishData, this.publishOnStateCallBack); + }); + console.log("[FormComponent.host] notifyVisibleForm end"); + } else if(this.stateForm == "invisible") { + console.log("[FormComponent.host] notifyInvisibleForm start"); + formManager.notifyInvisibleForms(this.stateIds) + .then((data) => { + console.info('[FormComponent.host] notifyInvisibleForm result:' + data); + if(this.stateIds.length == 0) { + this.stateIds = ["-1"]; + } + console.info('[FormComponent.host] notifyInvisibleForm formId:' + this.stateIds[0]); + let commonEventPublishData = { + data: "0", + parameters: { + "kind": "invisible", + "formId" : this.stateIds[0] + } + }; + commonEvent.publish(this.formOnStateEvent, commonEventPublishData, this.publishOnStateCallBack); + }) + .catch((error) => { + console.info('[FormComponent.host] notifyInvisibleForm error:' + error.code); + if(this.stateIds.length == 0) { + this.stateIds = ["-1"]; + } + let commonEventPublishData = { + data: error.code.toString(), + parameters: { + "kind": "invisible", + "formId" : this.stateIds[0] + } + }; + commonEvent.publish(this.formOnStateEvent, commonEventPublishData, this.publishOnStateCallBack); + }); + console.log("[FormComponent.host] notifyInvisibleForm end"); + } else if(this.stateForm == "enable") { + console.log("[FormComponent.host] enableFormsUpdate start"); + formManager.enableFormsUpdate(this.stateIds) + .then((data) => { + console.info('[FormComponent.host] enableFormsUpdate result:' + data); + if(this.stateIds.length == 0) { + this.stateIds = ["-1"]; + } + let commonEventPublishData = { + data: "0", + parameters: { + "kind": "enable", + "formId" : this.stateIds[0] + } + }; + commonEvent.publish(this.formOnStateEvent, commonEventPublishData, this.publishOnStateCallBack); + }) + .catch((error) => { + console.info('[FormComponent.host] enableFormsUpdate error:' + error); + if(this.stateIds.length == 0) { + this.stateIds = ["-1"]; + } + let commonEventPublishData = { + data: error.code.toString(), + parameters: { + "kind": "enable", + "formId" : this.stateIds[0] + } + }; + commonEvent.publish(this.formOnStateEvent, commonEventPublishData, this.publishOnStateCallBack); + }); + console.log("[FormComponent.host] enableFormsUpdate end"); + } else { + console.log("[FormComponent.host] disableFormsUpdate start"); + formManager.disableFormsUpdate(this.stateIds) + .then((data) => { + console.info('[FormComponent.host] disableFormsUpdate result:' + data); + if(this.stateIds.length == 0) { + this.stateIds = ["-1"]; + } + let commonEventPublishData = { + data: "0", + parameters: { + "kind": "disable", + "formId" : this.stateIds[0] + } + }; + commonEvent.publish(this.formOnStateEvent, commonEventPublishData, this.publishOnStateCallBack); + }) + .catch((error) => { + console.info('[FormComponent.host] disableFormsUpdate error:' + error); + if(this.stateIds.length == 0) { + this.stateIds = ["-1"]; + } + let commonEventPublishData = { + data: error.code.toString(), + parameters: { + "kind": "disable", + "formId" : this.stateIds[0] + } + }; + commonEvent.publish(this.formOnStateEvent, commonEventPublishData, this.publishOnStateCallBack); + }); + console.log("[FormComponent.host] disableFormsUpdate end"); + } + }, 1000); + } else { + let commonEventPublishData = { + data: this.formId.toString(), + parameters: { + "formId" : this.formId.toString() + } + }; + commonEvent.publish(this.formOnAcquiredEvent, commonEventPublishData, this.publishOnAcquiredCallBack); + } + }) + .onUninstall((info) => { + console.log("[FormComponent] onUninstall:" + JSON.stringify(info)); + }) + .onError((error) => { + console.log("[FormComponent.host] error code:" + error.errcode); + console.log("[FormComponent.host] error msg:" + error.msg); + if(this.deleteForm && this.deleteId) { + let commonEventPublishData = { + data: error.msg, + parameters: { + "formId" : this.formId.toString() + } + }; + commonEvent.publish(this.formOnDeletedEvent, commonEventPublishData, this.publishOnDeletedCallBack); + } else { + let commonEventPublishData = { + data: error.msg, + parameters: { + "formId" : "-1" + } + }; + commonEvent.publish(this.formOnErrorEvent, commonEventPublishData, this.publishOnErrorCallBack); + } + }) + } + } + .backgroundColor(Color.White) + Text('form component test end') + } + .backgroundColor(Color.White) + } } \ No newline at end of file diff --git a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhosti/entry/src/main/ets/MainAbility/pages/FormViewModel.ets b/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhosti/entry/src/main/ets/MainAbility/pages/FormViewModel.ets deleted file mode 100644 index dc72a2fb08469f1728b24fd8257a522d602af27c..0000000000000000000000000000000000000000 --- a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhosti/entry/src/main/ets/MainAbility/pages/FormViewModel.ets +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import formManager from '@ohos.application.formHost'; -import bundleManager from '@ohos.bundle'; -import abilityManager from '@ohos.app.abilityManager'; - -export default class FormViewModel { - private static sFormViewModel: FormViewModel = null; - - public static getInstance(): FormViewModel { - if (FormViewModel.sFormViewModel == null) { - FormViewModel.sFormViewModel = new FormViewModel(); - } - return FormViewModel.sFormViewModel; - } - - public async castTempFormToNormal(formId: string) { - formManager.castTempForm(formId) - .then((data) => { - console.info('[FormComponent] castTempForm result:' + data); - }); - } - - public async requestForm(formId: string) { - formManager.requestForm(formId) - .then((data) => { - console.info('[FormComponent] requestForm result:' + data); - }); - } - - public async deleteCard(formId: string) { - formManager.deleteForm(formId) - .then((data) => { - console.info('[FormComponent] deleteForm result:' + data); - }); - } - - public async releaseCard(formId: string) { - formManager.releaseForm(formId) - .then((data) => { - console.info('[FormComponent] releaseForm result:' + data); - }); - } - - public async enableCard(formId: string) { - formManager.enableFormsUpdate([formId]) - .then((data) => { - console.info('[FormComponent] enableFormsUpdate result:' + data); - }); - } - - public async disableCard(formId: string) { - formManager.disableFormsUpdate([formId]) - .then((data) => { - console.info('[FormComponent] disableCard result:' + data); - }); - } - - public async changeCardVisible(formId: string, isVisible: boolean) { - if (isVisible) { - formManager.notifyVisibleForms([formId]) - .then((data) => { - console.info('[FormComponent] changeCardVisible result:' + data + ', isVisible:' + isVisible); - }); - } else { - formManager.notifyInvisibleForms([formId]) - .then((data) => { - console.info('[FormComponent] changeCardVisible result:' + data + ', isVisible:' + isVisible); - }); - } - } - - public async isFmsReady() { - formManager.isSystemReady() - .then((data) => { - console.info('[FormComponent] isFmsReady result:' + data); - }); - } - - public async getAllFormsInfo() { - formManager.getAllFormsInfo() - .then((data) => { - console.info('[FormComponent] getAllFormsInfo result:' + JSON.stringify(data)); - }); - } - - public async getFormsInfoByApp(bundle: string) { - formManager.getFormsInfo(bundle) - .then((data) => { - console.info('[FormComponent] getFormsInfoByApp result:' + JSON.stringify(data)); - }); - } - - public async getFormsInfoByModule(bundle: string, moduleName: string) { - formManager.getFormsInfo(bundle, moduleName) - .then((data) => { - console.info('[FormComponent] getFormsInfoByModule result:' + JSON.stringify(data)); - }); - } - - public async clearFormUserCache() { - abilityManager.clearUpApplicationData('com.ohos.myapplicationform') - .then((data) => { - console.info('[FormComponent] cleanBundleCacheFiles result:' + JSON.stringify(data)); - }); - } - - public async clearFormProviderCache(bundle: string) { - abilityManager.clearUpApplicationData(bundle) - .then((data) => { - console.info('[FormComponent] cleanBundleCacheFiles result:' + JSON.stringify(data)); - }); - } -} \ No newline at end of file diff --git a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhosti/entry/src/main/ets/MainAbility/pages/index.ets b/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhosti/entry/src/main/ets/MainAbility/pages/index.ets index 0d7d51e9567e3ab0de3e49f5a71be21f6e592595..14318ae2da62da2ec4af8f00fec1f06c937fbe3e 100644 --- a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhosti/entry/src/main/ets/MainAbility/pages/index.ets +++ b/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhosti/entry/src/main/ets/MainAbility/pages/index.ets @@ -13,10 +13,10 @@ * limitations under the License. */ +import commonEvent from '@ohos.commonEvent'; import featureAbility from "@ohos.ability.featureAbility"; import formManager from '@ohos.application.formHost'; -import commonEvent from '@ohos.commonEvent'; -import FormViewModel from './FormViewModel.ets'; + @Entry @Component struct Index { @@ -25,10 +25,7 @@ struct Index { @State ability: string = "com.form.formsystemtestservicea.hmservice.MainAbility"; @State moduleName: string = "entry"; @State name: string = "Form_Js001"; - @State width: number = 300; - @State height: number = 200; @State allowUpate: boolean = true; - @State onAcquireResult: string = ""; @State isShowing: boolean = true; @State canCreateForm: boolean = false; @@ -37,12 +34,7 @@ struct Index { private deleteId = "-1"; private temporaryId = "-1"; private temporary = false; - private mFormViewModel: FormViewModel; - private isVisible = false; - private mMargin = 15; - private BTN_BG_COLOR: string = '#0D9FFB'; private castForm = false; - private tempFormId: number = 0; private formOnAcquiredEvent = "FMS_FormOnAcquired_commonEvent"; private formCastEvent = "FMS_FormCast_commonEvent"; @@ -78,16 +70,7 @@ struct Index { console.info("!!!====>formsystemhost deleteCallBack end ====>"); } - private unSubscribeDeleteCallback() { - console.info("====>formsystemhost unSubscribeDeleteCallback_1100 CallBack====>"); - } - private aboutToAppear() { - - const TAG = "[FormComponent.host]" - - this.mFormViewModel = FormViewModel.getInstance(); - commonEvent.createSubscriber(this.subscriberFormDeleteEvent).then(async (data) => { console.info("====>formsystemhost Subscriber FormDelete data:====>", JSON.stringify(data)); this.subscriberDel = data; @@ -282,9 +265,6 @@ struct Index { .onError((error) => { console.info("[FormComponent.host] error code:" + error.errcode); console.info("[FormComponent.host] error msg:" + error.msg); - this.onAcquireResult += error.errcode; - this.onAcquireResult += " "; - this.onAcquireResult += error.msg; if (this.deleteForm && this.deleteId) { let commonEventPublishData = { data: error.msg, diff --git a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostj/entry/src/main/ets/MainAbility/pages/FormViewModel.ets b/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostj/entry/src/main/ets/MainAbility/pages/FormViewModel.ets deleted file mode 100644 index cb25732d908c6cc580d69de1ae9984cde6230774..0000000000000000000000000000000000000000 --- a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostj/entry/src/main/ets/MainAbility/pages/FormViewModel.ets +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import formManager from '@ohos.ability.formmanager'; -import bundleManager from '@ohos.bundle'; -import abilityManager from '@ohos.app.abilityManager'; - -export default class FormViewModel { - private static sFormViewModel: FormViewModel = null; - - public static getInstance(): FormViewModel { - if (FormViewModel.sFormViewModel == null) { - FormViewModel.sFormViewModel = new FormViewModel(); - } - return FormViewModel.sFormViewModel; - } - - public async castTempFormToNormal(formId: string) { - formManager.castTempForm(formId) - .then((data) => { - console.info('[FormComponent] castTempForm result:' + data); - }); - } - - public async requestForm(formId: string) { - formManager.requestForm(formId) - .then((data) => { - console.info('[FormComponent] requestForm result:' + data); - }); - } - - public async deleteCard(formId: string) { - formManager.deleteForm(formId) - .then((data) => { - console.info('[FormComponent] deleteForm result:' + data); - }); - } - - public async releaseCard(formId: string) { - formManager.releaseForm(formId) - .then((data) => { - console.info('[FormComponent] releaseForm result:' + data); - }); - } - - public async enableCard(formId: string) { - formManager.enableFormsUpdate([formId]) - .then((data) => { - console.info('[FormComponent] enableFormsUpdate result:' + data); - }); - } - - public async disableCard(formId: string) { - formManager.disableFormsUpdate([formId]) - .then((data) => { - console.info('[FormComponent] disableCard result:' + data); - }); - } - - public async changeCardVisible(formId: string, isVisible: boolean) { - if (isVisible) { - formManager.notifyVisibleForms([formId]) - .then((data) => { - console.info('[FormComponent] changeCardVisible result:' + data + ', isVisible:' + isVisible); - }); - } else { - formManager.notifyInvisibleForms([formId]) - .then((data) => { - console.info('[FormComponent] changeCardVisible result:' + data + ', isVisible:' + isVisible); - }); - } - } - - public async isFmsReady() { - formManager.isSystemReady() - .then((data) => { - console.info('[FormComponent] isFmsReady result:' + data); - }); - } - - public async getAllFormsInfo() { - formManager.getAllFormsInfo() - .then((data) => { - console.info('[FormComponent] getAllFormsInfo result:' + JSON.stringify(data)); - }); - } - - public async getFormsInfoByApp(bundle: string) { - formManager.getFormsInfo(bundle) - .then((data) => { - console.info('[FormComponent] getFormsInfoByApp result:' + JSON.stringify(data)); - }); - } - - public async getFormsInfoByModule(bundle: string, moduleName: string) { - formManager.getFormsInfo(bundle, moduleName) - .then((data) => { - console.info('[FormComponent] getFormsInfoByModule result:' + JSON.stringify(data)); - }); - } - - public async clearFormUserCache() { - abilityManager.clearUpApplicationData('com.ohos.myapplicationform') - .then((data) => { - console.info('[FormComponent] cleanBundleCacheFiles result:' + JSON.stringify(data)); - }); - } - - public async clearFormProviderCache(bundle: string) { - abilityManager.clearUpApplicationData(bundle) - .then((data) => { - console.info('[FormComponent] cleanBundleCacheFiles result:' + JSON.stringify(data)); - }); - } -} \ No newline at end of file diff --git a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostj/entry/src/main/ets/MainAbility/pages/index.ets b/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostj/entry/src/main/ets/MainAbility/pages/index.ets index 3148e1e9d7e1e0672ce2ff9a34fdf1c02c423b72..bd7874c1aca816921c9bd2681d4fd1d0ee60ce49 100644 --- a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostj/entry/src/main/ets/MainAbility/pages/index.ets +++ b/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostj/entry/src/main/ets/MainAbility/pages/index.ets @@ -13,11 +13,10 @@ * limitations under the License. */ -import FormViewModel from './FormViewModel.ets'; -import router from '@system.router'; -import featureAbility from "@ohos.ability.featureAbility"; -import formManager from '@ohos.application.formHost' import commonEvent from '@ohos.commonEvent'; +import featureAbility from "@ohos.ability.featureAbility"; +import formManager from '@ohos.application.formHost'; + @Entry @Component struct Index { @@ -25,11 +24,8 @@ struct Index { @State bundle: string = "com.form.formsystemtestservicea.hmservice"; @State ability: string = "com.form.formsystemtestservicea.hmservice.MainAbility"; @State moduleName: string = "entry"; - @State name: string = "Form_Js001"; - @State width: number = 300; - @State height: number = 200; + @State name: string = "Form_Js001"; @State allowUpate: boolean = true; - @State onAcquireResult: string = ""; @State isShowing: boolean = true; @State canCreateForm: boolean = false; private dimension: FormDimension = FormDimension.Dimension_1_2; @@ -38,12 +34,7 @@ struct Index { private deleteId = "-1"; private temporaryId="-1"; private temporary = false; - private mFormViewModel: FormViewModel; - private isVisible = false; - private mMargin = 15; - private BTN_BG_COLOR: string = '#0D9FFB'; private castForm = false; - private tempFormId: number = 0; private formOnAcquiredEvent = "FMS_FormOnAcquired_commonEvent"; private formCastEvent = "FMS_FormCast_commonEvent"; @@ -79,16 +70,7 @@ struct Index { console.info("!!!====>formsystemhostj deleteCallBack end ====>"); } - private unSubscribeDeleteCallback() { - console.debug("====>formsystemhostj unSubscribeDeleteCallback_1100 CallBack====>"); - } - private aboutToAppear() { - - const TAG = "[FormComponent.host]" - - this.mFormViewModel = FormViewModel.getInstance(); - commonEvent.createSubscriber(this.subscriberFormDeleteEvent).then(async (data) => { console.info("====>formsystemhostj Subscriber FormDelete data:====>", JSON.stringify(data)); this.subscriberDel = data; @@ -283,9 +265,6 @@ struct Index { .onError((error) => { console.log("[FormComponent.host] error code:" + error.errcode); console.log("[FormComponent.host] error msg:" + error.msg); - this.onAcquireResult += error.errcode; - this.onAcquireResult += " "; - this.onAcquireResult += error.msg; if(this.deleteForm && this.deleteId) { let commonEventPublishData = { data: error.msg, diff --git a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostk/entry/src/main/ets/MainAbility/pages/FormViewModel.ets b/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostk/entry/src/main/ets/MainAbility/pages/FormViewModel.ets deleted file mode 100644 index 9b09225070d8baf4062cf466a595a441993ae53b..0000000000000000000000000000000000000000 --- a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostk/entry/src/main/ets/MainAbility/pages/FormViewModel.ets +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import formManager from '@ohos.ability.formmanager'; -import bundleManager from '@ohos.bundle'; -import abilityManager from '@ohos.app.abilityManager'; - -export default class FormViewModel { - private static sFormViewModel: FormViewModel = null; - - public static getInstance(): FormViewModel { - if (FormViewModel.sFormViewModel == null) { - FormViewModel.sFormViewModel = new FormViewModel(); - } - return FormViewModel.sFormViewModel; - } - - public async castTempFormToNormal(formId: string) { - formManager.castTempForm(formId) - .then((data) => { - console.info('[FormComponent] castTempForm result:' + data); - }); - } - - public async requestForm(formId: string) { - formManager.requestForm(formId) - .then((data) => { - console.info('[FormComponent] requestForm result:' + data); - }); - } - - public async deleteCard(formId: string) { - formManager.deleteForm(formId) - .then((data) => { - console.info('[FormComponent] deleteForm result:' + data); - }); - } - - public async releaseCard(formId: string) { - formManager.releaseForm(formId) - .then((data) => { - console.info('[FormComponent] releaseForm result:' + data); - }); - } - - public async enableCard(formId: string) { - formManager.enableFormsUpdate([formId]) - .then((data) => { - console.info('[FormComponent] enableFormsUpdate result:' + data); - }); - } - - public async disableCard(formId: string) { - formManager.disableFormsUpdate([formId]) - .then((data) => { - console.info('[FormComponent] disableCard result:' + data); - }); - } - - public async changeCardVisible(formId: string, isVisible: boolean) { - if (isVisible) { - formManager.notifyVisibleForms([formId]) - .then((data) => { - console.info('[FormComponent] changeCardVisible result:' + data + ', isVisible:' + isVisible); - }); - } else { - formManager.notifyInvisibleForms([formId]) - .then((data) => { - console.info('[FormComponent] changeCardVisible result:' + data + ', isVisible:' + isVisible); - }); - } - } - - public async isFmsReady() { - formManager.isSystemReady() - .then((data) => { - console.info('[FormComponent] isFmsReady result:' + data); - }); - } - - public async getAllFormsInfo() { - formManager.getAllFormsInfo() - .then((data) => { - console.info('[FormComponent] getAllFormsInfo result:' + JSON.stringify(data)); - }); - } - - public async getFormsInfoByApp(bundle: string) { - formManager.getFormsInfo(bundle) - .then((data) => { - console.info('[FormComponent] getFormsInfoByApp result:' + JSON.stringify(data)); - }); - } - - public async getFormsInfoByModule(bundle: string, moduleName: string) { - formManager.getFormsInfo(bundle, moduleName) - .then((data) => { - console.info('[FormComponent] getFormsInfoByModule result:' + JSON.stringify(data)); - }); - } - - public async clearFormUserCache() { - abilityManager.clearUpApplicationData('com.ohos.myapplicationform') - .then((data) => { - console.info('[FormComponent] cleanBundleCacheFiles result:' + JSON.stringify(data)); - }); - } - - public async clearFormProviderCache(bundle: string) { - abilityManager.clearUpApplicationData(bundle) - .then((data) => { - console.info('[FormComponent] cleanBundleCacheFiles result:' + JSON.stringify(data)); - }); - } -} \ No newline at end of file diff --git a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostl/entry/src/main/ets/MainAbility/pages/FormViewModel.ets b/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostl/entry/src/main/ets/MainAbility/pages/FormViewModel.ets deleted file mode 100644 index cb25732d908c6cc580d69de1ae9984cde6230774..0000000000000000000000000000000000000000 --- a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostl/entry/src/main/ets/MainAbility/pages/FormViewModel.ets +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import formManager from '@ohos.ability.formmanager'; -import bundleManager from '@ohos.bundle'; -import abilityManager from '@ohos.app.abilityManager'; - -export default class FormViewModel { - private static sFormViewModel: FormViewModel = null; - - public static getInstance(): FormViewModel { - if (FormViewModel.sFormViewModel == null) { - FormViewModel.sFormViewModel = new FormViewModel(); - } - return FormViewModel.sFormViewModel; - } - - public async castTempFormToNormal(formId: string) { - formManager.castTempForm(formId) - .then((data) => { - console.info('[FormComponent] castTempForm result:' + data); - }); - } - - public async requestForm(formId: string) { - formManager.requestForm(formId) - .then((data) => { - console.info('[FormComponent] requestForm result:' + data); - }); - } - - public async deleteCard(formId: string) { - formManager.deleteForm(formId) - .then((data) => { - console.info('[FormComponent] deleteForm result:' + data); - }); - } - - public async releaseCard(formId: string) { - formManager.releaseForm(formId) - .then((data) => { - console.info('[FormComponent] releaseForm result:' + data); - }); - } - - public async enableCard(formId: string) { - formManager.enableFormsUpdate([formId]) - .then((data) => { - console.info('[FormComponent] enableFormsUpdate result:' + data); - }); - } - - public async disableCard(formId: string) { - formManager.disableFormsUpdate([formId]) - .then((data) => { - console.info('[FormComponent] disableCard result:' + data); - }); - } - - public async changeCardVisible(formId: string, isVisible: boolean) { - if (isVisible) { - formManager.notifyVisibleForms([formId]) - .then((data) => { - console.info('[FormComponent] changeCardVisible result:' + data + ', isVisible:' + isVisible); - }); - } else { - formManager.notifyInvisibleForms([formId]) - .then((data) => { - console.info('[FormComponent] changeCardVisible result:' + data + ', isVisible:' + isVisible); - }); - } - } - - public async isFmsReady() { - formManager.isSystemReady() - .then((data) => { - console.info('[FormComponent] isFmsReady result:' + data); - }); - } - - public async getAllFormsInfo() { - formManager.getAllFormsInfo() - .then((data) => { - console.info('[FormComponent] getAllFormsInfo result:' + JSON.stringify(data)); - }); - } - - public async getFormsInfoByApp(bundle: string) { - formManager.getFormsInfo(bundle) - .then((data) => { - console.info('[FormComponent] getFormsInfoByApp result:' + JSON.stringify(data)); - }); - } - - public async getFormsInfoByModule(bundle: string, moduleName: string) { - formManager.getFormsInfo(bundle, moduleName) - .then((data) => { - console.info('[FormComponent] getFormsInfoByModule result:' + JSON.stringify(data)); - }); - } - - public async clearFormUserCache() { - abilityManager.clearUpApplicationData('com.ohos.myapplicationform') - .then((data) => { - console.info('[FormComponent] cleanBundleCacheFiles result:' + JSON.stringify(data)); - }); - } - - public async clearFormProviderCache(bundle: string) { - abilityManager.clearUpApplicationData(bundle) - .then((data) => { - console.info('[FormComponent] cleanBundleCacheFiles result:' + JSON.stringify(data)); - }); - } -} \ No newline at end of file diff --git a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostl/entry/src/main/ets/MainAbility/pages/index.ets b/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostl/entry/src/main/ets/MainAbility/pages/index.ets index 096a1854cf1bfebaae4abf31309a2df52fd73169..707008c2b7d41740cab53cd179e49b25b372a844 100644 --- a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostl/entry/src/main/ets/MainAbility/pages/index.ets +++ b/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostl/entry/src/main/ets/MainAbility/pages/index.ets @@ -13,7 +13,6 @@ * limitations under the License. */ -import FormViewModel from './FormViewModel.ets'; import commonEvent from '@ohos.commonEvent'; import featureAbility from '@ohos.ability.featureAbility'; import formManager from '@ohos.application.formHost'; @@ -32,7 +31,6 @@ struct Index { @State isShowing: boolean = true; @State dimension: FormDimension = FormDimension.Dimension_1_2; @State temporary: boolean = false; - private mFormViewModel: FormViewModel; private requestForm = false; private requestId = `-1`; private subscriberDel; @@ -57,8 +55,6 @@ struct Index { } async private aboutToAppear() { - this.mFormViewModel = FormViewModel.getInstance(); - const onDeleteEventSubscriber = await commonEvent.createSubscriber(this.subscriberFormDeleteEvent); commonEvent.subscribe(onDeleteEventSubscriber, async (err, data) => { console.info(`${this.TAG} deleteCallBack start:====> ${JSON.stringify(data)}`); diff --git a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostn/entry/src/main/ets/MainAbility/pages/index.ets b/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostn/entry/src/main/ets/MainAbility/pages/index.ets index de99d63ccfe0fde5b84a9a4584be1b89f602e4ed..e4e8562fc92d4bacb97b41c514aefe3cc255846e 100644 --- a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostn/entry/src/main/ets/MainAbility/pages/index.ets +++ b/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostn/entry/src/main/ets/MainAbility/pages/index.ets @@ -1,462 +1,455 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import featureAbility from "@ohos.ability.featureAbility"; -import formManager from '@ohos.application.formHost'; -import commonEvent from '@ohos.commonEvent'; -@Entry -@Component -struct Index { - @State bundle: string = "com.form.formsystemtestservicea.hmservice"; - @State ability: string = "com.form.formsystemtestservicea.hmservice.MainAbility"; - @State moduleName: string = "entry"; - @State name: string = "Form_Js001"; - @State width: number = 300; - @State height: number = 200; - @State allowUpate: boolean = true; - @State onAcquireResult: string = ""; - @State isShowing: boolean = true; - @State optType: number = 0; - private dimension: FormDimension = FormDimension.Dimension_1_2; - private isTemporary = false; - private isVisible = false; - private mMargin = 15; - private BTN_BG_COLOR: string = '#0D9FFB'; - - private normal = 0; - private temporary = 0; - private normaldel = 0; - private temporarydel = 0; - private normalFormIds = []; - private tempFormIds = []; - - private deleteIds = []; - private delCount = 0; - - private normalFormCounts = []; - private tempFormCounts = []; - - private castFormId = "-1"; - - private formOnAcquiredEvent = "FMS_FormOnAcquired_commonEvent"; - private formOnErrorEvent = "FMS_FormOnError_commonEvent"; - private formCastEvent = "FMS_FormCast_commonEvent"; - - private subscriberDel; - private subscriberFormDeleteEvent = { - events: ["FMS_FormDelete_commonEvent"], - }; - - private subscriberSendCastForm; - private subscriberSendCastFormEvent = { - events: ["FMS_SendCastForm_commonEvent"], - }; - - private publishOnErrorCallBack() { - console.debug("====> [FormComponent] formsystemhostn formOnErrorEvent Publish CallBack ====>"); - } - private publishOnAcquiredCallBack() { - console.debug("====> [FormComponent] formsystemhostn formOnAcquiredEvent Publish CallBack ====>"); - } - private publishDeleteCallBack() { - console.debug("====> [FormComponent] formsystemhostn publishDeleteCallBack Publish CallBack ====>"); - } - private publishCastCallBack() { - console.debug("====>formCastEvent Publish CallBack ====>"); - } - private startAbility(bundleName, abilityName, sendMsg) { - featureAbility.startAbility({ - want: { - bundleName: bundleName, - abilityName: abilityName, - parameters: { - "formId": "0", - "name": "Form_Js001", - "bundle": "com.form.formsystemtestservicea.hmservice", - "ability": "com.form.formsystemtestservicea.hmservice.MainAbility", - "moduleName": "entry", - "temporary": false, - "sendCastForm": true, - "sendCastFormMsg": sendMsg, - "isCreate": false - } - } - }).then((res: any) => { - console.info(`[FormComponent] formsystemhostn featureAbility.startAbility res: ${JSON.stringify(res)}`); - }).catch((err: any) => { - console.info(`[FormComponent] formsystemhostn featureAbility.startAbility error: ${JSON.stringify(err)}`); - }); - } - private publishOnSendCastForm(err, data) { - console.info("!!!====>[FormComponent] formsystemhostn OnSendCastForm start:====>" + JSON.stringify(data)); - if (data.bundleName && data.bundleName != "com.ohos.st.formsystemhostn") { - return; - } - let formId = data.parameters.castFormId; - setTimeout(function () { - console.info("[FormComponent.host] castTempForm start, formId: " + formId); - formManager.castTempForm(formId) - .then((data) => { - console.info('[FormComponent] castTempForm result:' + data); - this.startAbility("com.ohos.st.formsystemhostc", "com.ohos.st.formsystemhostc.MainAbility", data.toString()); - }) - .catch((error) => { - console.info('[FormComponent] castTempForm error:' + JSON.stringify(error)); - this.startAbility("com.ohos.st.formsystemhostc", "com.ohos.st.formsystemhostc.MainAbility", error.code.toString()); - }); - console.info("[FormComponent.host] castTempForm end"); - }, 5000); - console.info("!!!====>[FormComponent] formsystemhostn OnSendCastForm end"); - } - - private deleteCallBack(err, data) { - console.info("!!!====>[FormComponent] formsystemhostn deleteCallBack start:====>" + JSON.stringify(data)); - const delFormIds = data.parameters.formIds; - console.info(`[FormComponent] data size ${delFormIds.length}`); - - console.info(`[FormComponent] data.subscriber ${JSON.stringify(this.subscriberDel)}`); - commonEvent.unsubscribe(this.subscriberDel, () => { - console.info("====> [FormComponent] formsystemhostn optType unSubscribeDeleteCallback CallBack====>"); - }); - commonEvent.unsubscribe(this.subscriberSendCastForm, () => { - console.info("====> [FormComponent] formsystemhostn optType unSubscribeCastFormCallback CallBack====>"); - }); - console.info(`[FormComponent] data.bundleName ${JSON.stringify(data.bundleName)}`); - console.info(`[FormComponent] tof ${"com.ohos.st.formsystemhostn" != data.bundleName}`); - if ("com.ohos.st.formsystemhostn" != data.bundleName) { - return; - } - delFormIds.forEach(async (formId, index) => { - console.info(`[FormComponent] formsystemhostn deleteForm ${index}`); - try { - const res = await formManager.deleteForm(formId); - console.info(`[FormComponent] formsystemhostn deleteForm ${index} ${formId} result: ${JSON.stringify(res)}`); - } catch (error) { - console.info(`[FormComponent] formsystemhostn deleteForm ${index} ${formId} error: ${JSON.stringify(error)}`); - } - }); - console.info("!!!====> [FormComponent] formsystemhostn optType deleteCallBack end ====>"); - } - - private unSubscribeDeleteCallback() { - console.debug("====> [FormComponent] formsystemhostn optType unSubscribeDeleteCallback CallBack====>"); - } - - private unSubscribeCastFormCallback() { - console.debug("====> [FormComponent] formsystemhostn optType unSubscribeCastFormCallback CallBack====>"); - } - - private aboutToAppear() { - const TAG = "[FormComponent.hostn]"; - - commonEvent.createSubscriber(this.subscriberFormDeleteEvent).then(async (data) => { - console.info("====>[FormComponent] formsystemhostn Subscriber FormDelete data:====>", JSON.stringify(data)); - this.subscriberDel = data; - commonEvent.subscribe(this.subscriberDel, (err, data) => { - if ("com.ohos.st.formsystemhostn" != data.bundleName) { - return; - } else { - console.info("!!!====>[FormComponent.hostn] formsystemhostn deleteCallBack start:====>" + JSON.stringify(data)); - const delFormIds = data.parameters.formIds; - console.info(`[FormComponent] data size ${delFormIds.length}`); - commonEvent.unsubscribe(this.subscriberDel, () => { - console.info("====> [FormComponent] formsystemhostn optType unSubscribeDeleteCallback CallBack====>"); - }); - commonEvent.unsubscribe(this.subscriberSendCastForm, () => { - console.info("====> [FormComponent] formsystemhostn optType unSubscribeCastFormCallback CallBack====>"); - }); - let delCounter = 0; - delFormIds.forEach((formId) => { - formManager.deleteForm(formId, (error, data) => { - console.info(`[FormComponent] formsystemhostn deleteForm ${++delCounter} ${formId} data: ${JSON.stringify(data)} err: ${JSON.stringify(error)}`); - }); - }); - } - }); - }); - - commonEvent.createSubscriber(this.subscriberSendCastFormEvent).then(async (data) => { - console.info("====>[FormComponent] formsystemhostn Subscriber SendCastForm data:====>", JSON.stringify(data)); - this.subscriberSendCastForm = data; - await commonEvent.subscribe(this.subscriberSendCastForm, this.publishOnSendCastForm); - }); - - featureAbility.getWant() - .then(async (want: any) => { - console.info(" [FormComponent] formsystemhostn getWant:" + JSON.stringify(want)); - - this.name = want.parameters.name; - this.bundle = want.parameters.bundle; - this.ability = want.parameters.ability; - if (want.parameters.moduleName) { - this.moduleName = want.parameters.moduleName; - } - - if (want.parameters.dimension) { - this.dimension = want.parameters.dimension; - } - - if (want.parameters.normal) { - this.normal = want.parameters.normal; - } - - if (want.parameters.temporary) { - this.temporary = want.parameters.temporary; - } - if (want.parameters.normaldel) { - this.normaldel = want.parameters.normaldel; - } - - if (want.parameters.temporarydel) { - this.temporarydel = want.parameters.temporarydel; - } - - if (want.parameters.deleteIds) { - this.deleteIds = want.parameters.deleteIds; - } - if (want.parameters.castFormId) { - this.castFormId = want.parameters.castFormId; - } - - if (want.parameters.releaseFormId) { - commonEvent.unsubscribe(this.subscriberDel, () => { - console.info("====> [FormComponent] formsystemhostn optType unSubscribeDeleteCallback CallBack====>"); - }); - commonEvent.unsubscribe(this.subscriberSendCastForm, () => { - console.info("====> [FormComponent] formsystemhostn optType unSubscribeCastFormCallback CallBack====>"); - }); - - const formId = want.parameters.releaseFormId; - const isReleaseCache = want.parameters.isReleaseCache; - const res = await formManager.releaseForm(formId, isReleaseCache); - console.info(`[FormComponent] releaseForm res: ${JSON.stringify(res)}`); - const commonEventPublishData = { - data: `releaseForm`, - bundleName: `com.ohos.st.formsystemhostn`, - parameters: { - formIds: [].concat(formId) - } - }; - commonEvent.publish(this.formOnAcquiredEvent, commonEventPublishData, this.publishOnAcquiredCallBack); - - this.normal = 1; - } - - this.makeCount(); - - setTimeout(() => { - this.optType = want.parameters.optType; - console.info(' [FormComponent] formsystemhostn getWant optType:' + this.optType); - }, 10); - - if (this.castFormId != "-1" && want.parameters.optType == 3) { - console.info("[FormComponent.host] castTempForm start"); - commonEvent.unsubscribe(this.subscriberDel, () => { - console.info("====> [FormComponent] formsystemhostn optType unSubscribeDeleteCallback CallBack====>"); - }); - commonEvent.unsubscribe(this.subscriberSendCastForm, () => { - console.info("====> [FormComponent] formsystemhostn optType unSubscribeCastFormCallback CallBack====>"); - }); - - formManager.castTempForm(this.castFormId) - .then((data) => { - console.info('[FormComponent] castTempForm result:' + data); - let commonEventPublishData = { - data: data || `0`, - bundleName: "com.ohos.st.formsystemhostn", - parameters: { - formId: this.castFormId.toString() - } - }; - commonEvent.publish(this.formCastEvent, commonEventPublishData, this.publishCastCallBack); - }) - .catch((error) => { - console.info('[FormComponent] castTempForm error:' + error.code); - let commonEventPublishData = { - data: error.code.toString(), - errMsg: error.msg, - bundleName: "com.ohos.st.formsystemhostn", - parameters: { - formId: this.castFormId.toString() - } - }; - commonEvent.publish(this.formCastEvent, commonEventPublishData, this.publishCastCallBack); - }); - console.info("[FormComponent.host] castTempForm end"); - } - - if (want.parameters.optType == 2 && this.deleteIds.length > 0) { - for (let iIndex = 0; iIndex < this.deleteIds.length; ++iIndex) { - console.info("[FormComponent] formsystemhostn deleteForm start"); - formManager.deleteForm(this.deleteIds[iIndex]) - .then((data) => { - console.info('[FormComponent] formsystemhostn deleteForm result:' + data); - this.delCount++; - - if (this.delCount == this.deleteIds.length) { - let commonEventPublishData = { - data: data.toString(), - bundleName: "com.ohos.st.formsystemhostn", - parameters: { - "formIds": this.deleteIds - } - }; - commonEvent.publish(this.formOnErrorEvent, commonEventPublishData, this.publishDeleteCallBack); - } - }) - .catch((error) => { - console.info(' [FormComponent] formsystemhostn deleteForm error:' + error); - let commonEventPublishData = { - data: error.code.toString(), - bundleName: "com.ohos.st.formsystemhostn", - parameters: { - "formIds": [this.deleteIds[iIndex]] - } - }; - commonEvent.publish(this.formOnErrorEvent, commonEventPublishData, this.publishOnErrorCallBack); - }); - console.info("[FormComponent] formsystemhostn deleteForm end"); - } - } - }) - .catch((error: any) => { - console.error(' [FormComponent] formsystemhostn Operation failed. Cause: ' + JSON.stringify(error)); - }) - console.info(`[FormComponent.host] aboutToAppear end`); - } - - private makeCount() { - console.info(' [FormComponent] formsystemhostn makeCount start.'); - for (let nNormal = 0; nNormal < this.normal; nNormal++) { - this.normalFormCounts.push(nNormal); - } - console.info(' [FormComponent] formsystemhostn this.normalFormCounts.length:' + this.normalFormCounts.length); - - for (let nTemp = 0; nTemp < this.temporary; nTemp++) { - this.tempFormCounts.push(nTemp); - } - console.info(' [FormComponent] formsystemhostn this.tempFormCounts.length:' + this.tempFormCounts.length); - } - - build() { - Scroll(new Scroller()) { - Column() { - if (this.optType == 1) { - Text(' [FormComponent] formsystemhostn normal form component test begin') - Grid() { - ForEach(this.normalFormCounts, (item) => { - GridItem() { - FormComponent({ - id: 0, - name: this.name, - bundle: this.bundle, - ability: this.ability, - module: this.moduleName, - dimension: this.dimension, - temporary: false - }) - .allowUpdate(this.allowUpate) - .visibility(this.isShowing ? Visibility.Visible : Visibility.Hidden) - .onAcquired((form) => { - console.info(" [FormComponent] formsystemhostn get normal form, form id:" + form.id); - - this.normalFormIds.push(form.id.toString()); - if (this.normalFormIds.length == this.normal - this.normaldel) { - let commonEventPublishData = { - data: "normalForm", - bundleName: "com.ohos.st.formsystemhostn", - parameters: { - "formIds": this.normalFormIds - } - }; - commonEvent.publish(this.formOnAcquiredEvent, commonEventPublishData, this.publishOnAcquiredCallBack); - } - }) - .onError((error) => { - console.info(" [FormComponent] formsystemhostn normal form error code:" + error.errcode); - console.info(" [FormComponent] formsystemhostn normal form error msg:" + error.msg); - let commonEventPublishData = { - data: error.msg, - bundleName: "com.ohos.st.formsystemhostn" - }; - commonEvent.publish(this.formOnErrorEvent, commonEventPublishData, this.publishOnErrorCallBack); - }) - .size({ width: 40, height: 40 }) - } - }, (item) => JSON.stringify(item)) - } - .columnsTemplate('1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr ') - .columnsGap(2) - .rowsGap(2) - .width('100%') - Text(' [FormComponent] formsystemhostn normal form component test end') - - Text(' [FormComponent] formsystemhostn temp form component test start') - Grid() { - ForEach(this.tempFormCounts, (item) => { - GridItem() { - FormComponent({ - id: 0, - name: this.name, - bundle: this.bundle, - ability: this.ability, - module: this.moduleName, - dimension: this.dimension, - temporary: true - }) - .allowUpdate(this.allowUpate) - .visibility(this.isShowing ? Visibility.Visible : Visibility.Hidden) - .onAcquired((form) => { - console.info(" [FormComponent] formsystemhostn get temp form, form id:" + form.id); - this.tempFormIds.push(form.id.toString()); - if (this.tempFormIds.length == this.temporary - this.temporarydel) { - let commonEventPublishData = { - data: "tempForm", - bundleName: "com.ohos.st.formsystemhostn", - parameters: { - "formIds": this.tempFormIds - } - }; - commonEvent.publish(this.formOnAcquiredEvent, commonEventPublishData, this.publishOnAcquiredCallBack); - } - }) - .onError((error) => { - console.info(" [FormComponent] formsystemhostn temp form error code:" + error.errcode); - console.info(" [FormComponent] formsystemhostn temp form error msg:" + error.msg); - let commonEventPublishData = { - data: error.msg, - bundleName: "com.ohos.st.formsystemhostn" - }; - commonEvent.publish(this.formOnErrorEvent, commonEventPublishData, this.publishOnErrorCallBack); - }) - .size({ width: 40, height: 40 }) - } - }, (item) => JSON.stringify(item)) - } - .columnsTemplate('1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr ') - .columnsGap(2) - .rowsGap(2) - .width('100%') - - Text(' [FormComponent] formsystemhostn temp form component test end') - } - } - .backgroundColor(Color.White) - } - .scrollable(ScrollDirection.Vertical) - .width('100%') - .height('100%') - } +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import commonEvent from '@ohos.commonEvent'; +import featureAbility from "@ohos.ability.featureAbility"; +import formManager from '@ohos.application.formHost'; + +@Entry +@Component +struct Index { + @State bundle: string = "com.form.formsystemtestservicea.hmservice"; + @State ability: string = "com.form.formsystemtestservicea.hmservice.MainAbility"; + @State moduleName: string = "entry"; + @State name: string = "Form_Js001"; + @State allowUpate: boolean = true; + @State isShowing: boolean = true; + @State optType: number = 0; + private dimension: FormDimension = FormDimension.Dimension_1_2; + + private normal = 0; + private temporary = 0; + private normaldel = 0; + private temporarydel = 0; + private normalFormIds = []; + private tempFormIds = []; + + private deleteIds = []; + private delCount = 0; + + private normalFormCounts = []; + private tempFormCounts = []; + + private castFormId = "-1"; + + private formOnAcquiredEvent = "FMS_FormOnAcquired_commonEvent"; + private formOnErrorEvent = "FMS_FormOnError_commonEvent"; + private formCastEvent = "FMS_FormCast_commonEvent"; + + private subscriberDel; + private subscriberFormDeleteEvent = { + events: ["FMS_FormDelete_commonEvent"], + }; + + private subscriberSendCastForm; + private subscriberSendCastFormEvent = { + events: ["FMS_SendCastForm_commonEvent"], + }; + + private publishOnErrorCallBack() { + console.debug("====> [FormComponent] formsystemhostn formOnErrorEvent Publish CallBack ====>"); + } + private publishOnAcquiredCallBack() { + console.debug("====> [FormComponent] formsystemhostn formOnAcquiredEvent Publish CallBack ====>"); + } + private publishDeleteCallBack() { + console.debug("====> [FormComponent] formsystemhostn publishDeleteCallBack Publish CallBack ====>"); + } + private publishCastCallBack() { + console.debug("====>formCastEvent Publish CallBack ====>"); + } + private startAbility(bundleName, abilityName, sendMsg) { + featureAbility.startAbility({ + want: { + bundleName: bundleName, + abilityName: abilityName, + parameters: { + "formId": "0", + "name": "Form_Js001", + "bundle": "com.form.formsystemtestservicea.hmservice", + "ability": "com.form.formsystemtestservicea.hmservice.MainAbility", + "moduleName": "entry", + "temporary": false, + "sendCastForm": true, + "sendCastFormMsg": sendMsg, + "isCreate": false + } + } + }).then((res: any) => { + console.info(`[FormComponent] formsystemhostn featureAbility.startAbility res: ${JSON.stringify(res)}`); + }).catch((err: any) => { + console.info(`[FormComponent] formsystemhostn featureAbility.startAbility error: ${JSON.stringify(err)}`); + }); + } + + private publishOnSendCastForm(err, data) { + console.info("!!!====>[FormComponent] formsystemhostn OnSendCastForm start:====>" + JSON.stringify(data)); + if (data.bundleName && data.bundleName != "com.ohos.st.formsystemhostn") { + return; + } + let formId = data.parameters.castFormId; + setTimeout(function () { + console.info("[FormComponent.host] castTempForm start, formId: " + formId); + formManager.castTempForm(formId) + .then((data) => { + console.info('[FormComponent] castTempForm result:' + data); + this.startAbility("com.ohos.st.formsystemhostc", "com.ohos.st.formsystemhostc.MainAbility", data.toString()); + }) + .catch((error) => { + console.info('[FormComponent] castTempForm error:' + JSON.stringify(error)); + this.startAbility("com.ohos.st.formsystemhostc", "com.ohos.st.formsystemhostc.MainAbility", error.code.toString()); + }); + console.info("[FormComponent.host] castTempForm end"); + }, 5000); + console.info("!!!====>[FormComponent] formsystemhostn OnSendCastForm end"); + } + + private deleteCallBack(err, data) { + console.info("!!!====>[FormComponent] formsystemhostn deleteCallBack start:====>" + JSON.stringify(data)); + const delFormIds = data.parameters.formIds; + console.info(`[FormComponent] data size ${delFormIds.length}`); + + console.info(`[FormComponent] data.subscriber ${JSON.stringify(this.subscriberDel)}`); + commonEvent.unsubscribe(this.subscriberDel, () => { + console.info("====> [FormComponent] formsystemhostn optType unSubscribeDeleteCallback CallBack====>"); + }); + commonEvent.unsubscribe(this.subscriberSendCastForm, () => { + console.info("====> [FormComponent] formsystemhostn optType unSubscribeCastFormCallback CallBack====>"); + }); + console.info(`[FormComponent] data.bundleName ${JSON.stringify(data.bundleName)}`); + console.info(`[FormComponent] tof ${"com.ohos.st.formsystemhostn" != data.bundleName}`); + if ("com.ohos.st.formsystemhostn" != data.bundleName) { + return; + } + delFormIds.forEach(async (formId, index) => { + console.info(`[FormComponent] formsystemhostn deleteForm ${index}`); + try { + const res = await formManager.deleteForm(formId); + console.info(`[FormComponent] formsystemhostn deleteForm ${index} ${formId} result: ${JSON.stringify(res)}`); + } catch (error) { + console.info(`[FormComponent] formsystemhostn deleteForm ${index} ${formId} error: ${JSON.stringify(error)}`); + } + }); + console.info("!!!====> [FormComponent] formsystemhostn optType deleteCallBack end ====>"); + } + + private unSubscribeDeleteCallback() { + console.debug("====> [FormComponent] formsystemhostn optType unSubscribeDeleteCallback CallBack====>"); + } + + private unSubscribeCastFormCallback() { + console.debug("====> [FormComponent] formsystemhostn optType unSubscribeCastFormCallback CallBack====>"); + } + + private aboutToAppear() { + commonEvent.createSubscriber(this.subscriberFormDeleteEvent).then(async (data) => { + console.info("====>[FormComponent] formsystemhostn Subscriber FormDelete data:====>", JSON.stringify(data)); + this.subscriberDel = data; + commonEvent.subscribe(this.subscriberDel, (err, data) => { + if ("com.ohos.st.formsystemhostn" != data.bundleName) { + return; + } else { + console.info("!!!====>[FormComponent.hostn] formsystemhostn deleteCallBack start:====>" + JSON.stringify(data)); + const delFormIds = data.parameters.formIds; + console.info(`[FormComponent] data size ${delFormIds.length}`); + commonEvent.unsubscribe(this.subscriberDel, () => { + console.info("====> [FormComponent] formsystemhostn optType unSubscribeDeleteCallback CallBack====>"); + }); + commonEvent.unsubscribe(this.subscriberSendCastForm, () => { + console.info("====> [FormComponent] formsystemhostn optType unSubscribeCastFormCallback CallBack====>"); + }); + let delCounter = 0; + delFormIds.forEach((formId) => { + formManager.deleteForm(formId, (error, data) => { + console.info(`[FormComponent] formsystemhostn deleteForm ${++delCounter} ${formId} data: ${JSON.stringify(data)} err: ${JSON.stringify(error)}`); + }); + }); + } + }); + }); + + commonEvent.createSubscriber(this.subscriberSendCastFormEvent).then(async (data) => { + console.info("====>[FormComponent] formsystemhostn Subscriber SendCastForm data:====>", JSON.stringify(data)); + this.subscriberSendCastForm = data; + await commonEvent.subscribe(this.subscriberSendCastForm, this.publishOnSendCastForm); + }); + + featureAbility.getWant() + .then(async (want: any) => { + console.info(" [FormComponent] formsystemhostn getWant:" + JSON.stringify(want)); + + this.name = want.parameters.name; + this.bundle = want.parameters.bundle; + this.ability = want.parameters.ability; + if (want.parameters.moduleName) { + this.moduleName = want.parameters.moduleName; + } + + if (want.parameters.dimension) { + this.dimension = want.parameters.dimension; + } + + if (want.parameters.normal) { + this.normal = want.parameters.normal; + } + + if (want.parameters.temporary) { + this.temporary = want.parameters.temporary; + } + if (want.parameters.normaldel) { + this.normaldel = want.parameters.normaldel; + } + + if (want.parameters.temporarydel) { + this.temporarydel = want.parameters.temporarydel; + } + + if (want.parameters.deleteIds) { + this.deleteIds = want.parameters.deleteIds; + } + if (want.parameters.castFormId) { + this.castFormId = want.parameters.castFormId; + } + + if (want.parameters.releaseFormId) { + commonEvent.unsubscribe(this.subscriberDel, () => { + console.info("====> [FormComponent] formsystemhostn optType unSubscribeDeleteCallback CallBack====>"); + }); + commonEvent.unsubscribe(this.subscriberSendCastForm, () => { + console.info("====> [FormComponent] formsystemhostn optType unSubscribeCastFormCallback CallBack====>"); + }); + + const formId = want.parameters.releaseFormId; + const isReleaseCache = want.parameters.isReleaseCache; + const res = await formManager.releaseForm(formId, isReleaseCache); + console.info(`[FormComponent] releaseForm res: ${JSON.stringify(res)}`); + const commonEventPublishData = { + data: `releaseForm`, + bundleName: `com.ohos.st.formsystemhostn`, + parameters: { + formIds: [].concat(formId) + } + }; + commonEvent.publish(this.formOnAcquiredEvent, commonEventPublishData, this.publishOnAcquiredCallBack); + + this.normal = 1; + } + + this.makeCount(); + + setTimeout(() => { + this.optType = want.parameters.optType; + console.info(' [FormComponent] formsystemhostn getWant optType:' + this.optType); + }, 10); + + if (this.castFormId != "-1" && want.parameters.optType == 3) { + console.info("[FormComponent.host] castTempForm start"); + commonEvent.unsubscribe(this.subscriberDel, () => { + console.info("====> [FormComponent] formsystemhostn optType unSubscribeDeleteCallback CallBack====>"); + }); + commonEvent.unsubscribe(this.subscriberSendCastForm, () => { + console.info("====> [FormComponent] formsystemhostn optType unSubscribeCastFormCallback CallBack====>"); + }); + + formManager.castTempForm(this.castFormId) + .then((data) => { + console.info('[FormComponent] castTempForm result:' + data); + let commonEventPublishData = { + data: data || `0`, + bundleName: "com.ohos.st.formsystemhostn", + parameters: { + formId: this.castFormId.toString() + } + }; + commonEvent.publish(this.formCastEvent, commonEventPublishData, this.publishCastCallBack); + }) + .catch((error) => { + console.info('[FormComponent] castTempForm error:' + error.code); + let commonEventPublishData = { + data: error.code.toString(), + errMsg: error.msg, + bundleName: "com.ohos.st.formsystemhostn", + parameters: { + formId: this.castFormId.toString() + } + }; + commonEvent.publish(this.formCastEvent, commonEventPublishData, this.publishCastCallBack); + }); + console.info("[FormComponent.host] castTempForm end"); + } + + if (want.parameters.optType == 2 && this.deleteIds.length > 0) { + for (let iIndex = 0; iIndex < this.deleteIds.length; ++iIndex) { + console.info("[FormComponent] formsystemhostn deleteForm start"); + formManager.deleteForm(this.deleteIds[iIndex]) + .then((data) => { + console.info('[FormComponent] formsystemhostn deleteForm result:' + data); + this.delCount++; + + if (this.delCount == this.deleteIds.length) { + let commonEventPublishData = { + data: data.toString(), + bundleName: "com.ohos.st.formsystemhostn", + parameters: { + "formIds": this.deleteIds + } + }; + commonEvent.publish(this.formOnErrorEvent, commonEventPublishData, this.publishDeleteCallBack); + } + }) + .catch((error) => { + console.info(' [FormComponent] formsystemhostn deleteForm error:' + error); + let commonEventPublishData = { + data: error.code.toString(), + bundleName: "com.ohos.st.formsystemhostn", + parameters: { + "formIds": [this.deleteIds[iIndex]] + } + }; + commonEvent.publish(this.formOnErrorEvent, commonEventPublishData, this.publishOnErrorCallBack); + }); + console.info("[FormComponent] formsystemhostn deleteForm end"); + } + } + }) + .catch((error: any) => { + console.error(' [FormComponent] formsystemhostn Operation failed. Cause: ' + JSON.stringify(error)); + }) + console.info(`[FormComponent.host] aboutToAppear end`); + } + + private makeCount() { + console.info(' [FormComponent] formsystemhostn makeCount start.'); + for (let nNormal = 0; nNormal < this.normal; nNormal++) { + this.normalFormCounts.push(nNormal); + } + console.info(' [FormComponent] formsystemhostn this.normalFormCounts.length:' + this.normalFormCounts.length); + + for (let nTemp = 0; nTemp < this.temporary; nTemp++) { + this.tempFormCounts.push(nTemp); + } + console.info(' [FormComponent] formsystemhostn this.tempFormCounts.length:' + this.tempFormCounts.length); + } + + build() { + Scroll(new Scroller()) { + Column() { + if (this.optType == 1) { + Text(' [FormComponent] formsystemhostn normal form component test begin') + Grid() { + ForEach(this.normalFormCounts, (item) => { + GridItem() { + FormComponent({ + id: 0, + name: this.name, + bundle: this.bundle, + ability: this.ability, + module: this.moduleName, + dimension: this.dimension, + temporary: false + }) + .allowUpdate(this.allowUpate) + .visibility(this.isShowing ? Visibility.Visible : Visibility.Hidden) + .onAcquired((form) => { + console.info(" [FormComponent] formsystemhostn get normal form, form id:" + form.id); + + this.normalFormIds.push(form.id.toString()); + if (this.normalFormIds.length == this.normal - this.normaldel) { + let commonEventPublishData = { + data: "normalForm", + bundleName: "com.ohos.st.formsystemhostn", + parameters: { + "formIds": this.normalFormIds + } + }; + commonEvent.publish(this.formOnAcquiredEvent, commonEventPublishData, this.publishOnAcquiredCallBack); + } + }) + .onError((error) => { + console.info(" [FormComponent] formsystemhostn normal form error code:" + error.errcode); + console.info(" [FormComponent] formsystemhostn normal form error msg:" + error.msg); + let commonEventPublishData = { + data: error.msg, + bundleName: "com.ohos.st.formsystemhostn" + }; + commonEvent.publish(this.formOnErrorEvent, commonEventPublishData, this.publishOnErrorCallBack); + }) + .size({ width: 40, height: 40 }) + } + }, (item) => JSON.stringify(item)) + } + .columnsTemplate('1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr ') + .columnsGap(2) + .rowsGap(2) + .width('100%') + Text(' [FormComponent] formsystemhostn normal form component test end') + + Text(' [FormComponent] formsystemhostn temp form component test start') + Grid() { + ForEach(this.tempFormCounts, (item) => { + GridItem() { + FormComponent({ + id: 0, + name: this.name, + bundle: this.bundle, + ability: this.ability, + module: this.moduleName, + dimension: this.dimension, + temporary: true + }) + .allowUpdate(this.allowUpate) + .visibility(this.isShowing ? Visibility.Visible : Visibility.Hidden) + .onAcquired((form) => { + console.info(" [FormComponent] formsystemhostn get temp form, form id:" + form.id); + this.tempFormIds.push(form.id.toString()); + if (this.tempFormIds.length == this.temporary - this.temporarydel) { + let commonEventPublishData = { + data: "tempForm", + bundleName: "com.ohos.st.formsystemhostn", + parameters: { + "formIds": this.tempFormIds + } + }; + commonEvent.publish(this.formOnAcquiredEvent, commonEventPublishData, this.publishOnAcquiredCallBack); + } + }) + .onError((error) => { + console.info(" [FormComponent] formsystemhostn temp form error code:" + error.errcode); + console.info(" [FormComponent] formsystemhostn temp form error msg:" + error.msg); + let commonEventPublishData = { + data: error.msg, + bundleName: "com.ohos.st.formsystemhostn" + }; + commonEvent.publish(this.formOnErrorEvent, commonEventPublishData, this.publishOnErrorCallBack); + }) + .size({ width: 40, height: 40 }) + } + }, (item) => JSON.stringify(item)) + } + .columnsTemplate('1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr ') + .columnsGap(2) + .rowsGap(2) + .width('100%') + + Text(' [FormComponent] formsystemhostn temp form component test end') + } + } + .backgroundColor(Color.White) + } + .scrollable(ScrollDirection.Vertical) + .width('100%') + .height('100%') + } } \ No newline at end of file diff --git a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostnoperm/entry/src/main/ets/MainAbility/pages/FormViewModel.ets b/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostnoperm/entry/src/main/ets/MainAbility/pages/FormViewModel.ets deleted file mode 100644 index 9b09225070d8baf4062cf466a595a441993ae53b..0000000000000000000000000000000000000000 --- a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostnoperm/entry/src/main/ets/MainAbility/pages/FormViewModel.ets +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import formManager from '@ohos.ability.formmanager'; -import bundleManager from '@ohos.bundle'; -import abilityManager from '@ohos.app.abilityManager'; - -export default class FormViewModel { - private static sFormViewModel: FormViewModel = null; - - public static getInstance(): FormViewModel { - if (FormViewModel.sFormViewModel == null) { - FormViewModel.sFormViewModel = new FormViewModel(); - } - return FormViewModel.sFormViewModel; - } - - public async castTempFormToNormal(formId: string) { - formManager.castTempForm(formId) - .then((data) => { - console.info('[FormComponent] castTempForm result:' + data); - }); - } - - public async requestForm(formId: string) { - formManager.requestForm(formId) - .then((data) => { - console.info('[FormComponent] requestForm result:' + data); - }); - } - - public async deleteCard(formId: string) { - formManager.deleteForm(formId) - .then((data) => { - console.info('[FormComponent] deleteForm result:' + data); - }); - } - - public async releaseCard(formId: string) { - formManager.releaseForm(formId) - .then((data) => { - console.info('[FormComponent] releaseForm result:' + data); - }); - } - - public async enableCard(formId: string) { - formManager.enableFormsUpdate([formId]) - .then((data) => { - console.info('[FormComponent] enableFormsUpdate result:' + data); - }); - } - - public async disableCard(formId: string) { - formManager.disableFormsUpdate([formId]) - .then((data) => { - console.info('[FormComponent] disableCard result:' + data); - }); - } - - public async changeCardVisible(formId: string, isVisible: boolean) { - if (isVisible) { - formManager.notifyVisibleForms([formId]) - .then((data) => { - console.info('[FormComponent] changeCardVisible result:' + data + ', isVisible:' + isVisible); - }); - } else { - formManager.notifyInvisibleForms([formId]) - .then((data) => { - console.info('[FormComponent] changeCardVisible result:' + data + ', isVisible:' + isVisible); - }); - } - } - - public async isFmsReady() { - formManager.isSystemReady() - .then((data) => { - console.info('[FormComponent] isFmsReady result:' + data); - }); - } - - public async getAllFormsInfo() { - formManager.getAllFormsInfo() - .then((data) => { - console.info('[FormComponent] getAllFormsInfo result:' + JSON.stringify(data)); - }); - } - - public async getFormsInfoByApp(bundle: string) { - formManager.getFormsInfo(bundle) - .then((data) => { - console.info('[FormComponent] getFormsInfoByApp result:' + JSON.stringify(data)); - }); - } - - public async getFormsInfoByModule(bundle: string, moduleName: string) { - formManager.getFormsInfo(bundle, moduleName) - .then((data) => { - console.info('[FormComponent] getFormsInfoByModule result:' + JSON.stringify(data)); - }); - } - - public async clearFormUserCache() { - abilityManager.clearUpApplicationData('com.ohos.myapplicationform') - .then((data) => { - console.info('[FormComponent] cleanBundleCacheFiles result:' + JSON.stringify(data)); - }); - } - - public async clearFormProviderCache(bundle: string) { - abilityManager.clearUpApplicationData(bundle) - .then((data) => { - console.info('[FormComponent] cleanBundleCacheFiles result:' + JSON.stringify(data)); - }); - } -} \ No newline at end of file diff --git a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostnoperm/entry/src/main/ets/MainAbility/pages/index.ets b/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostnoperm/entry/src/main/ets/MainAbility/pages/index.ets index e3b5aa05994955fe402d41ecb074a72a1d7fbf88..4bc1a76a3696910add8590c4ea6e601092da7228 100644 --- a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostnoperm/entry/src/main/ets/MainAbility/pages/index.ets +++ b/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostnoperm/entry/src/main/ets/MainAbility/pages/index.ets @@ -1,354 +1,335 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import FormViewModel from './FormViewModel.ets'; -import router from '@system.router'; -import featureAbility from "@ohos.ability.featureAbility"; -import formManager from '@ohos.application.formHost' -import commonEvent from '@ohos.commonEvent'; - -@Entry -@Component -struct Index { - @State formId: number = 0; - @State bundle: string = "com.form.formsystemtestservicea.hmservice"; - @State ability: string = "com.form.formsystemtestservicea.hmservice.MainAbility"; - @State moduleName: string = "entry"; - @State name: string = "Form_Js001"; - @State width: number = 300; - @State height: number = 200; - @State allowUpate: boolean = true; - @State onAcquireResult: string = ""; - @State isShowing: boolean = true; - @State canCreateForm: boolean = false; - - private dimension: FormDimension = FormDimension.Dimension_1_2; - - private stateForm = "visible"; - private stateIds = []; - private requestForm = false; - private requestId = "-1"; - private releaseForm = false; - private releaseId = "-1"; - private deleteForm = false; - private deleteId = "-1"; - private temporary = false; - private mFormViewModel: FormViewModel; - private isVisible = false; - private mMargin = 15; - private BTN_BG_COLOR: string = '#0D9FFB'; - private castForm = false; - private tempFormId: number = 0; - - private formOnErrorEvent = "FMS_FormOnError_commonEvent"; - private formOnDeletedEvent = "FMS_FormOnDeleted_commonEvent"; - private formOnReleasedEvent = "FMS_FormOnReleased_commonEvent"; - private formOnRequestEvent = "FMS_FormOnRequest_commonEvent"; - private formOnStateEvent = "FMS_FormOnState_commonEvent"; - - private publishCallBack() { - console.debug("====>formOnErrorEvent Publish CallBack ====>"); - } - - private aboutToAppear() { - - const TAG = "[FormComponent.host]" - - this.mFormViewModel = FormViewModel.getInstance(); - - console.error('[FormComponent] getWant'); - featureAbility.getWant() - .then((want: any) => { - this.formId = parseInt(want.parameters.formId); - this.name = want.parameters.name; - this.bundle = want.parameters.bundle; - this.ability = want.parameters.ability; - if(want.parameters.moduleName) { - this.moduleName = want.parameters.moduleName; - } - if(want.parameters.temporary) { - this.temporary = want.parameters.temporary; - } - if(want.parameters.dimension) { - this.dimension = want.parameters.dimension; - } - if(want.parameters.castForm) { - this.castForm = want.parameters.castForm; - } - if(want.parameters.deleteForm) { - this.deleteForm = want.parameters.deleteForm; - } - if(want.parameters.deleteId) { - this.deleteId = want.parameters.deleteId; - } - if(want.parameters.releaseForm) { - this.releaseForm = want.parameters.releaseForm; - } - if(want.parameters.releaseId) { - this.releaseId = want.parameters.releaseId; - } - if(want.parameters.requestForm) { - this.requestForm = want.parameters.requestForm; - } - if(want.parameters.requestId) { - this.requestId = want.parameters.requestId; - } - if(want.parameters.stateForm) { - this.stateForm = want.parameters.stateForm; - } - if(want.parameters.stateIds) { - this.stateIds = want.parameters.stateIds; - } - - setTimeout(() => { - this.canCreateForm = want.parameters.isCreate ? true : false; - console.error('[FormComponent] getWant canCreateForm:'+ this.canCreateForm); - }, 10); - console.error('[FormComponent] getWant end'+ JSON.stringify(want)); - - if(!want.parameters.isCreate && this.deleteForm) { - console.log("formsystemhostnoperm deleteForm start"); - formManager.deleteForm(this.deleteId) - .then((data) => { - console.info('formsystemhostnoperm deleteForm result:' + data); - let commonEventPublishData = { - data: data.toString(), - parameters: { - "formId" : this.deleteId.toString() - } - }; - commonEvent.publish(this.formOnDeletedEvent, commonEventPublishData, this.publishCallBack); - }) - .catch((error) => { - console.info('formsystemhostnoperm deleteForm error:' + error); - let commonEventPublishData = { - data: error.code.toString(), - parameters: { - "formId" : this.deleteId.toString() - } - }; - commonEvent.publish(this.formOnDeletedEvent, commonEventPublishData, this.publishCallBack); - }); - - console.log("formsystemhostnoperm deleteForm end"); - } - - if(!want.parameters.isCreate && this.releaseForm) { - console.log("formsystemhost releaseForm start"); - formManager.releaseForm(this.releaseId) - .then((data) => { - console.info('formsystemhost releaseForm result:' + data); - let commonEventPublishData = { - data: data.toString(), - parameters: { - "formId" : this.releaseId.toString() - } - }; - commonEvent.publish(this.formOnReleasedEvent, commonEventPublishData, this.publishCallBack); - }) - .catch((error) => { - console.info('formsystemhost releaseForm error:' + error); - let commonEventPublishData = { - data: error.code.toString(), - parameters: { - "formId" : this.releaseId.toString() - } - }; - commonEvent.publish(this.formOnReleasedEvent, commonEventPublishData, this.publishCallBack); - }); - - console.log("formsystemhost releaseForm end"); - } - - if(!want.parameters.isCreate && this.requestForm) { - console.log("[FormComponent.host] requestForm start"); - formManager.requestForm(this.requestId) - .then((data) => { - console.info('[FormComponent] requestForm result:' + data); - let commonEventPublishData = { - data: data.toString(), - parameters: { - "formId" : this.requestId - } - }; - commonEvent.publish(this.formOnRequestEvent, commonEventPublishData, this.publishCallBack); - }) - .catch((error) => { - console.info('[FormComponent] requestForm error:' + error); - let commonEventPublishData = { - data: error.code.toString(), - parameters: { - "formId" : this.requestId - } - }; - commonEvent.publish(this.formOnRequestEvent, commonEventPublishData, this.publishCallBack); - }); - - console.log("[FormComponent.host] requestForm end"); - } - if(!want.parameters.isCreate && this.stateForm) { - if(this.stateForm == "visible") { - console.log("formsystemhost notifyVisibleForm start"); - formManager.notifyVisibleForms(this.stateIds) - .then((data) => { - console.info('formsystemhost notifyVisibleForm result:' + data); - let retData = "0"; - if(data == 0) { - retData = data.toString(); - } else { - retData = data.code.toString(); - } - let commonEventPublishData = { - data: retData, - parameters: { - "formId" : this.stateIds.toString() - } - }; - commonEvent.publish(this.formOnStateEvent, commonEventPublishData, this.publishCallBack); - }) - .catch((error) => { - console.info('formsystemhost notifyVisibleForm error:' + error); - let commonEventPublishData = { - data: error.code.toString(), - parameters: { - "formId" : this.stateIds.toString() - } - }; - commonEvent.publish(this.formOnStateEvent, commonEventPublishData, this.publishCallBack); - }); - console.log("formsystemhost notifyVisibleForm end"); - } else if(this.stateForm == "invisible") { - console.log("formsystemhost notifyInvisibleForm start"); - formManager.notifyInvisibleForms(this.stateIds) - .then((data) => { - console.info('formsystemhost notifyInvisibleForm result:' + data); - let commonEventPublishData = { - data: data.toString(), - parameters: { - "formId" : this.stateIds.toString() - } - }; - commonEvent.publish(this.formOnStateEvent, commonEventPublishData, this.publishCallBack); - }) - .catch((error) => { - console.info('formsystemhost notifyInvisibleForm error:' + error); - let commonEventPublishData = { - data: error.code.toString(), - parameters: { - "formId" : this.stateIds.toString() - } - }; - commonEvent.publish(this.formOnStateEvent, commonEventPublishData, this.publishCallBack); - }); - console.log("formsystemhost notifyInvisibleForm end"); - } else if(this.stateForm == "enable") { - console.log("formsystemhost enableFormsUpdate start"); - formManager.enableFormsUpdate(this.stateIds) - .then((data) => { - console.info('formsystemhost enableFormsUpdate result:' + data); - let commonEventPublishData = { - data: data.toString(), - parameters: { - "formId" : this.stateIds.toString() - } - }; - commonEvent.publish(this.formOnStateEvent, commonEventPublishData, this.publishCallBack); - }) - .catch((error) => { - console.info('formsystemhost enableFormsUpdate error:' + error); - let commonEventPublishData = { - data: error.code.toString(), - parameters: { - "formId" : this.stateIds.toString() - } - }; - commonEvent.publish(this.formOnStateEvent, commonEventPublishData, this.publishCallBack); - }); - console.log("formsystemhost enableFormsUpdate end"); - } else { - console.log("formsystemhost disableFormsUpdate start"); - formManager.disableFormsUpdate(this.stateIds) - .then((data) => { - console.info('formsystemhost disableFormsUpdate result:' + data); - let commonEventPublishData = { - data: data.toString(), - parameters: { - "formId" : this.stateIds.toString() - } - }; - commonEvent.publish(this.formOnStateEvent, commonEventPublishData, this.publishCallBack); - }) - .catch((error) => { - console.info('formsystemhost disableFormsUpdate error:' + error); - let commonEventPublishData = { - data: error.code.toString(), - parameters: { - "formId" : this.stateIds.toString() - } - }; - commonEvent.publish(this.formOnStateEvent, commonEventPublishData, this.publishCallBack); - }); - console.log("formsystemhost disableFormsUpdate end"); - } - } - - }) - .catch((error: any) => { - console.error('[FormComponent] Operation failed. Cause: ' + JSON.stringify(error)); - }) - - console.log(`[FormComponent.host] aboutToAppear end`); - } - - build() { - Column() { - Text('form component test begin') - Column() { - if (this.canCreateForm) { - FormComponent({ - id: this.formId, - name: this.name, - bundle: this.bundle, - ability: this.ability, - module: this.moduleName, - dimension: this.dimension, - temporary: this.temporary, - }) - .allowUpdate(this.allowUpate) - .visibility(this.isShowing ? Visibility.Visible : Visibility.Hidden) - .onAcquired((form) => { - this.formId = form.id; - console.log("[FormComponent.host] get form, form id:" + form.id); - }) - .onError((error) => { - console.log("[FormComponent.host] error code:" + error.errcode); - console.log("[FormComponent.host] error msg:" + error.msg); - this.onAcquireResult += error.errcode; - this.onAcquireResult += " "; - this.onAcquireResult += error.msg; - - let commonEventPublishData = { - data: error.msg - }; - commonEvent.publish(this.formOnErrorEvent, commonEventPublishData, this.publishCallBack); - }) - } - } - .backgroundColor(Color.White) - Text('form component test end') - } - .backgroundColor(Color.White) - } +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import commonEvent from '@ohos.commonEvent'; +import featureAbility from "@ohos.ability.featureAbility"; +import formManager from '@ohos.application.formHost'; + +@Entry +@Component +struct Index { + @State formId: number = 0; + @State bundle: string = "com.form.formsystemtestservicea.hmservice"; + @State ability: string = "com.form.formsystemtestservicea.hmservice.MainAbility"; + @State moduleName: string = "entry"; + @State name: string = "Form_Js001"; + @State allowUpate: boolean = true; + @State isShowing: boolean = true; + @State canCreateForm: boolean = false; + + private dimension: FormDimension = FormDimension.Dimension_1_2; + + private stateForm = "visible"; + private stateIds = []; + private requestForm = false; + private requestId = "-1"; + private releaseForm = false; + private releaseId = "-1"; + private deleteForm = false; + private deleteId = "-1"; + private temporary = false; + private castForm = false; + + private formOnErrorEvent = "FMS_FormOnError_commonEvent"; + private formOnDeletedEvent = "FMS_FormOnDeleted_commonEvent"; + private formOnReleasedEvent = "FMS_FormOnReleased_commonEvent"; + private formOnRequestEvent = "FMS_FormOnRequest_commonEvent"; + private formOnStateEvent = "FMS_FormOnState_commonEvent"; + + private publishCallBack() { + console.debug("====>formOnErrorEvent Publish CallBack ====>"); + } + + private aboutToAppear() { + console.error('[FormComponent] getWant'); + featureAbility.getWant() + .then((want: any) => { + this.formId = parseInt(want.parameters.formId); + this.name = want.parameters.name; + this.bundle = want.parameters.bundle; + this.ability = want.parameters.ability; + if(want.parameters.moduleName) { + this.moduleName = want.parameters.moduleName; + } + if(want.parameters.temporary) { + this.temporary = want.parameters.temporary; + } + if(want.parameters.dimension) { + this.dimension = want.parameters.dimension; + } + if(want.parameters.castForm) { + this.castForm = want.parameters.castForm; + } + if(want.parameters.deleteForm) { + this.deleteForm = want.parameters.deleteForm; + } + if(want.parameters.deleteId) { + this.deleteId = want.parameters.deleteId; + } + if(want.parameters.releaseForm) { + this.releaseForm = want.parameters.releaseForm; + } + if(want.parameters.releaseId) { + this.releaseId = want.parameters.releaseId; + } + if(want.parameters.requestForm) { + this.requestForm = want.parameters.requestForm; + } + if(want.parameters.requestId) { + this.requestId = want.parameters.requestId; + } + if(want.parameters.stateForm) { + this.stateForm = want.parameters.stateForm; + } + if(want.parameters.stateIds) { + this.stateIds = want.parameters.stateIds; + } + + setTimeout(() => { + this.canCreateForm = want.parameters.isCreate ? true : false; + console.error('[FormComponent] getWant canCreateForm:'+ this.canCreateForm); + }, 10); + console.error('[FormComponent] getWant end'+ JSON.stringify(want)); + + if(!want.parameters.isCreate && this.deleteForm) { + console.log("formsystemhostnoperm deleteForm start"); + formManager.deleteForm(this.deleteId) + .then((data) => { + console.info('formsystemhostnoperm deleteForm result:' + data); + let commonEventPublishData = { + data: data.toString(), + parameters: { + "formId" : this.deleteId.toString() + } + }; + commonEvent.publish(this.formOnDeletedEvent, commonEventPublishData, this.publishCallBack); + }) + .catch((error) => { + console.info('formsystemhostnoperm deleteForm error:' + error); + let commonEventPublishData = { + data: error.code.toString(), + parameters: { + "formId" : this.deleteId.toString() + } + }; + commonEvent.publish(this.formOnDeletedEvent, commonEventPublishData, this.publishCallBack); + }); + + console.log("formsystemhostnoperm deleteForm end"); + } + + if(!want.parameters.isCreate && this.releaseForm) { + console.log("formsystemhost releaseForm start"); + formManager.releaseForm(this.releaseId) + .then((data) => { + console.info('formsystemhost releaseForm result:' + data); + let commonEventPublishData = { + data: data.toString(), + parameters: { + "formId" : this.releaseId.toString() + } + }; + commonEvent.publish(this.formOnReleasedEvent, commonEventPublishData, this.publishCallBack); + }) + .catch((error) => { + console.info('formsystemhost releaseForm error:' + error); + let commonEventPublishData = { + data: error.code.toString(), + parameters: { + "formId" : this.releaseId.toString() + } + }; + commonEvent.publish(this.formOnReleasedEvent, commonEventPublishData, this.publishCallBack); + }); + + console.log("formsystemhost releaseForm end"); + } + + if(!want.parameters.isCreate && this.requestForm) { + console.log("[FormComponent.host] requestForm start"); + formManager.requestForm(this.requestId) + .then((data) => { + console.info('[FormComponent] requestForm result:' + data); + let commonEventPublishData = { + data: data.toString(), + parameters: { + "formId" : this.requestId + } + }; + commonEvent.publish(this.formOnRequestEvent, commonEventPublishData, this.publishCallBack); + }) + .catch((error) => { + console.info('[FormComponent] requestForm error:' + error); + let commonEventPublishData = { + data: error.code.toString(), + parameters: { + "formId" : this.requestId + } + }; + commonEvent.publish(this.formOnRequestEvent, commonEventPublishData, this.publishCallBack); + }); + + console.log("[FormComponent.host] requestForm end"); + } + if(!want.parameters.isCreate && this.stateForm) { + if(this.stateForm == "visible") { + console.log("formsystemhost notifyVisibleForm start"); + formManager.notifyVisibleForms(this.stateIds) + .then((data) => { + console.info('formsystemhost notifyVisibleForm result:' + data); + let retData = "0"; + if(data == 0) { + retData = data.toString(); + } else { + retData = data.code.toString(); + } + let commonEventPublishData = { + data: retData, + parameters: { + "formId" : this.stateIds.toString() + } + }; + commonEvent.publish(this.formOnStateEvent, commonEventPublishData, this.publishCallBack); + }) + .catch((error) => { + console.info('formsystemhost notifyVisibleForm error:' + error); + let commonEventPublishData = { + data: error.code.toString(), + parameters: { + "formId" : this.stateIds.toString() + } + }; + commonEvent.publish(this.formOnStateEvent, commonEventPublishData, this.publishCallBack); + }); + console.log("formsystemhost notifyVisibleForm end"); + } else if(this.stateForm == "invisible") { + console.log("formsystemhost notifyInvisibleForm start"); + formManager.notifyInvisibleForms(this.stateIds) + .then((data) => { + console.info('formsystemhost notifyInvisibleForm result:' + data); + let commonEventPublishData = { + data: data.toString(), + parameters: { + "formId" : this.stateIds.toString() + } + }; + commonEvent.publish(this.formOnStateEvent, commonEventPublishData, this.publishCallBack); + }) + .catch((error) => { + console.info('formsystemhost notifyInvisibleForm error:' + error); + let commonEventPublishData = { + data: error.code.toString(), + parameters: { + "formId" : this.stateIds.toString() + } + }; + commonEvent.publish(this.formOnStateEvent, commonEventPublishData, this.publishCallBack); + }); + console.log("formsystemhost notifyInvisibleForm end"); + } else if(this.stateForm == "enable") { + console.log("formsystemhost enableFormsUpdate start"); + formManager.enableFormsUpdate(this.stateIds) + .then((data) => { + console.info('formsystemhost enableFormsUpdate result:' + data); + let commonEventPublishData = { + data: data.toString(), + parameters: { + "formId" : this.stateIds.toString() + } + }; + commonEvent.publish(this.formOnStateEvent, commonEventPublishData, this.publishCallBack); + }) + .catch((error) => { + console.info('formsystemhost enableFormsUpdate error:' + error); + let commonEventPublishData = { + data: error.code.toString(), + parameters: { + "formId" : this.stateIds.toString() + } + }; + commonEvent.publish(this.formOnStateEvent, commonEventPublishData, this.publishCallBack); + }); + console.log("formsystemhost enableFormsUpdate end"); + } else { + console.log("formsystemhost disableFormsUpdate start"); + formManager.disableFormsUpdate(this.stateIds) + .then((data) => { + console.info('formsystemhost disableFormsUpdate result:' + data); + let commonEventPublishData = { + data: data.toString(), + parameters: { + "formId" : this.stateIds.toString() + } + }; + commonEvent.publish(this.formOnStateEvent, commonEventPublishData, this.publishCallBack); + }) + .catch((error) => { + console.info('formsystemhost disableFormsUpdate error:' + error); + let commonEventPublishData = { + data: error.code.toString(), + parameters: { + "formId" : this.stateIds.toString() + } + }; + commonEvent.publish(this.formOnStateEvent, commonEventPublishData, this.publishCallBack); + }); + console.log("formsystemhost disableFormsUpdate end"); + } + } + + }) + .catch((error: any) => { + console.error('[FormComponent] Operation failed. Cause: ' + JSON.stringify(error)); + }) + + console.log(`[FormComponent.host] aboutToAppear end`); + } + + build() { + Column() { + Text('form component test begin') + Column() { + if (this.canCreateForm) { + FormComponent({ + id: this.formId, + name: this.name, + bundle: this.bundle, + ability: this.ability, + module: this.moduleName, + dimension: this.dimension, + temporary: this.temporary, + }) + .allowUpdate(this.allowUpate) + .visibility(this.isShowing ? Visibility.Visible : Visibility.Hidden) + .onAcquired((form) => { + this.formId = form.id; + console.log("[FormComponent.host] get form, form id:" + form.id); + }) + .onError((error) => { + console.log("[FormComponent.host] error code:" + error.errcode); + console.log("[FormComponent.host] error msg:" + error.msg); + let commonEventPublishData = { + data: error.msg + }; + commonEvent.publish(this.formOnErrorEvent, commonEventPublishData, this.publishCallBack); + }) + } + } + .backgroundColor(Color.White) + Text('form component test end') + } + .backgroundColor(Color.White) + } } \ No newline at end of file diff --git a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostnoperm/entry/src/main/resources/base/element/string.json b/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostnoperm/entry/src/main/resources/base/element/string.json index 66cc8e0f2ebb653c63c0a4a708e9f3705764abe3..9fbbb3f68ca2efbbaa315fbc8c7c087bd07b9ab6 100644 --- a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostnoperm/entry/src/main/resources/base/element/string.json +++ b/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostnoperm/entry/src/main/resources/base/element/string.json @@ -2,7 +2,7 @@ "string": [ { "name": "entry_MainAbility", - "value": "formhostB" + "value": "formhostNoPerm" }, { "name": "description_mainability", diff --git a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhosto/entry/src/main/ets/MainAbility/pages/index.ets b/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhosto/entry/src/main/ets/MainAbility/pages/index.ets index 93da5a98a87834e505d990e13ca58130438a0ae4..ef8e33d681a1b36f59b7b3b10a3d7a0eb845a287 100644 --- a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhosto/entry/src/main/ets/MainAbility/pages/index.ets +++ b/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhosto/entry/src/main/ets/MainAbility/pages/index.ets @@ -1,438 +1,432 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import featureAbility from "@ohos.ability.featureAbility"; -import formManager from '@ohos.application.formHost'; -import commonEvent from '@ohos.commonEvent'; -@Entry -@Component -struct Index { - @State bundle: string = "com.form.formsystemtestservicea.hmservice"; - @State ability: string = "com.form.formsystemtestservicea.hmservice.FormAbility"; - @State moduleName: string = "entry"; - @State name: string = "Form_Js001"; - @State width: number = 300; - @State height: number = 200; - @State allowUpate: boolean = true; - @State onAcquireResult: string = ""; - @State isShowing: boolean = true; - @State optType: number = 0; - private dimension: FormDimension = FormDimension.Dimension_1_2; - private isTemporary = false; - private isVisible = false; - private mMargin = 15; - private BTN_BG_COLOR: string = '#0D9FFB'; - - private normal = 0; - private temporary = 0; - private normaldel = 0; - private temporarydel = 0; - private normalFormIds = []; - private tempFormIds = []; - - private deleteIds = []; - private delCount = 0; - - private normalFormCounts = []; - private tempFormCounts = []; - - private castFormId = "-1"; - - private formOnAcquiredEvent = "FMS_FormOnAcquired_commonEvent"; - private formOnErrorEvent = "FMS_FormOnError_commonEvent"; - private formCastEvent = "FMS_FormCast_commonEvent"; - - private subscriberDel; - private subscriberFormDeleteEvent = { - events: ["FMS_FormDelete_commonEvent"], - }; - - private subscriberSendCastForm; - private subscriberSendCastFormEvent = { - events: ["FMS_SendCastForm_commonEvent"], - }; - - private publishOnErrorCallBack() { - console.debug("====> [FormComponent] formsystemhosto formOnErrorEvent Publish CallBack ====>"); - } - private publishOnAcquiredCallBack() { - console.debug("====> [FormComponent] formsystemhosto formOnAcquiredEvent Publish CallBack ====>"); - } - private publishDeleteCallBack() { - console.debug("====> [FormComponent] formsystemhosto publishDeleteCallBack Publish CallBack ====>"); - } - private publishCastCallBack() { - console.debug("====>formCastEvent Publish CallBack ====>"); - } - private startAbility(bundleName, abilityName, sendMsg) { - featureAbility.startAbility({ - want: { - bundleName: bundleName, - abilityName: abilityName, - parameters: { - "formId": "0", - "name": "Form_Js001", - "bundle": "com.form.formsystemtestservicea.hmservice", - "ability": "com.form.formsystemtestservicea.hmservice.FormAbility", - "moduleName": "entry", - "temporary": false, - "sendCastForm": true, - "sendCastFormMsg": sendMsg, - "isCreate": false - } - } - }).then((res: any) => { - console.info(`[FormComponent] formsystemhosto featureAbility.startAbility res: ${JSON.stringify(res)}`); - }).catch((err: any) => { - console.info(`[FormComponent] formsystemhosto featureAbility.startAbility error: ${JSON.stringify(err)}`); - }); - } - private publishOnSendCastForm(err, data) { - console.info("!!!====>[FormComponent] formsystemhosto OnSendCastForm start:====>" + JSON.stringify(data)); - if (data.bundleName && data.bundleName != "com.ohos.st.formsystemhosto") { - return; - } - let formId = data.parameters.castFormId; - setTimeout(function () { - console.info("[FormComponent.host] castTempForm start, formId: " + formId); - formManager.castTempForm(formId) - .then((data) => { - console.info('[FormComponent] castTempForm result:' + data); - this.startAbility("com.ohos.st.formsystemhostc", "com.ohos.st.formsystemhostc.MainAbility", data.toString()); - }) - .catch((error) => { - console.info('[FormComponent] castTempForm error:' + JSON.stringify(error)); - this.startAbility("com.ohos.st.formsystemhostc", "com.ohos.st.formsystemhostc.MainAbility", error.code.toString()); - }); - console.info("[FormComponent.host] castTempForm end"); - }, 5000); - console.info("!!!====>[FormComponent] formsystemhosto OnSendCastForm end"); - } - - private deleteCallBack(err, data) { - console.info("!!!====>[FormComponent] formsystemhosto deleteCallBack start:====>" + JSON.stringify(data)); - const delFormIds = data.parameters.formIds; - console.info(`[FormComponent] data size ${delFormIds.length}`); - - console.info(`[FormComponent] data.subscriber ${JSON.stringify(this.subscriberDel)}`); - commonEvent.unsubscribe(this.subscriberDel, () => { - console.info("====> [FormComponent] formsystemhosto optType unSubscribeDeleteCallback CallBack====>"); - }); - commonEvent.unsubscribe(this.subscriberSendCastForm, () => { - console.info("====> [FormComponent] formsystemhosto optType unSubscribeCastFormCallback CallBack====>"); - }); - console.info(`[FormComponent] data.bundleName ${JSON.stringify(data.bundleName)}`); - console.info(`[FormComponent] tof ${"com.ohos.st.formsystemhosto" != data.bundleName}`); - if ("com.ohos.st.formsystemhosto" != data.bundleName) { - return; - } - delFormIds.forEach(async (formId, index) => { - console.info(`[FormComponent] formsystemhosto deleteForm ${index}`); - try { - const res = await formManager.deleteForm(formId); - console.info(`[FormComponent] formsystemhosto deleteForm ${index} ${formId} result: ${JSON.stringify(res)}`); - } catch (error) { - console.info(`[FormComponent] formsystemhosto deleteForm ${index} ${formId} error: ${JSON.stringify(error)}`); - } - }); - console.info("!!!====> [FormComponent] formsystemhosto optType deleteCallBack end ====>"); - } - - private unSubscribeDeleteCallback() { - console.debug("====> [FormComponent] formsystemhosto optType unSubscribeDeleteCallback CallBack====>"); - } - - private unSubscribeCastFormCallback() { - console.debug("====> [FormComponent] formsystemhosto optType unSubscribeCastFormCallback CallBack====>"); - } - - private aboutToAppear() { - const TAG = "[FormComponent.hosto]"; - - commonEvent.createSubscriber(this.subscriberFormDeleteEvent).then(async (data) => { - console.info("====>[FormComponent] formsystemhosto Subscriber FormDelete data:====>", JSON.stringify(data)); - this.subscriberDel = data; - commonEvent.subscribe(this.subscriberDel, (err, data) => { - if ("com.ohos.st.formsystemhosto" != data.bundleName) { - return; - } else { - console.info("!!!====>[FormComponent.hosto] formsystemhosto deleteCallBack start:====>" + JSON.stringify(data)); - const delFormIds = data.parameters.formIds; - console.info(`[FormComponent] data size ${delFormIds.length}`); - commonEvent.unsubscribe(this.subscriberDel, () => { - console.info("====> [FormComponent] formsystemhosto optType unSubscribeDeleteCallback CallBack====>"); - }); - commonEvent.unsubscribe(this.subscriberSendCastForm, () => { - console.info("====> [FormComponent] formsystemhosto optType unSubscribeCastFormCallback CallBack====>"); - }); - let delCounter = 0; - delFormIds.forEach((formId) => { - formManager.deleteForm(formId, (error, data) => { - console.info(`[FormComponent] formsystemhosto deleteForm ${++delCounter} ${formId} data: ${JSON.stringify(data)} err: ${JSON.stringify(error)}`); - }); - }); - } - }); - }); - - commonEvent.createSubscriber(this.subscriberSendCastFormEvent).then(async (data) => { - console.info("====>[FormComponent] formsystemhosto Subscriber SendCastForm data:====>", JSON.stringify(data)); - this.subscriberSendCastForm = data; - await commonEvent.subscribe(this.subscriberSendCastForm, this.publishOnSendCastForm); - }); - - featureAbility.getWant() - .then((want: any) => { - console.info(" [FormComponent] formsystemhosto getWant:" + JSON.stringify(want)); - - this.name = want.parameters.name; - this.bundle = want.parameters.bundle; - this.ability = want.parameters.ability; - if (want.parameters.moduleName) { - this.moduleName = want.parameters.moduleName; - } - - if (want.parameters.dimension) { - this.dimension = want.parameters.dimension; - } - - if (want.parameters.normal) { - this.normal = want.parameters.normal; - } - - if (want.parameters.temporary) { - this.temporary = want.parameters.temporary; - } - if (want.parameters.normaldel) { - this.normaldel = want.parameters.normaldel; - } - - if (want.parameters.temporarydel) { - this.temporarydel = want.parameters.temporarydel; - } - - if (want.parameters.deleteIds) { - this.deleteIds = want.parameters.deleteIds; - } - if (want.parameters.castFormId) { - this.castFormId = want.parameters.castFormId; - } - - this.makeCount(); - - setTimeout(() => { - this.optType = want.parameters.optType; - console.info(' [FormComponent] formsystemhosto getWant optType:' + this.optType); - }, 10); - - if (this.castFormId != "-1" && want.parameters.optType == 3) { - console.info("[FormComponent.host] castTempForm start"); - commonEvent.unsubscribe(this.subscriberDel, () => { - console.info("====> [FormComponent] formsystemhosto optType unSubscribeDeleteCallback CallBack====>"); - }); - commonEvent.unsubscribe(this.subscriberSendCastForm, () => { - console.info("====> [FormComponent] formsystemhosto optType unSubscribeCastFormCallback CallBack====>"); - }); - - formManager.castTempForm(this.castFormId) - .then((data) => { - console.info('[FormComponent] castTempForm result:' + data); - let commonEventPublishData = { - data: data || `0`, - bundleName: "com.ohos.st.formsystemhosto", - parameters: { - formId: this.castFormId.toString() - } - }; - commonEvent.publish(this.formCastEvent, commonEventPublishData, this.publishCastCallBack); - }) - .catch((error) => { - console.info('[FormComponent] castTempForm error:' + JSON.stringify(error)); - let commonEventPublishData = { - data: error.code.toString(), - bundleName: "com.ohos.st.formsystemhosto", - parameters: { - errMsg: error.message, - formId: this.castFormId.toString() - } - }; - commonEvent.publish(this.formCastEvent, commonEventPublishData, this.publishCastCallBack); - }); - console.info("[FormComponent.host] castTempForm end"); - } - - if (want.parameters.optType == 2 && this.deleteIds.length > 0) { - for (let iIndex = 0; iIndex < this.deleteIds.length; ++iIndex) { - console.info("[FormComponent] formsystemhosto deleteForm start"); - formManager.deleteForm(this.deleteIds[iIndex]) - .then((data) => { - console.info('[FormComponent] formsystemhosto deleteForm result:' + data); - this.delCount++; - - if (this.delCount == this.deleteIds.length) { - let commonEventPublishData = { - data: data.toString(), - bundleName: "com.ohos.st.formsystemhosto", - parameters: { - "formIds": this.deleteIds - } - }; - commonEvent.publish(this.formOnErrorEvent, commonEventPublishData, this.publishDeleteCallBack); - } - }) - .catch((error) => { - console.info(' [FormComponent] formsystemhosto deleteForm error:' + error); - let commonEventPublishData = { - data: error.code.toString(), - bundleName: "com.ohos.st.formsystemhosto", - parameters: { - "formIds": [this.deleteIds[iIndex]] - } - }; - commonEvent.publish(this.formOnErrorEvent, commonEventPublishData, this.publishOnErrorCallBack); - }); - console.info("[FormComponent] formsystemhosto deleteForm end"); - } - } - }) - .catch((error: any) => { - console.error(' [FormComponent] formsystemhosto Operation failed. Cause: ' + JSON.stringify(error)); - }) - console.info(`[FormComponent.host] aboutToAppear end`); - } - - private makeCount() { - console.info(' [FormComponent] formsystemhosto makeCount start.'); - for (let nNormal = 0; nNormal < this.normal; nNormal++) { - this.normalFormCounts.push(nNormal); - } - console.info(' [FormComponent] formsystemhosto this.normalFormCounts.length:' + this.normalFormCounts.length); - - for (let nTemp = 0; nTemp < this.temporary; nTemp++) { - this.tempFormCounts.push(nTemp); - } - console.info(' [FormComponent] formsystemhosto this.tempFormCounts.length:' + this.tempFormCounts.length); - } - - build() { - Scroll(new Scroller()) { - Column() { - if (this.optType == 1) { - Text(' [FormComponent] formsystemhosto normal form component test begin') - Grid() { - ForEach(this.normalFormCounts, (item) => { - GridItem() { - FormComponent({ - id: 0, - name: this.name, - bundle: this.bundle, - ability: this.ability, - module: this.moduleName, - dimension: this.dimension, - temporary: false - }) - .allowUpdate(this.allowUpate) - .visibility(this.isShowing ? Visibility.Visible : Visibility.Hidden) - .onAcquired((form) => { - console.info(" [FormComponent] formsystemhosto get normal form, form id:" + form.id); - - this.normalFormIds.push(form.id.toString()); - if (this.normalFormIds.length == this.normal - this.normaldel) { - let commonEventPublishData = { - data: "normalForm", - bundleName: "com.ohos.st.formsystemhosto", - parameters: { - "formIds": this.normalFormIds - } - }; - commonEvent.publish(this.formOnAcquiredEvent, commonEventPublishData, this.publishOnAcquiredCallBack); - } - }) - .onError((error) => { - console.info(" [FormComponent] formsystemhosto normal form error code:" + error.errcode); - console.info(" [FormComponent] formsystemhosto normal form error msg:" + error.msg); - let commonEventPublishData = { - data: error.msg, - bundleName: "com.ohos.st.formsystemhosto" - }; - commonEvent.publish(this.formOnErrorEvent, commonEventPublishData, this.publishOnErrorCallBack); - }) - .size({ width: 40, height: 40 }) - } - }, (item) => JSON.stringify(item)) - } - .columnsTemplate('1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr ') - .columnsGap(2) - .rowsGap(2) - .width('100%') - Text(' [FormComponent] formsystemhosto normal form component test end') - - Text(' [FormComponent] formsystemhosto temp form component test start') - Grid() { - ForEach(this.tempFormCounts, (item) => { - GridItem() { - FormComponent({ - id: 0, - name: this.name, - bundle: this.bundle, - ability: this.ability, - module: this.moduleName, - dimension: this.dimension, - temporary: true - }) - .allowUpdate(this.allowUpate) - .visibility(this.isShowing ? Visibility.Visible : Visibility.Hidden) - .onAcquired((form) => { - console.info(" [FormComponent] formsystemhosto get temp form, form id:" + form.id); - this.tempFormIds.push(form.id.toString()); - if (this.tempFormIds.length == this.temporary - this.temporarydel) { - let commonEventPublishData = { - data: "tempForm", - bundleName: "com.ohos.st.formsystemhosto", - parameters: { - "formIds": this.tempFormIds - } - }; - commonEvent.publish(this.formOnAcquiredEvent, commonEventPublishData, this.publishOnAcquiredCallBack); - } - }) - .onError((error) => { - console.info(" [FormComponent] formsystemhosto temp form error code:" + error.errcode); - console.info(" [FormComponent] formsystemhosto temp form error msg:" + error.msg); - let commonEventPublishData = { - data: error.msg, - bundleName: "com.ohos.st.formsystemhosto" - }; - commonEvent.publish(this.formOnErrorEvent, commonEventPublishData, this.publishOnErrorCallBack); - }) - .size({ width: 40, height: 40 }) - } - }, (item) => JSON.stringify(item)) - } - .columnsTemplate('1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr ') - .columnsGap(2) - .rowsGap(2) - .width('100%') - - Text(' [FormComponent] formsystemhosto temp form component test end') - } - } - .backgroundColor(Color.White) - } - .scrollable(ScrollDirection.Vertical) - .width('100%') - .height('100%') - } +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import featureAbility from "@ohos.ability.featureAbility"; +import formManager from '@ohos.application.formHost'; +import commonEvent from '@ohos.commonEvent'; + +@Entry +@Component +struct Index { + @State bundle: string = "com.form.formsystemtestservicea.hmservice"; + @State ability: string = "com.form.formsystemtestservicea.hmservice.FormAbility"; + @State moduleName: string = "entry"; + @State name: string = "Form_Js001"; + @State allowUpate: boolean = true; + @State isShowing: boolean = true; + @State optType: number = 0; + private dimension: FormDimension = FormDimension.Dimension_1_2; + + private normal = 0; + private temporary = 0; + private normaldel = 0; + private temporarydel = 0; + private normalFormIds = []; + private tempFormIds = []; + + private deleteIds = []; + private delCount = 0; + + private normalFormCounts = []; + private tempFormCounts = []; + + private castFormId = "-1"; + + private formOnAcquiredEvent = "FMS_FormOnAcquired_commonEvent"; + private formOnErrorEvent = "FMS_FormOnError_commonEvent"; + private formCastEvent = "FMS_FormCast_commonEvent"; + + private subscriberDel; + private subscriberFormDeleteEvent = { + events: ["FMS_FormDelete_commonEvent"], + }; + + private subscriberSendCastForm; + private subscriberSendCastFormEvent = { + events: ["FMS_SendCastForm_commonEvent"], + }; + + private publishOnErrorCallBack() { + console.debug("====> [FormComponent] formsystemhosto formOnErrorEvent Publish CallBack ====>"); + } + private publishOnAcquiredCallBack() { + console.debug("====> [FormComponent] formsystemhosto formOnAcquiredEvent Publish CallBack ====>"); + } + private publishDeleteCallBack() { + console.debug("====> [FormComponent] formsystemhosto publishDeleteCallBack Publish CallBack ====>"); + } + private publishCastCallBack() { + console.debug("====>formCastEvent Publish CallBack ====>"); + } + private startAbility(bundleName, abilityName, sendMsg) { + featureAbility.startAbility({ + want: { + bundleName: bundleName, + abilityName: abilityName, + parameters: { + "formId": "0", + "name": "Form_Js001", + "bundle": "com.form.formsystemtestservicea.hmservice", + "ability": "com.form.formsystemtestservicea.hmservice.FormAbility", + "moduleName": "entry", + "temporary": false, + "sendCastForm": true, + "sendCastFormMsg": sendMsg, + "isCreate": false + } + } + }).then((res: any) => { + console.info(`[FormComponent] formsystemhosto featureAbility.startAbility res: ${JSON.stringify(res)}`); + }).catch((err: any) => { + console.info(`[FormComponent] formsystemhosto featureAbility.startAbility error: ${JSON.stringify(err)}`); + }); + } + private publishOnSendCastForm(err, data) { + console.info("!!!====>[FormComponent] formsystemhosto OnSendCastForm start:====>" + JSON.stringify(data)); + if (data.bundleName && data.bundleName != "com.ohos.st.formsystemhosto") { + return; + } + let formId = data.parameters.castFormId; + setTimeout(function () { + console.info("[FormComponent.host] castTempForm start, formId: " + formId); + formManager.castTempForm(formId) + .then((data) => { + console.info('[FormComponent] castTempForm result:' + data); + this.startAbility("com.ohos.st.formsystemhostc", "com.ohos.st.formsystemhostc.MainAbility", data.toString()); + }) + .catch((error) => { + console.info('[FormComponent] castTempForm error:' + JSON.stringify(error)); + this.startAbility("com.ohos.st.formsystemhostc", "com.ohos.st.formsystemhostc.MainAbility", error.code.toString()); + }); + console.info("[FormComponent.host] castTempForm end"); + }, 5000); + console.info("!!!====>[FormComponent] formsystemhosto OnSendCastForm end"); + } + + private deleteCallBack(err, data) { + console.info("!!!====>[FormComponent] formsystemhosto deleteCallBack start:====>" + JSON.stringify(data)); + const delFormIds = data.parameters.formIds; + console.info(`[FormComponent] data size ${delFormIds.length}`); + + console.info(`[FormComponent] data.subscriber ${JSON.stringify(this.subscriberDel)}`); + commonEvent.unsubscribe(this.subscriberDel, () => { + console.info("====> [FormComponent] formsystemhosto optType unSubscribeDeleteCallback CallBack====>"); + }); + commonEvent.unsubscribe(this.subscriberSendCastForm, () => { + console.info("====> [FormComponent] formsystemhosto optType unSubscribeCastFormCallback CallBack====>"); + }); + console.info(`[FormComponent] data.bundleName ${JSON.stringify(data.bundleName)}`); + console.info(`[FormComponent] tof ${"com.ohos.st.formsystemhosto" != data.bundleName}`); + if ("com.ohos.st.formsystemhosto" != data.bundleName) { + return; + } + delFormIds.forEach(async (formId, index) => { + console.info(`[FormComponent] formsystemhosto deleteForm ${index}`); + try { + const res = await formManager.deleteForm(formId); + console.info(`[FormComponent] formsystemhosto deleteForm ${index} ${formId} result: ${JSON.stringify(res)}`); + } catch (error) { + console.info(`[FormComponent] formsystemhosto deleteForm ${index} ${formId} error: ${JSON.stringify(error)}`); + } + }); + console.info("!!!====> [FormComponent] formsystemhosto optType deleteCallBack end ====>"); + } + + private unSubscribeDeleteCallback() { + console.debug("====> [FormComponent] formsystemhosto optType unSubscribeDeleteCallback CallBack====>"); + } + + private unSubscribeCastFormCallback() { + console.debug("====> [FormComponent] formsystemhosto optType unSubscribeCastFormCallback CallBack====>"); + } + + private aboutToAppear() { + const TAG = "[FormComponent.hosto]"; + + commonEvent.createSubscriber(this.subscriberFormDeleteEvent).then(async (data) => { + console.info("====>[FormComponent] formsystemhosto Subscriber FormDelete data:====>", JSON.stringify(data)); + this.subscriberDel = data; + commonEvent.subscribe(this.subscriberDel, (err, data) => { + if ("com.ohos.st.formsystemhosto" != data.bundleName) { + return; + } else { + console.info("!!!====>[FormComponent.hosto] formsystemhosto deleteCallBack start:====>" + JSON.stringify(data)); + const delFormIds = data.parameters.formIds; + console.info(`[FormComponent] data size ${delFormIds.length}`); + commonEvent.unsubscribe(this.subscriberDel, () => { + console.info("====> [FormComponent] formsystemhosto optType unSubscribeDeleteCallback CallBack====>"); + }); + commonEvent.unsubscribe(this.subscriberSendCastForm, () => { + console.info("====> [FormComponent] formsystemhosto optType unSubscribeCastFormCallback CallBack====>"); + }); + let delCounter = 0; + delFormIds.forEach((formId) => { + formManager.deleteForm(formId, (error, data) => { + console.info(`[FormComponent] formsystemhosto deleteForm ${++delCounter} ${formId} data: ${JSON.stringify(data)} err: ${JSON.stringify(error)}`); + }); + }); + } + }); + }); + + commonEvent.createSubscriber(this.subscriberSendCastFormEvent).then(async (data) => { + console.info("====>[FormComponent] formsystemhosto Subscriber SendCastForm data:====>", JSON.stringify(data)); + this.subscriberSendCastForm = data; + await commonEvent.subscribe(this.subscriberSendCastForm, this.publishOnSendCastForm); + }); + + featureAbility.getWant() + .then((want: any) => { + console.info(" [FormComponent] formsystemhosto getWant:" + JSON.stringify(want)); + + this.name = want.parameters.name; + this.bundle = want.parameters.bundle; + this.ability = want.parameters.ability; + if (want.parameters.moduleName) { + this.moduleName = want.parameters.moduleName; + } + + if (want.parameters.dimension) { + this.dimension = want.parameters.dimension; + } + + if (want.parameters.normal) { + this.normal = want.parameters.normal; + } + + if (want.parameters.temporary) { + this.temporary = want.parameters.temporary; + } + if (want.parameters.normaldel) { + this.normaldel = want.parameters.normaldel; + } + + if (want.parameters.temporarydel) { + this.temporarydel = want.parameters.temporarydel; + } + + if (want.parameters.deleteIds) { + this.deleteIds = want.parameters.deleteIds; + } + if (want.parameters.castFormId) { + this.castFormId = want.parameters.castFormId; + } + + this.makeCount(); + + setTimeout(() => { + this.optType = want.parameters.optType; + console.info(' [FormComponent] formsystemhosto getWant optType:' + this.optType); + }, 10); + + if (this.castFormId != "-1" && want.parameters.optType == 3) { + console.info("[FormComponent.host] castTempForm start"); + commonEvent.unsubscribe(this.subscriberDel, () => { + console.info("====> [FormComponent] formsystemhosto optType unSubscribeDeleteCallback CallBack====>"); + }); + commonEvent.unsubscribe(this.subscriberSendCastForm, () => { + console.info("====> [FormComponent] formsystemhosto optType unSubscribeCastFormCallback CallBack====>"); + }); + + formManager.castTempForm(this.castFormId) + .then((data) => { + console.info('[FormComponent] castTempForm result:' + data); + let commonEventPublishData = { + data: data || `0`, + bundleName: "com.ohos.st.formsystemhosto", + parameters: { + formId: this.castFormId.toString() + } + }; + commonEvent.publish(this.formCastEvent, commonEventPublishData, this.publishCastCallBack); + }) + .catch((error) => { + console.info('[FormComponent] castTempForm error:' + JSON.stringify(error)); + let commonEventPublishData = { + data: error.code.toString(), + bundleName: "com.ohos.st.formsystemhosto", + parameters: { + errMsg: error.message, + formId: this.castFormId.toString() + } + }; + commonEvent.publish(this.formCastEvent, commonEventPublishData, this.publishCastCallBack); + }); + console.info("[FormComponent.host] castTempForm end"); + } + + if (want.parameters.optType == 2 && this.deleteIds.length > 0) { + for (let iIndex = 0; iIndex < this.deleteIds.length; ++iIndex) { + console.info("[FormComponent] formsystemhosto deleteForm start"); + formManager.deleteForm(this.deleteIds[iIndex]) + .then((data) => { + console.info('[FormComponent] formsystemhosto deleteForm result:' + data); + this.delCount++; + + if (this.delCount == this.deleteIds.length) { + let commonEventPublishData = { + data: data.toString(), + bundleName: "com.ohos.st.formsystemhosto", + parameters: { + "formIds": this.deleteIds + } + }; + commonEvent.publish(this.formOnErrorEvent, commonEventPublishData, this.publishDeleteCallBack); + } + }) + .catch((error) => { + console.info(' [FormComponent] formsystemhosto deleteForm error:' + error); + let commonEventPublishData = { + data: error.code.toString(), + bundleName: "com.ohos.st.formsystemhosto", + parameters: { + "formIds": [this.deleteIds[iIndex]] + } + }; + commonEvent.publish(this.formOnErrorEvent, commonEventPublishData, this.publishOnErrorCallBack); + }); + console.info("[FormComponent] formsystemhosto deleteForm end"); + } + } + }) + .catch((error: any) => { + console.error(' [FormComponent] formsystemhosto Operation failed. Cause: ' + JSON.stringify(error)); + }) + console.info(`[FormComponent.host] aboutToAppear end`); + } + + private makeCount() { + console.info(' [FormComponent] formsystemhosto makeCount start.'); + for (let nNormal = 0; nNormal < this.normal; nNormal++) { + this.normalFormCounts.push(nNormal); + } + console.info(' [FormComponent] formsystemhosto this.normalFormCounts.length:' + this.normalFormCounts.length); + + for (let nTemp = 0; nTemp < this.temporary; nTemp++) { + this.tempFormCounts.push(nTemp); + } + console.info(' [FormComponent] formsystemhosto this.tempFormCounts.length:' + this.tempFormCounts.length); + } + + build() { + Scroll(new Scroller()) { + Column() { + if (this.optType == 1) { + Text(' [FormComponent] formsystemhosto normal form component test begin') + Grid() { + ForEach(this.normalFormCounts, (item) => { + GridItem() { + FormComponent({ + id: 0, + name: this.name, + bundle: this.bundle, + ability: this.ability, + module: this.moduleName, + dimension: this.dimension, + temporary: false + }) + .allowUpdate(this.allowUpate) + .visibility(this.isShowing ? Visibility.Visible : Visibility.Hidden) + .onAcquired((form) => { + console.info(" [FormComponent] formsystemhosto get normal form, form id:" + form.id); + + this.normalFormIds.push(form.id.toString()); + if (this.normalFormIds.length == this.normal - this.normaldel) { + let commonEventPublishData = { + data: "normalForm", + bundleName: "com.ohos.st.formsystemhosto", + parameters: { + "formIds": this.normalFormIds + } + }; + commonEvent.publish(this.formOnAcquiredEvent, commonEventPublishData, this.publishOnAcquiredCallBack); + } + }) + .onError((error) => { + console.info(" [FormComponent] formsystemhosto normal form error code:" + error.errcode); + console.info(" [FormComponent] formsystemhosto normal form error msg:" + error.msg); + let commonEventPublishData = { + data: error.msg, + bundleName: "com.ohos.st.formsystemhosto" + }; + commonEvent.publish(this.formOnErrorEvent, commonEventPublishData, this.publishOnErrorCallBack); + }) + .size({ width: 40, height: 40 }) + } + }, (item) => JSON.stringify(item)) + } + .columnsTemplate('1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr ') + .columnsGap(2) + .rowsGap(2) + .width('100%') + Text(' [FormComponent] formsystemhosto normal form component test end') + + Text(' [FormComponent] formsystemhosto temp form component test start') + Grid() { + ForEach(this.tempFormCounts, (item) => { + GridItem() { + FormComponent({ + id: 0, + name: this.name, + bundle: this.bundle, + ability: this.ability, + module: this.moduleName, + dimension: this.dimension, + temporary: true + }) + .allowUpdate(this.allowUpate) + .visibility(this.isShowing ? Visibility.Visible : Visibility.Hidden) + .onAcquired((form) => { + console.info(" [FormComponent] formsystemhosto get temp form, form id:" + form.id); + this.tempFormIds.push(form.id.toString()); + if (this.tempFormIds.length == this.temporary - this.temporarydel) { + let commonEventPublishData = { + data: "tempForm", + bundleName: "com.ohos.st.formsystemhosto", + parameters: { + "formIds": this.tempFormIds + } + }; + commonEvent.publish(this.formOnAcquiredEvent, commonEventPublishData, this.publishOnAcquiredCallBack); + } + }) + .onError((error) => { + console.info(" [FormComponent] formsystemhosto temp form error code:" + error.errcode); + console.info(" [FormComponent] formsystemhosto temp form error msg:" + error.msg); + let commonEventPublishData = { + data: error.msg, + bundleName: "com.ohos.st.formsystemhosto" + }; + commonEvent.publish(this.formOnErrorEvent, commonEventPublishData, this.publishOnErrorCallBack); + }) + .size({ width: 40, height: 40 }) + } + }, (item) => JSON.stringify(item)) + } + .columnsTemplate('1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr ') + .columnsGap(2) + .rowsGap(2) + .width('100%') + + Text(' [FormComponent] formsystemhosto temp form component test end') + } + } + .backgroundColor(Color.White) + } + .scrollable(ScrollDirection.Vertical) + .width('100%') + .height('100%') + } } \ No newline at end of file diff --git a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostp/entry/src/main/ets/MainAbility/pages/index.ets b/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostp/entry/src/main/ets/MainAbility/pages/index.ets index dfb47a149bf937c43ab72cad2745efe36d6bdd52..e91fed1e065c25c972e24469330a08cb76351144 100644 --- a/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostp/entry/src/main/ets/MainAbility/pages/index.ets +++ b/aafwk/aafwk_standard/formmanager/fa/formhostst_ets/formsystemhostp/entry/src/main/ets/MainAbility/pages/index.ets @@ -1,430 +1,422 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import featureAbility from "@ohos.ability.featureAbility"; -import formManager from '@ohos.application.formHost'; -import commonEvent from '@ohos.commonEvent'; -@Entry -@Component -struct Index { - @State bundle: string = "com.form.formsystemtestservicea.hmservice"; - @State ability: string = "com.form.formsystemtestservicea.hmservice.MainAbility"; - @State moduleName: string = "entry"; - @State name: string = "Form_Js001"; - @State width: number = 300; - @State height: number = 200; - @State allowUpate: boolean = true; - @State onAcquireResult: string = ""; - @State isShowing: boolean = true; - @State optType: number = 0; - private dimension: FormDimension = FormDimension.Dimension_1_2; - private isTemporary = false; - private isVisible = false; - private mMargin = 15; - private BTN_BG_COLOR: string = '#0D9FFB'; - - private normal = 0; - private temporary = 0; - private normaldel = 0; - private temporarydel = 0; - private normalFormIds = []; - private tempFormIds = []; - - private deleteIds = []; - private delCount = 0; - - private normalFormCounts = []; - private tempFormCounts = []; - - private castFormId = "-1"; - - private formOnAcquiredEvent = "FMS_FormOnAcquired_commonEvent"; - private formOnErrorEvent = "FMS_FormOnError_commonEvent"; - private formCastEvent = "FMS_FormCast_commonEvent"; - - private subscriberDel; - private subscriberFormDeleteEvent = { - events: ["FMS_FormDelete_commonEvent"], - }; - - private subscriberSendCastForm; - private subscriberSendCastFormEvent = { - events: ["FMS_SendCastForm_commonEvent"], - }; - - private publishOnErrorCallBack() { - console.debug("====> [FormComponent] formsystemhostp formOnErrorEvent Publish CallBack ====>"); - } - private publishOnAcquiredCallBack() { - console.debug("====> [FormComponent] formsystemhostp formOnAcquiredEvent Publish CallBack ====>"); - } - private publishDeleteCallBack() { - console.debug("====> [FormComponent] formsystemhostp publishDeleteCallBack Publish CallBack ====>"); - } - private publishCastCallBack() { - console.debug("====>formCastEvent Publish CallBack ====>"); - } - private startAbility(bundleName, abilityName, sendMsg) { - featureAbility.startAbility({ - want: { - bundleName: bundleName, - abilityName: abilityName, - parameters: { - "formId": "0", - "name": "Form_Js001", - "bundle": "com.form.formsystemtestservicea.hmservice", - "ability": "com.form.formsystemtestservicea.hmservice.MainAbility", - "moduleName": "entry", - "temporary": false, - "sendCastForm": true, - "sendCastFormMsg": sendMsg, - "isCreate": false - } - } - }).then((res: any) => { - console.info(`[FormComponent] formsystemhostp featureAbility.startAbility res: ${JSON.stringify(res)}`); - }).catch((err: any) => { - console.info(`[FormComponent] formsystemhostp featureAbility.startAbility error: ${JSON.stringify(err)}`); - }); - } - private publishOnSendCastForm(err, data) { - console.info("!!!====>[FormComponent] formsystemhostp OnSendCastForm start:====>" + JSON.stringify(data)); - if (data.bundleName && data.bundleName != "com.ohos.st.formsystemhostp") { - return; - } - let formId = data.parameters.castFormId; - setTimeout(function () { - console.info("[FormComponent.host] castTempForm start, formId: " + formId); - formManager.castTempForm(formId) - .then((data) => { - console.info('[FormComponent] castTempForm result:' + data); - this.startAbility("com.ohos.st.formsystemhostc", "com.ohos.st.formsystemhostc.MainAbility", data.toString()); - }) - .catch((error) => { - console.info('[FormComponent] castTempForm error:' + JSON.stringify(error)); - this.startAbility("com.ohos.st.formsystemhostc", "com.ohos.st.formsystemhostc.MainAbility", error.code.toString()); - }); - console.info("[FormComponent.host] castTempForm end"); - }, 5000); - console.info("!!!====>[FormComponent] formsystemhostp OnSendCastForm end"); - } - - private deleteCallBack(err, data) { - console.info("!!!====>[FormComponent] formsystemhostp deleteCallBack start:====>" + JSON.stringify(data)); - const delFormIds = data.parameters.formIds; - console.info(`[FormComponent] data size ${delFormIds.length}`); - - console.info(`[FormComponent] data.subscriber ${JSON.stringify(this.subscriberDel)}`); - commonEvent.unsubscribe(this.subscriberDel, () => { - console.info("====> [FormComponent] formsystemhostp optType unSubscribeDeleteCallback CallBack====>"); - }); - commonEvent.unsubscribe(this.subscriberSendCastForm, () => { - console.info("====> [FormComponent] formsystemhostp optType unSubscribeCastFormCallback CallBack====>"); - }); - console.info(`[FormComponent] data.bundleName ${JSON.stringify(data.bundleName)}`); - console.info(`[FormComponent] tof ${"com.ohos.st.formsystemhostp" != data.bundleName}`); - if ("com.ohos.st.formsystemhostp" != data.bundleName) { - return; - } - delFormIds.forEach(async (formId, index) => { - console.info(`[FormComponent] formsystemhostp deleteForm ${index}`); - try { - const res = await formManager.deleteForm(formId); - console.info(`[FormComponent] formsystemhostp deleteForm ${index} ${formId} result: ${JSON.stringify(res)}`); - } catch (error) { - console.info(`[FormComponent] formsystemhostp deleteForm ${index} ${formId} error: ${JSON.stringify(error)}`); - } - }); - console.info("!!!====> [FormComponent] formsystemhostp optType deleteCallBack end ====>"); - } - - private unSubscribeDeleteCallback() { - console.debug("====> [FormComponent] formsystemhostp optType unSubscribeDeleteCallback CallBack====>"); - } - - private unSubscribeCastFormCallback() { - console.debug("====> [FormComponent] formsystemhostp optType unSubscribeCastFormCallback CallBack====>"); - } - - private aboutToAppear() { - const TAG = "[FormComponent.hostp]"; - - commonEvent.createSubscriber(this.subscriberFormDeleteEvent).then(async (data) => { - console.info("====>[FormComponent] formsystemhostp Subscriber FormDelete data:====>", JSON.stringify(data)); - this.subscriberDel = data; - commonEvent.subscribe(this.subscriberDel, (err, data) => { - if ("com.ohos.st.formsystemhostp" != data.bundleName) { - return; - } else { - console.info("!!!====>[FormComponent.hostp] formsystemhostp deleteCallBack start:====>" + JSON.stringify(data)); - const delFormIds = data.parameters.formIds; - console.info(`[FormComponent] data size ${delFormIds.length}`); - commonEvent.unsubscribe(this.subscriberDel, () => { - console.info("====> [FormComponent] formsystemhostp optType unSubscribeDeleteCallback CallBack====>"); - }); - commonEvent.unsubscribe(this.subscriberSendCastForm, () => { - console.info("====> [FormComponent] formsystemhostp optType unSubscribeCastFormCallback CallBack====>"); - }); - let delCounter = 0; - delFormIds.forEach((formId) => { - formManager.deleteForm(formId, (error, data) => { - console.info(`[FormComponent] formsystemhostp deleteForm ${++delCounter} ${formId} data: ${JSON.stringify(data)} err: ${JSON.stringify(error)}`); - }); - }); - } - }); - }); - - commonEvent.createSubscriber(this.subscriberSendCastFormEvent).then(async (data) => { - console.info("====>[FormComponent] formsystemhostp Subscriber SendCastForm data:====>", JSON.stringify(data)); - this.subscriberSendCastForm = data; - await commonEvent.subscribe(this.subscriberSendCastForm, this.publishOnSendCastForm); - }); - - featureAbility.getWant() - .then((want: any) => { - console.info(" [FormComponent] formsystemhostp getWant:" + JSON.stringify(want)); - - this.name = want.parameters.name; - this.bundle = want.parameters.bundle; - this.ability = want.parameters.ability; - if (want.parameters.moduleName) { - this.moduleName = want.parameters.moduleName; - } - - if (want.parameters.dimension) { - this.dimension = want.parameters.dimension; - } - - if (want.parameters.normal) { - this.normal = want.parameters.normal; - } - - if (want.parameters.temporary) { - this.temporary = want.parameters.temporary; - } - if (want.parameters.normaldel) { - this.normaldel = want.parameters.normaldel; - } - - if (want.parameters.temporarydel) { - this.temporarydel = want.parameters.temporarydel; - } - - if (want.parameters.deleteIds) { - this.deleteIds = want.parameters.deleteIds; - } - if (want.parameters.castFormId) { - this.castFormId = want.parameters.castFormId; - } - - this.makeCount(); - - setTimeout(() => { - this.optType = want.parameters.optType; - console.info(' [FormComponent] formsystemhostp getWant optType:' + this.optType); - }, 10); - - if (this.castFormId != "-1" && want.parameters.optType == 3) { - console.info("[FormComponent.host] castTempForm start"); - formManager.castTempForm(this.castFormId) - .then((data) => { - console.info('[FormComponent] castTempForm result:' + data); - let commonEventPublishData = { - data: data.toString(), - bundleName: "com.ohos.st.formsystemhostp", - parameters: { - "formId": this.castFormId.toString() - } - }; - commonEvent.publish(this.formCastEvent, commonEventPublishData, this.publishCastCallBack); - }) - .catch((error) => { - console.info('[FormComponent] castTempForm error:' + error.code); - let commonEventPublishData = { - data: error.code.toString(), - bundleName: "com.ohos.st.formsystemhostp", - parameters: { - "formId": this.castFormId.toString() - } - }; - commonEvent.publish(this.formCastEvent, commonEventPublishData, this.publishCastCallBack); - }); - console.info("[FormComponent.host] castTempForm end"); - } - - if (want.parameters.optType == 2 && this.deleteIds.length > 0) { - for (let iIndex = 0; iIndex < this.deleteIds.length; ++iIndex) { - console.info("[FormComponent] formsystemhostp deleteForm start"); - formManager.deleteForm(this.deleteIds[iIndex]) - .then((data) => { - console.info('[FormComponent] formsystemhostp deleteForm result:' + data); - this.delCount++; - - if (this.delCount == this.deleteIds.length) { - let commonEventPublishData = { - data: data.toString(), - bundleName: "com.ohos.st.formsystemhostp", - parameters: { - "formIds": this.deleteIds - } - }; - commonEvent.publish(this.formOnErrorEvent, commonEventPublishData, this.publishDeleteCallBack); - } - }) - .catch((error) => { - console.info(' [FormComponent] formsystemhostp deleteForm error:' + error); - let commonEventPublishData = { - data: error.code.toString(), - bundleName: "com.ohos.st.formsystemhostp", - parameters: { - "formIds": [this.deleteIds[iIndex]] - } - }; - commonEvent.publish(this.formOnErrorEvent, commonEventPublishData, this.publishOnErrorCallBack); - }); - console.info("[FormComponent] formsystemhostp deleteForm end"); - } - } - }) - .catch((error: any) => { - console.error(' [FormComponent] formsystemhostp Operation failed. Cause: ' + JSON.stringify(error)); - }) - console.info(`[FormComponent.host] aboutToAppear end`); - } - - private makeCount() { - console.info(' [FormComponent] formsystemhostp makeCount start.'); - for (let nNormal = 0; nNormal < this.normal; nNormal++) { - this.normalFormCounts.push(nNormal); - } - console.info(' [FormComponent] formsystemhostp this.normalFormCounts.length:' + this.normalFormCounts.length); - - for (let nTemp = 0; nTemp < this.temporary; nTemp++) { - this.tempFormCounts.push(nTemp); - } - console.info(' [FormComponent] formsystemhostp this.tempFormCounts.length:' + this.tempFormCounts.length); - } - - build() { - Scroll(new Scroller()) { - Column() { - if (this.optType == 1) { - Text(' [FormComponent] formsystemhostp normal form component test begin') - Grid() { - ForEach(this.normalFormCounts, (item) => { - GridItem() { - FormComponent({ - id: 0, - name: this.name, - bundle: this.bundle, - ability: this.ability, - module: this.moduleName, - dimension: this.dimension, - temporary: false - }) - .allowUpdate(this.allowUpate) - .visibility(this.isShowing ? Visibility.Visible : Visibility.Hidden) - .onAcquired((form) => { - console.info(" [FormComponent] formsystemhostp get normal form, form id:" + form.id); - - this.normalFormIds.push(form.id.toString()); - if (this.normalFormIds.length == this.normal - this.normaldel) { - let commonEventPublishData = { - data: "normalForm", - bundleName: "com.ohos.st.formsystemhostp", - parameters: { - "formIds": this.normalFormIds - } - }; - commonEvent.publish(this.formOnAcquiredEvent, commonEventPublishData, this.publishOnAcquiredCallBack); - } - }) - .onError((error) => { - console.info(" [FormComponent] formsystemhostp normal form error code:" + error.errcode); - console.info(" [FormComponent] formsystemhostp normal form error msg:" + error.msg); - let commonEventPublishData = { - data: error.msg, - bundleName: "com.ohos.st.formsystemhostp" - }; - commonEvent.publish(this.formOnErrorEvent, commonEventPublishData, this.publishOnErrorCallBack); - }) - .size({ width: 40, height: 40 }) - } - }, (item) => JSON.stringify(item)) - } - .columnsTemplate('1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr ') - .columnsGap(2) - .rowsGap(2) - .width('100%') - Text(' [FormComponent] formsystemhostp normal form component test end') - - Text(' [FormComponent] formsystemhostp temp form component test start') - Grid() { - ForEach(this.tempFormCounts, (item) => { - GridItem() { - FormComponent({ - id: 0, - name: this.name, - bundle: this.bundle, - ability: this.ability, - module: this.moduleName, - dimension: this.dimension, - temporary: true - }) - .allowUpdate(this.allowUpate) - .visibility(this.isShowing ? Visibility.Visible : Visibility.Hidden) - .onAcquired((form) => { - console.info(" [FormComponent] formsystemhostp get temp form, form id:" + form.id); - this.tempFormIds.push(form.id.toString()); - if (this.tempFormIds.length == this.temporary - this.temporarydel) { - let commonEventPublishData = { - data: "tempForm", - bundleName: "com.ohos.st.formsystemhostp", - parameters: { - "formIds": this.tempFormIds - } - }; - commonEvent.publish(this.formOnAcquiredEvent, commonEventPublishData, this.publishOnAcquiredCallBack); - } - }) - .onError((error) => { - console.info(" [FormComponent] formsystemhostp temp form error code:" + error.errcode); - console.info(" [FormComponent] formsystemhostp temp form error msg:" + error.msg); - let commonEventPublishData = { - data: error.msg, - bundleName: "com.ohos.st.formsystemhostp" - }; - commonEvent.publish(this.formOnErrorEvent, commonEventPublishData, this.publishOnErrorCallBack); - }) - .size({ width: 40, height: 40 }) - } - }, (item) => JSON.stringify(item)) - } - .columnsTemplate('1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr ') - .columnsGap(2) - .rowsGap(2) - .width('100%') - - Text(' [FormComponent] formsystemhostp temp form component test end') - } - } - .backgroundColor(Color.White) - } - .scrollable(ScrollDirection.Vertical) - .width('100%') - .height('100%') - } +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import featureAbility from "@ohos.ability.featureAbility"; +import formManager from '@ohos.application.formHost'; +import commonEvent from '@ohos.commonEvent'; + +@Entry +@Component +struct Index { + @State bundle: string = "com.form.formsystemtestservicea.hmservice"; + @State ability: string = "com.form.formsystemtestservicea.hmservice.FormAbility"; + @State moduleName: string = "entry"; + @State name: string = "Form_Js001"; + @State allowUpate: boolean = true; + @State isShowing: boolean = true; + @State optType: number = 0; + private dimension: FormDimension = FormDimension.Dimension_1_2; + + private normal = 0; + private temporary = 0; + private normaldel = 0; + private temporarydel = 0; + private normalFormIds = []; + private tempFormIds = []; + + private deleteIds = []; + private delCount = 0; + + private normalFormCounts = []; + private tempFormCounts = []; + + private castFormId = "-1"; + + private formOnAcquiredEvent = "FMS_FormOnAcquired_commonEvent"; + private formOnErrorEvent = "FMS_FormOnError_commonEvent"; + private formCastEvent = "FMS_FormCast_commonEvent"; + + private subscriberDel; + private subscriberFormDeleteEvent = { + events: ["FMS_FormDelete_commonEvent"], + }; + + private subscriberSendCastForm; + private subscriberSendCastFormEvent = { + events: ["FMS_SendCastForm_commonEvent"], + }; + + private publishOnErrorCallBack() { + console.debug("====> [FormComponent] formsystemhostp formOnErrorEvent Publish CallBack ====>"); + } + private publishOnAcquiredCallBack() { + console.debug("====> [FormComponent] formsystemhostp formOnAcquiredEvent Publish CallBack ====>"); + } + private publishDeleteCallBack() { + console.debug("====> [FormComponent] formsystemhostp publishDeleteCallBack Publish CallBack ====>"); + } + private publishCastCallBack() { + console.debug("====>formCastEvent Publish CallBack ====>"); + } + private startAbility(bundleName, abilityName, sendMsg) { + featureAbility.startAbility({ + want: { + bundleName: bundleName, + abilityName: abilityName, + parameters: { + "formId": "0", + "name": "Form_Js001", + "bundle": "com.form.formsystemtestservicea.hmservice", + "ability": "com.form.formsystemtestservicea.hmservice.FormAbility", + "moduleName": "entry", + "temporary": false, + "sendCastForm": true, + "sendCastFormMsg": sendMsg, + "isCreate": false + } + } + }).then((res: any) => { + console.info(`[FormComponent] formsystemhostp featureAbility.startAbility res: ${JSON.stringify(res)}`); + }).catch((err: any) => { + console.info(`[FormComponent] formsystemhostp featureAbility.startAbility error: ${JSON.stringify(err)}`); + }); + } + private publishOnSendCastForm(err, data) { + console.info("!!!====>[FormComponent] formsystemhostp OnSendCastForm start:====>" + JSON.stringify(data)); + if (data.bundleName && data.bundleName != "com.ohos.st.formsystemhostp") { + return; + } + let formId = data.parameters.castFormId; + setTimeout(function () { + console.info("[FormComponent.host] castTempForm start, formId: " + formId); + formManager.castTempForm(formId) + .then((data) => { + console.info('[FormComponent] castTempForm result:' + data); + this.startAbility("com.ohos.st.formsystemhostc", "com.ohos.st.formsystemhostc.MainAbility", data.toString()); + }) + .catch((error) => { + console.info('[FormComponent] castTempForm error:' + JSON.stringify(error)); + this.startAbility("com.ohos.st.formsystemhostc", "com.ohos.st.formsystemhostc.MainAbility", error.code.toString()); + }); + console.info("[FormComponent.host] castTempForm end"); + }, 5000); + console.info("!!!====>[FormComponent] formsystemhostp OnSendCastForm end"); + } + + private deleteCallBack(err, data) { + console.info("!!!====>[FormComponent] formsystemhostp deleteCallBack start:====>" + JSON.stringify(data)); + const delFormIds = data.parameters.formIds; + console.info(`[FormComponent] data size ${delFormIds.length}`); + + console.info(`[FormComponent] data.subscriber ${JSON.stringify(this.subscriberDel)}`); + commonEvent.unsubscribe(this.subscriberDel, () => { + console.info("====> [FormComponent] formsystemhostp optType unSubscribeDeleteCallback CallBack====>"); + }); + commonEvent.unsubscribe(this.subscriberSendCastForm, () => { + console.info("====> [FormComponent] formsystemhostp optType unSubscribeCastFormCallback CallBack====>"); + }); + console.info(`[FormComponent] data.bundleName ${JSON.stringify(data.bundleName)}`); + console.info(`[FormComponent] tof ${"com.ohos.st.formsystemhostp" != data.bundleName}`); + if ("com.ohos.st.formsystemhostp" != data.bundleName) { + return; + } + delFormIds.forEach(async (formId, index) => { + console.info(`[FormComponent] formsystemhostp deleteForm ${index}`); + try { + const res = await formManager.deleteForm(formId); + console.info(`[FormComponent] formsystemhostp deleteForm ${index} ${formId} result: ${JSON.stringify(res)}`); + } catch (error) { + console.info(`[FormComponent] formsystemhostp deleteForm ${index} ${formId} error: ${JSON.stringify(error)}`); + } + }); + console.info("!!!====> [FormComponent] formsystemhostp optType deleteCallBack end ====>"); + } + + private aboutToAppear() { + commonEvent.createSubscriber(this.subscriberFormDeleteEvent).then(async (data) => { + console.info("====>[FormComponent] formsystemhostp Subscriber FormDelete data:====>", JSON.stringify(data)); + this.subscriberDel = data; + commonEvent.subscribe(this.subscriberDel, (err, data) => { + if ("com.ohos.st.formsystemhostp" != data.bundleName) { + return; + } else { + console.info("!!!====>[FormComponent.hostp] formsystemhostp deleteCallBack start:====>" + JSON.stringify(data)); + const delFormIds = data.parameters.formIds; + console.info(`[FormComponent] data size ${delFormIds.length}`); + commonEvent.unsubscribe(this.subscriberDel, () => { + console.info("====> [FormComponent] formsystemhostp optType unSubscribeDeleteCallback CallBack====>"); + }); + commonEvent.unsubscribe(this.subscriberSendCastForm, () => { + console.info("====> [FormComponent] formsystemhostp optType unSubscribeCastFormCallback CallBack====>"); + }); + let delCounter = 0; + delFormIds.forEach((formId) => { + formManager.deleteForm(formId, (error, data) => { + console.info(`[FormComponent] formsystemhostp deleteForm ${++delCounter} ${formId} data: ${JSON.stringify(data)} err: ${JSON.stringify(error)}`); + }); + }); + } + }); + }); + + commonEvent.createSubscriber(this.subscriberSendCastFormEvent).then(async (data) => { + console.info("====>[FormComponent] formsystemhostp Subscriber SendCastForm data:====>", JSON.stringify(data)); + this.subscriberSendCastForm = data; + await commonEvent.subscribe(this.subscriberSendCastForm, this.publishOnSendCastForm); + }); + + featureAbility.getWant() + .then((want: any) => { + console.info(" [FormComponent] formsystemhostp getWant:" + JSON.stringify(want)); + + this.name = want.parameters.name; + this.bundle = want.parameters.bundle; + this.ability = want.parameters.ability; + if (want.parameters.moduleName) { + this.moduleName = want.parameters.moduleName; + } + + if (want.parameters.dimension) { + this.dimension = want.parameters.dimension; + } + + if (want.parameters.normal) { + this.normal = want.parameters.normal; + } + + if (want.parameters.temporary) { + this.temporary = want.parameters.temporary; + } + if (want.parameters.normaldel) { + this.normaldel = want.parameters.normaldel; + } + + if (want.parameters.temporarydel) { + this.temporarydel = want.parameters.temporarydel; + } + + if (want.parameters.deleteIds) { + this.deleteIds = want.parameters.deleteIds; + } + if (want.parameters.castFormId) { + this.castFormId = want.parameters.castFormId; + } + + this.makeCount(); + + setTimeout(() => { + this.optType = want.parameters.optType; + console.info(' [FormComponent] formsystemhostp getWant optType:' + this.optType); + }, 10); + + if (this.castFormId != "-1" && want.parameters.optType == 3) { + console.info("[FormComponent.host] castTempForm start"); + commonEvent.unsubscribe(this.subscriberDel, () => { + console.info("====> [FormComponent] formsystemhostp optType unSubscribeDeleteCallback CallBack====>"); + }); + commonEvent.unsubscribe(this.subscriberSendCastForm, () => { + console.info("====> [FormComponent] formsystemhostp optType unSubscribeCastFormCallback CallBack====>"); + }); + + formManager.castTempForm(this.castFormId) + .then((data) => { + console.info('[FormComponent] castTempForm result:' + data); + let commonEventPublishData = { + data: data || `0`, + bundleName: "com.ohos.st.formsystemhostp", + parameters: { + formId: this.castFormId.toString() + } + }; + commonEvent.publish(this.formCastEvent, commonEventPublishData, this.publishCastCallBack); + }) + .catch((error) => { + console.info('[FormComponent] castTempForm error:' + JSON.stringify(error)); + let commonEventPublishData = { + data: error.code.toString(), + bundleName: "com.ohos.st.formsystemhostp", + parameters: { + errMsg: error.message, + formId: this.castFormId.toString() + } + }; + commonEvent.publish(this.formCastEvent, commonEventPublishData, this.publishCastCallBack); + }); + console.info("[FormComponent.host] castTempForm end"); + } + + if (want.parameters.optType == 2 && this.deleteIds.length > 0) { + for (let iIndex = 0; iIndex < this.deleteIds.length; ++iIndex) { + console.info("[FormComponent] formsystemhostp deleteForm start"); + formManager.deleteForm(this.deleteIds[iIndex]) + .then((data) => { + console.info('[FormComponent] formsystemhostp deleteForm result:' + data); + this.delCount++; + + if (this.delCount == this.deleteIds.length) { + let commonEventPublishData = { + data: data.toString(), + bundleName: "com.ohos.st.formsystemhostp", + parameters: { + "formIds": this.deleteIds + } + }; + commonEvent.publish(this.formOnErrorEvent, commonEventPublishData, this.publishDeleteCallBack); + } + }) + .catch((error) => { + console.info(' [FormComponent] formsystemhostp deleteForm error:' + error); + let commonEventPublishData = { + data: error.code.toString(), + bundleName: "com.ohos.st.formsystemhostp", + parameters: { + "formIds": [this.deleteIds[iIndex]] + } + }; + commonEvent.publish(this.formOnErrorEvent, commonEventPublishData, this.publishOnErrorCallBack); + }); + console.info("[FormComponent] formsystemhostp deleteForm end"); + } + } + }) + .catch((error: any) => { + console.error(' [FormComponent] formsystemhostp Operation failed. Cause: ' + JSON.stringify(error)); + }) + console.info(`[FormComponent.host] aboutToAppear end`); + } + + private makeCount() { + console.info(' [FormComponent] formsystemhostp makeCount start.'); + for (let nNormal = 0; nNormal < this.normal; nNormal++) { + this.normalFormCounts.push(nNormal); + } + console.info(' [FormComponent] formsystemhostp this.normalFormCounts.length:' + this.normalFormCounts.length); + + for (let nTemp = 0; nTemp < this.temporary; nTemp++) { + this.tempFormCounts.push(nTemp); + } + console.info(' [FormComponent] formsystemhostp this.tempFormCounts.length:' + this.tempFormCounts.length); + } + + build() { + Scroll(new Scroller()) { + Column() { + if (this.optType == 1) { + Text(' [FormComponent] formsystemhostp normal form component test begin') + Grid() { + ForEach(this.normalFormCounts, (item) => { + GridItem() { + FormComponent({ + id: 0, + name: this.name, + bundle: this.bundle, + ability: this.ability, + module: this.moduleName, + dimension: this.dimension, + temporary: false + }) + .allowUpdate(this.allowUpate) + .visibility(this.isShowing ? Visibility.Visible : Visibility.Hidden) + .onAcquired((form) => { + console.info(" [FormComponent] formsystemhostp get normal form, form id:" + form.id); + + this.normalFormIds.push(form.id.toString()); + if (this.normalFormIds.length == this.normal - this.normaldel) { + let commonEventPublishData = { + data: "normalForm", + bundleName: "com.ohos.st.formsystemhostp", + parameters: { + "formIds": this.normalFormIds + } + }; + commonEvent.publish(this.formOnAcquiredEvent, commonEventPublishData, this.publishOnAcquiredCallBack); + } + }) + .onError((error) => { + console.info(" [FormComponent] formsystemhostp normal form error code:" + error.errcode); + console.info(" [FormComponent] formsystemhostp normal form error msg:" + error.msg); + let commonEventPublishData = { + data: error.msg, + bundleName: "com.ohos.st.formsystemhostp" + }; + commonEvent.publish(this.formOnErrorEvent, commonEventPublishData, this.publishOnErrorCallBack); + }) + .size({ width: 40, height: 40 }) + } + }, (item) => JSON.stringify(item)) + } + .columnsTemplate('1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr ') + .columnsGap(2) + .rowsGap(2) + .width('100%') + Text(' [FormComponent] formsystemhostp normal form component test end') + + Text(' [FormComponent] formsystemhostp temp form component test start') + Grid() { + ForEach(this.tempFormCounts, (item) => { + GridItem() { + FormComponent({ + id: 0, + name: this.name, + bundle: this.bundle, + ability: this.ability, + module: this.moduleName, + dimension: this.dimension, + temporary: true + }) + .allowUpdate(this.allowUpate) + .visibility(this.isShowing ? Visibility.Visible : Visibility.Hidden) + .onAcquired((form) => { + console.info(" [FormComponent] formsystemhostp get temp form, form id:" + form.id); + this.tempFormIds.push(form.id.toString()); + if (this.tempFormIds.length == this.temporary - this.temporarydel) { + let commonEventPublishData = { + data: "tempForm", + bundleName: "com.ohos.st.formsystemhostp", + parameters: { + "formIds": this.tempFormIds + } + }; + commonEvent.publish(this.formOnAcquiredEvent, commonEventPublishData, this.publishOnAcquiredCallBack); + } + }) + .onError((error) => { + console.info(" [FormComponent] formsystemhostp temp form error code:" + error.errcode); + console.info(" [FormComponent] formsystemhostp temp form error msg:" + error.msg); + let commonEventPublishData = { + data: error.msg, + bundleName: "com.ohos.st.formsystemhostp" + }; + commonEvent.publish(this.formOnErrorEvent, commonEventPublishData, this.publishOnErrorCallBack); + }) + .size({ width: 40, height: 40 }) + } + }, (item) => JSON.stringify(item)) + } + .columnsTemplate('1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr ') + .columnsGap(2) + .rowsGap(2) + .width('100%') + + Text(' [FormComponent] formsystemhostp temp form component test end') + } + } + .backgroundColor(Color.White) + } + .scrollable(ScrollDirection.Vertical) + .width('100%') + .height('100%') + } } \ No newline at end of file diff --git a/aafwk/aafwk_standard/formmanager/fa/formsystemtest_ets/formdeletetest/entry/src/main/ets/MainAbility/model/FormViewModel.ets b/aafwk/aafwk_standard/formmanager/fa/formsystemtest_ets/formdeletetest/entry/src/main/ets/MainAbility/model/FormViewModel.ets deleted file mode 100644 index 659108ce439cf2b927fdf1801539f3dddbd851d6..0000000000000000000000000000000000000000 --- a/aafwk/aafwk_standard/formmanager/fa/formsystemtest_ets/formdeletetest/entry/src/main/ets/MainAbility/model/FormViewModel.ets +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import formManager from '@ohos.ability.formmanager'; -import bundleManager from '@ohos.bundle'; - -export default class FormViewModel { - private static sFormViewModel: FormViewModel = null; - - public static getInstance(): FormViewModel { - if (FormViewModel.sFormViewModel == null) { - FormViewModel.sFormViewModel = new FormViewModel(); - } - return FormViewModel.sFormViewModel; - } - - public async requestForm(formId: string) { - formManager.requestForm(formId) - .then((data) => { - console.info( '[FormComponent] requestForm result:' + data); - }); - } - - public async deleteCard(formId: string) { - formManager.deleteForm(formId) - .then((data) => { - console.info('[FormComponent] deleteForm result:' + data); - }); - } - - public async releaseCard(formId: string) { - formManager.releaseForm(formId) - .then((data) => { - console.info('[FormComponent] releaseForm result:' + data); - }); - } - - public async castTempToNormal(formId: string) { - formManager.castTempForm(formId) - .then((data) => { - console.info('[FormComponent] castTempToNormal result:' + data); - }); - } - - public async enableCard(formId: string) { - formManager.enableFormsUpdate([formId]) - .then((data) => { - console.info('[FormComponent] enableFormsUpdate result:' + data); - }); - } - - public async disableCard(formId: string) { - formManager.disableFormsUpdate([formId]) - .then((data) => { - console.info('[FormComponent] disableCard result:' + data); - }); - } - - public async changeCardVisible(formId: string, isVisible: boolean) { - if (isVisible) { - formManager.notifyVisibleForms([formId]) - .then((data) => { - console.info('[FormComponent] changeCardVisible result:' + data + ', isVisible:' + isVisible); - }); - } else { - formManager.notifyInvisibleForms([formId]) - .then((data) => { - console.info('[FormComponent] changeCardVisible result:' + data + ', isVisible:' + isVisible); - }); - } - } - - public async isFmsReady() { - formManager.isSystemReady() - .then((data) => { - console.info('[FormComponent] isFmsReady result:' + data); - }); - } - - public async getAllFormsInfo() { - console.info("[FormComponent] getAllFormsInfo start"); - formManager.getAllFormsInfo() - .then((data) => { - console.info('[FormComponent] getAllFormsInfo result:' + JSON.stringify(data)); - }) - .catch((err) => { - console.info('[FormComponent] getAllFormsInfo error:' + JSON.stringify(err)); - }); - console.info("[FormComponent] getAllFormsInfo end"); - } - - public async getFormsInfoByApp(bundle: string) { - formManager.getFormsInfo(bundle) - .then((data) => { - console.info('[FormComponent] getFormsInfoByApp result:' + JSON.stringify(data)); - }); - } - - public async getFormsInfoByModule(bundle: string, moduleName: string) { - formManager.getFormsInfo(bundle, moduleName) - .then((data) => { - console.info('[FormComponent] getFormsInfoByModule result:' + JSON.stringify(data)); - }); - } - - public async clearFormUserCache() { - bundleManager.cleanBundleCacheFiles('com.ohos.myapplicationform') - .then((data) => { - console.info('[FormComponent] cleanBundleCacheFiles result:' + JSON.stringify(data)); - }); - } - - public async clearFormProviderCache(bundle: string) { - bundleManager.cleanBundleCacheFiles(bundle) - .then((data) => { - console.info('[FormComponent] cleanBundleCacheFiles result:' + JSON.stringify(data)); - }); - } -} \ No newline at end of file diff --git a/aafwk/aafwk_standard/formmanager/fa/formsystemtest_ets/formdeletetest/entry/src/main/ets/MainAbility/test/FmsDeleteForm.test.ets b/aafwk/aafwk_standard/formmanager/fa/formsystemtest_ets/formdeletetest/entry/src/main/ets/MainAbility/test/FmsDeleteForm.test.ets index 77252ade397e4a2c3addb1f6576b5285ffdaec28..988882982a25672d22398f92393cf68e5ad63eb7 100644 --- a/aafwk/aafwk_standard/formmanager/fa/formsystemtest_ets/formdeletetest/entry/src/main/ets/MainAbility/test/FmsDeleteForm.test.ets +++ b/aafwk/aafwk_standard/formmanager/fa/formsystemtest_ets/formdeletetest/entry/src/main/ets/MainAbility/test/FmsDeleteForm.test.ets @@ -13,69 +13,41 @@ * limitations under the License. */ -import featureAbility from "@ohos.ability.featureAbility"; +import featureAbility from '@ohos.ability.featureAbility'; import commonEvent from '@ohos.commonEvent'; import { setTime } from '@ohos.systemTime'; -import { beforeAll, describe, expect, it } from "deccjsunit/index.ets"; +import { beforeEach, describe, expect, it } from 'deccjsunit/index.ets'; -var onErrorForm_Event = { - events: ["FMS_FormOnError_commonEvent"], -}; -var onAcquiredForm_Event = { +const onAcquiredForm_Event = { events: ["FMS_FormOnAcquired_commonEvent"], }; - -var onDetetedFormEvent = { +const onDeletedFormEvent = { events: ["FMS_FormOnDeleted_commonEvent"], }; -var onReleasedFormEvent = { +const onReleasedFormEvent = { events: ["FMS_FormOnReleased_commonEvent"], }; - -var onSupplyEvent = { +const onSupplyEvent = { events: ["FMS_FormSupply_commonEvent"], }; -var deleteForm_Event = "FMS_FormDelete_commonEvent"; +const deleteForm_Event = "FMS_FormDelete_commonEvent"; + +let subscriberOnAcquired; +let subscriberOnReleased; +let subscriberOnDeleted; +let subscriberSupply; export default function test() { describe(`FmsDeleteFormTest`, () => { - beforeAll(async (done) => { - done(); - }) - - /** - * Set time - * - * @param hour hour of 24H clock - * @param min minute - * @param second second - */ - const changeTime = async (hour, min, second) => { - console.info(`FMS_deleteForm changeTime start`); - const datetime = new Date(); - const year = datetime.getFullYear(); - const month = datetime.getMonth() + 1; - const day = datetime.getDate(); - const formatTime = year + '-' + fill(month) + '-' + fill(day) - + 'T' + fill(hour) + ':' + fill(min) + ':' + fill(second); - const s = (new Date(formatTime)).getTime(); - console.log(`FMS_deleteForm changeTime formatTime: ${formatTime}`); - console.log(`FMS_deleteForm changeTime s: ${s}`); - - try { - await setTime(s); - console.log(`FMS_deleteForm set time success: ${formatTime}`); - } catch (error) { - console.log(`FMS_deleteForm set time failure: ${error}`); - } - console.info(`FMS_deleteForm changeTime end`); - } - - const fill = value => { - return (value > 9 ? "" : "0") + value; - } + beforeEach(async () => { + subscriberOnAcquired = await commonEvent.createSubscriber(onAcquiredForm_Event); + subscriberOnReleased = await commonEvent.createSubscriber(onReleasedFormEvent); + subscriberOnDeleted = await commonEvent.createSubscriber(onDeletedFormEvent); + subscriberSupply = await commonEvent.createSubscriber(onSupplyEvent); + await sleep(1000); + }); /** * @tc.number: FMS_deleteForm_0200 @@ -84,721 +56,590 @@ export default function test() { * 2.Verify the result is false */ it(`FMS_deleteForm_0200`, 0, async (done) => { - console.log(`FMS_deleteForm_0200 start`); - let subscriberOnDeleted; - let subscriberOnAcquired; + const tcNumber = `FMS_deleteForm_0200`; let formId; - function delPublishCallBack() { - console.info("!!!====>FMS_deleteForm_0200 delPublishCallBack====>"); - setTimeout(function () { - console.info('FMS_deleteForm_0200 delPublishCallBack end'); - console.log(`FMS_deleteForm_0200 end`); - done(); - }, 1000) - } - - function onDeletedCallBack(err, data) { - console.info("!!!====>FMS_deleteForm_0200 onDeletedCallBack data:====>" + JSON.stringify(data)); - expect(data.event).assertEqual("FMS_FormOnDeleted_commonEvent"); + const onDeletedCallback = async (_, data) => { + console.info(`${tcNumber} onDeletedCallback data: ${JSON.stringify(data)}`); + expect(data.event).assertEqual(`FMS_FormOnDeleted_commonEvent`); expect(data.data != "0").assertEqual(true); - commonEvent.unsubscribe(subscriberOnDeleted, unSubscribeOnDetetedCallback); - let commonEventPublishData = { + commonEvent.unsubscribe(subscriberOnDeleted, () => unsubscribeOnDeletedCallback(tcNumber)); + const commonEventPublishData = { data: formId }; - commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallBack); - } - function unSubscribeOnDetetedCallback() { - console.debug("====>FMS_deleteForm_0200 unSubscribeOnDetetedCallback====>"); - } - - function onAcquiredCallBack(err, data) { - console.info("!!!====>FMS_deleteForm_0200 onAcquiredCallBack data:====>" + JSON.stringify(data)); - expect(data.event).assertEqual("FMS_FormOnAcquired_commonEvent"); - commonEvent.unsubscribe(subscriberOnAcquired, unSubscribeOnAcquiredCallback) + commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallback(tcNumber, done)); + }; + commonEvent.subscribe(subscriberOnDeleted, onDeletedCallback); + + const onAcquiredCallback = async (_, data) => { + console.info(`${tcNumber} onAcquiredCallback data: ${JSON.stringify(data)}`); + expect(data.event).assertEqual(`FMS_FormOnAcquired_commonEvent`); + commonEvent.unsubscribe(subscriberOnAcquired, () => unsubscribeOnAcquiredCallback(tcNumber)); formId = data.data; - commonEvent.createSubscriber(onDetetedFormEvent).then(async (data) => { - console.debug("====>FMS_deleteForm_0200 onDetetedFormEvent Subscriber====>"); - subscriberOnDeleted = data; - await commonEvent.subscribe(subscriberOnDeleted, onDeletedCallBack); - }); - console.log(`FMS_deleteForm_0200 featureAbility.startAbility again start`); - featureAbility.startAbility({ + console.info(`${tcNumber} featureAbility.startAbility again start`); + await featureAbility.startAbility({ want: { bundleName: "com.ohos.st.formsystemhostnoperm", abilityName: "com.ohos.st.formsystemhostnoperm.MainAbility", parameters: { - "formId" : "0", - "name" : "Form_Js001", - "bundle" : "com.form.formsystemtestservicea.hmservice", - "ability" : "com.form.formsystemtestservicea.hmservice.FormAbility", - "moduleName" : "entry", - "temporary" : false, - "deleteForm" : true, - "deleteId" : formId, - "isCreate" : false + formId: "0", + name: "Form_Js001", + bundle: "com.form.formsystemtestservicea.hmservice", + ability: "com.form.formsystemtestservicea.hmservice.FormAbility", + moduleName: "entry", + temporary: false, + deleteForm: true, + deleteId: formId, + isCreate: false } } }).then((res: any) => { - console.log(`FMS_deleteForm_0200 featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); }).catch((err: any) => { - console.log(`FMS_deleteForm_0200 featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); }); - console.log(`FMS_deleteForm_0200 featureAbility.startAbility again end`); - } - function unSubscribeOnAcquiredCallback() { - console.debug("====>FMS_deleteForm_0200 OnAcquired UnSubscribe CallBack====>"); - } - - commonEvent.createSubscriber(onAcquiredForm_Event).then(async (data) => { - console.debug("====>FMS_deleteForm_0200 Create OnAcquired Subscriber====>"); - subscriberOnAcquired = data; - await commonEvent.subscribe(subscriberOnAcquired, onAcquiredCallBack); - }); - console.log(`FMS_deleteForm_0200 featureAbility.startAbility start`); + console.info(`${tcNumber} featureAbility.startAbility again end`); + }; + commonEvent.subscribe(subscriberOnAcquired, onAcquiredCallback); + + console.info(`${tcNumber} featureAbility.startAbility start`); await featureAbility.startAbility({ want: { bundleName: "com.ohos.st.formsystemhostc", abilityName: "com.ohos.st.formsystemhostc.MainAbility", parameters: { - "formId" : "0", - "name" : "Form_Js001", - "bundle" : "com.form.formsystemtestservicea.hmservice", - "ability" : "com.form.formsystemtestservicea.hmservice.FormAbility", - "moduleName" : "entry", - "temporary" : false, - "isCreate" : true + formId: "0", + name: "Form_Js001", + bundle: "com.form.formsystemtestservicea.hmservice", + ability: "com.form.formsystemtestservicea.hmservice.FormAbility", + moduleName: "entry", + temporary: false, + isCreate: true } } }).then((res: any) => { - console.log(`FMS_deleteForm_0200 featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); }).catch((err: any) => { - console.log(`FMS_deleteForm_0200 featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); }); - console.log(`FMS_deleteForm_0200 featureAbility.startAbility end`); + console.info(`${tcNumber} featureAbility.startAbility end`); }); + /** - * @tc.number: FMS_deleteForm_0300 - * @tc.name: formID id is error(formID < 0) - * @tc.desc: 1.delete the form - * 2.Verify the result is false - */ + * @tc.number: FMS_deleteForm_0300 + * @tc.name: formID id is error(formID < 0) + * @tc.desc: 1.delete the form + * 2.Verify the result is false + */ it(`FMS_deleteForm_0300`, 0, async (done) => { - console.log(`FMS_deleteForm_0300 start`); - let subscriberOnDeleted; - let subscriberOnAcquired; - - function delPublishCallBack() { - console.info("!!!====>FMS_deleteForm_0300 delPublishCallBack====>"); - setTimeout(function () { - console.info('FMS_deleteForm_0300 delPublishCallBack end'); - console.log(`FMS_deleteForm_0300 end`); - done(); - }, 1000) - } + const tcNumber = `FMS_deleteForm_0300`; - function onDeletedCallBack(err, data) { - console.info("!!!====>FMS_deleteForm_0300 onDeletedCallBack data:====>" + JSON.stringify(data)); - expect(data.event).assertEqual("FMS_FormOnDeleted_commonEvent"); + const onDeletedCallback = async (_, data) => { + console.info(`${tcNumber} onDeletedCallback data: ${JSON.stringify(data)}`); + expect(data.event).assertEqual(`FMS_FormOnDeleted_commonEvent`); expect(data.data != "0").assertEqual(true); - commonEvent.unsubscribe(subscriberOnDeleted, unSubscribeOnDetetedCallback); - let commonEventPublishData = { + commonEvent.unsubscribe(subscriberOnDeleted, () => unsubscribeOnDeletedCallback(tcNumber)); + const commonEventPublishData = { data: data.parameters.formId }; - commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallBack); - } - function unSubscribeOnDetetedCallback() { - console.debug("====>FMS_deleteForm_0300 unSubscribeOnDetetedCallback CallBack====>"); - } - commonEvent.createSubscriber(onDetetedFormEvent).then(async (data) => { - console.debug("====>FMS_deleteForm_0300 onDetetedFormEvent Subscriber====>"); - subscriberOnDeleted = data; - await commonEvent.subscribe(subscriberOnDeleted, onDeletedCallBack); - }); + commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallback(tcNumber, done)); + }; + commonEvent.subscribe(subscriberOnDeleted, onDeletedCallback); - console.log(`FMS_deleteForm_0300 featureAbility.startAbility start`); + console.info(`${tcNumber} featureAbility.startAbility start`); await featureAbility.startAbility({ want: { bundleName: "com.ohos.st.formsystemhostc", abilityName: "com.ohos.st.formsystemhostc.MainAbility", parameters: { - "formId" : "0", - "name" : "Form_Js001", - "bundle" : "com.form.formsystemtestservicea.hmservice", - "ability" : "com.form.formsystemtestservicea.hmservice.FormAbility", - "moduleName" : "entry", - "temporary" : false, - "deleteForm" : true, - "deleteId" : "-1", - "isCreate" : true + formId: "0", + name: "Form_Js001", + bundle: "com.form.formsystemtestservicea.hmservice", + ability: "com.form.formsystemtestservicea.hmservice.FormAbility", + moduleName: "entry", + temporary: false, + deleteForm: true, + deleteId: "-1", + isCreate: true } } }).then((res: any) => { - console.log(`FMS_deleteForm_0300 featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); }).catch((err: any) => { - console.log(`FMS_deleteForm_0300 featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); }); - console.log(`FMS_deleteForm_0300 featureAbility.startAbility end`); + console.info(`${tcNumber} featureAbility.startAbility end`); }); + /** - * @tc.number: FMS_deleteForm_0400 - * @tc.name: formID id is error(formID = 0) - * @tc.desc: 1.delete the form - * 2.Verify the result is false - */ + * @tc.number: FMS_deleteForm_0400 + * @tc.name: formID id is error(formID = 0) + * @tc.desc: 1.delete the form + * 2.Verify the result is false + */ it(`FMS_deleteForm_0400`, 0, async (done) => { - console.log(`FMS_deleteForm_0400 start`); - let subscriberOnDeleted; - let subscriberOnAcquired; - - function delPublishCallBack() { - console.info("!!!====>FMS_deleteForm_0400 delPublishCallBack====>"); - setTimeout(function () { - console.info('FMS_deleteForm_0400 delPublishCallBack end'); - console.log(`FMS_deleteForm_0400 end`); - done(); - }, 1000) - } + const tcNumber = `FMS_deleteForm_0400`; - function onDeletedCallBack(err, data) { - console.info("!!!====>FMS_deleteForm_0400 onDeletedCallBack data:====>" + JSON.stringify(data)); - expect(data.event).assertEqual("FMS_FormOnDeleted_commonEvent"); + const onDeletedCallback = async (_, data) => { + console.info(`${tcNumber} onDeletedCallback data: ${JSON.stringify(data)}`); + expect(data.event).assertEqual(`FMS_FormOnDeleted_commonEvent`); expect(data.data != "0").assertEqual(true); - commonEvent.unsubscribe(subscriberOnDeleted, unSubscribeOnDetetedCallback); - let commonEventPublishData = { + commonEvent.unsubscribe(subscriberOnDeleted, () => unsubscribeOnDeletedCallback(tcNumber)); + const commonEventPublishData = { data: data.parameters.formId }; - commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallBack); - } - function unSubscribeOnDetetedCallback() { - console.debug("====>FMS_deleteForm_0400 unSubscribeOnDetetedCallback CallBack====>"); - } - commonEvent.createSubscriber(onDetetedFormEvent).then(async (data) => { - console.debug("====>FMS_deleteForm_0400 onDetetedFormEvent Subscriber====>"); - subscriberOnDeleted = data; - await commonEvent.subscribe(subscriberOnDeleted, onDeletedCallBack); - }); + commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallback(tcNumber, done)); + }; + commonEvent.subscribe(subscriberOnDeleted, onDeletedCallback); - console.log(`FMS_deleteForm_0400 featureAbility.startAbility start`); + console.info(`${tcNumber} featureAbility.startAbility start`); await featureAbility.startAbility({ want: { bundleName: "com.ohos.st.formsystemhostc", abilityName: "com.ohos.st.formsystemhostc.MainAbility", parameters: { - "formId" : "0", - "name" : "Form_Js001", - "bundle" : "com.form.formsystemtestservicea.hmservice", - "ability" : "com.form.formsystemtestservicea.hmservice.FormAbility", - "moduleName" : "entry", - "temporary" : false, - "deleteForm" : true, - "deleteId" : "0", - "isCreate" : true + formId: "0", + name: "Form_Js001", + bundle: "com.form.formsystemtestservicea.hmservice", + ability: "com.form.formsystemtestservicea.hmservice.FormAbility", + moduleName: "entry", + temporary: false, + deleteForm: true, + deleteId: "0", + isCreate: true } } }).then((res: any) => { - console.log(`FMS_deleteForm_0400 featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); }).catch((err: any) => { - console.log(`FMS_deleteForm_0400 featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); }); - console.log(`FMS_deleteForm_0400 featureAbility.startAbility end`); + console.info(`${tcNumber} featureAbility.startAbility end`); }); + /** - * @tc.number: FMS_deleteForm_0500 - * @tc.name: formID id is error because formId is not self - * @tc.desc: 1.host A create a formA - * 2.host B delete the formA - * 2.Verify the result is false - */ + * @tc.number: FMS_deleteForm_0500 + * @tc.name: formID id is error because formId is not self + * @tc.desc: 1.host A create a formA + * 2.host B delete the formA + * 2.Verify the result is false + */ it(`FMS_deleteForm_0500`, 0, async (done) => { - console.log(`FMS_deleteForm_0500 start`); - let subscriberOnDeleted; - let subscriberOnAcquired; + const tcNumber = `FMS_deleteForm_0500`; let formId; - function delPublishCallBack() { - console.info("!!!====>FMS_deleteForm_0500 delPublishCallBack====>"); - setTimeout(function () { - console.info('FMS_deleteForm_0500 delPublishCallBack end'); - console.log(`FMS_deleteForm_0500 end`); - done(); - }, 1000) - } - - function onDeletedCallBack(err, data) { - console.info("!!!====>FMS_deleteForm_0500 onDeletedCallBack data:====>" + JSON.stringify(data)); - expect(data.event).assertEqual("FMS_FormOnDeleted_commonEvent"); + const onDeletedCallback = async (_, data) => { + console.info(`${tcNumber} onDeletedCallback data: ${JSON.stringify(data)}`); + expect(data.event).assertEqual(`FMS_FormOnDeleted_commonEvent`); expect(data.data != "0").assertEqual(true); - commonEvent.unsubscribe(subscriberOnDeleted, unSubscribeOnDetetedCallback); - let commonEventPublishData = { + commonEvent.unsubscribe(subscriberOnDeleted, () => unsubscribeOnDeletedCallback(tcNumber)); + const commonEventPublishData = { data: formId }; - commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallBack); - } - function unSubscribeOnDetetedCallback() { - console.debug("====>FMS_deleteForm_0500 unSubscribeOnDetetedCallback CallBack====>"); - } - - function onAcquiredCallBack(err, data) { - console.info("!!!====>FMS_deleteForm_0500 onAcquiredCallBack data:====>" + JSON.stringify(data)); - expect(data.event).assertEqual("FMS_FormOnAcquired_commonEvent"); - commonEvent.unsubscribe(subscriberOnAcquired, unSubscribeOnAcquiredCallback) + commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallback(tcNumber, done)); + }; + commonEvent.subscribe(subscriberOnDeleted, onDeletedCallback); + + const onAcquiredCallback = async (_, data) => { + console.info(`${tcNumber} onAcquiredCallback data: ${JSON.stringify(data)}`); + expect(data.event).assertEqual(`FMS_FormOnAcquired_commonEvent`); + commonEvent.unsubscribe(subscriberOnAcquired, () => unsubscribeOnAcquiredCallback(tcNumber)); formId = data.data; - commonEvent.createSubscriber(onDetetedFormEvent).then(async (data) => { - console.debug("====>FMS_deleteForm_0500 onDetetedFormEvent Subscriber====>"); - subscriberOnDeleted = data; - await commonEvent.subscribe(subscriberOnDeleted, onDeletedCallBack); - }); - console.log(`FMS_deleteForm_0500 featureAbility.startAbility again start`); - featureAbility.startAbility({ + console.info(`${tcNumber} featureAbility.startAbility again start`); + await featureAbility.startAbility({ want: { bundleName: "com.ohos.st.formsystemhostd", abilityName: "com.ohos.st.formsystemhostd.MainAbility", parameters: { - "formId" : "0", - "name" : "Form_Js001", - "bundle" : "com.form.formsystemtestservicea.hmservice", - "ability" : "com.form.formsystemtestservicea.hmservice.FormAbility", - "moduleName" : "entry", - "temporary" : false, - "deleteForm" : true, - "deleteId" : formId, - "isCreate" : false + formId: "0", + name: "Form_Js001", + bundle: "com.form.formsystemtestservicea.hmservice", + ability: "com.form.formsystemtestservicea.hmservice.FormAbility", + moduleName: "entry", + temporary: false, + deleteForm: true, + deleteId: formId, + isCreate: false } } }).then((res: any) => { - console.log(`FMS_deleteForm_0500 featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); }).catch((err: any) => { - console.log(`FMS_deleteForm_0500 featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); }); - console.log(`FMS_deleteForm_0500 featureAbility.startAbility again end`); - } - function unSubscribeOnAcquiredCallback() { - console.debug("====>FMS_deleteForm_0500 OnAcquired UnSubscribe CallBack====>"); - } - - commonEvent.createSubscriber(onAcquiredForm_Event).then(async (data) => { - console.debug("====>FMS_deleteForm_0500 Create OnAcquired Subscriber====>"); - subscriberOnAcquired = data; - await commonEvent.subscribe(subscriberOnAcquired, onAcquiredCallBack); - }); - console.log(`FMS_deleteForm_0500 featureAbility.startAbility start`); + console.info(`${tcNumber} featureAbility.startAbility again end`); + }; + commonEvent.subscribe(subscriberOnAcquired, onAcquiredCallback); + + console.info(`${tcNumber} featureAbility.startAbility start`); await featureAbility.startAbility({ want: { bundleName: "com.ohos.st.formsystemhostc", abilityName: "com.ohos.st.formsystemhostc.MainAbility", parameters: { - "formId" : "0", - "name" : "Form_Js001", - "bundle" : "com.form.formsystemtestservicea.hmservice", - "ability" : "com.form.formsystemtestservicea.hmservice.FormAbility", - "moduleName" : "entry", - "temporary" : false, - "isCreate" : true + formId: "0", + name: "Form_Js001", + bundle: "com.form.formsystemtestservicea.hmservice", + ability: "com.form.formsystemtestservicea.hmservice.FormAbility", + moduleName: "entry", + temporary: false, + isCreate: true } } }).then((res: any) => { - console.log(`FMS_deleteForm_0500 featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); }).catch((err: any) => { - console.log(`FMS_deleteForm_0500 featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); }); - console.log(`FMS_deleteForm_0500 featureAbility.startAbility end`); + console.info(`${tcNumber} featureAbility.startAbility end`); }); + /** - * @tc.number: FMS_deleteForm_0600 - * @tc.name: Delete a normal form and the form reference is not 0 after deletion - * @tc.desc: 1.host A create a normal formA - * 2.host B create a form with formA's ID - * 3.delete formA, and verify the result is true - */ + * @tc.number: FMS_deleteForm_0600 + * @tc.name: Delete a normal form and the form reference is not 0 after deletion + * @tc.desc: 1.host A create a normal formA + * 2.host B create a form with formA's ID + * 3.delete formA, and verify the result is true + */ it(`FMS_deleteForm_0600`, 0, async (done) => { - console.log(`FMS_deleteForm_0600 start`); - let subscriberOnDeleted; - let subscriberOnAcquired; + const tcNumber = `FMS_deleteForm_0600`; let formId; - let subscriberSupply; let supplyFlag = false; - function delPublishCallBack() { - console.info("!!!====>FMS_deleteForm_0600 delPublishCallBack====>"); - setTimeout(function () { - commonEvent.unsubscribe(subscriberSupply, unSubscribeSupplyCallback); - if(supplyFlag) { - deleteFormB(); - expect().assertFail(); - } else { - deleteFormB(); - } - console.info('FMS_deleteForm_0600 delPublishCallBack end'); - }, 1000) + async function delPublishCallback() { + console.info(`${tcNumber} delPublishCallback`); + await sleep(1000); + commonEvent.unsubscribe(subscriberSupply, () => unsubscribeSupplyCallback(tcNumber)); + if (supplyFlag) { + deleteFormB(); + expect().assertFail(); + } else { + deleteFormB(); + } + console.info(`${tcNumber} delPublishCallback end`); } - function delPublishCallBackB() { - console.info("!!!====>FMS_deleteForm_0600 delPublishCallBackB====>"); - setTimeout(function () { - console.info('FMS_deleteForm_0600 delPublishCallBackB end'); - console.log(`FMS_deleteForm_0600 end`); - done(); - }, 500); + async function delPublishCallbackB() { + console.info(`${tcNumber} delPublishCallbackB`); + await sleep(500); + console.info(`${tcNumber} delPublishCallbackB end`); + console.info(`${tcNumber} end`); + done(); } function deleteFormB() { - console.info("!!!====>FMS_deleteForm_0600 deleteFormB start====>"); - let commonEventPublishData = { + console.info(`${tcNumber} deleteFormB start`); + const commonEventPublishData = { bundleName: "com.ohos.st.formsystemhostd", data: formId }; - commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallBackB); - console.info("!!!====>FMS_deleteForm_0600 deleteFormB end====>"); + commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallbackB); + console.info(`${tcNumber} deleteFormB end`); } - function onAcquiredCallBackB(err, data) { - console.info("!!!====>FMS_deleteForm_0600 onAcquiredCallBackB data:====>" + JSON.stringify(data)); - expect(data.event).assertEqual("FMS_FormOnAcquired_commonEvent"); + + const onAcquiredCallbackB = async (_, data) => { + console.info(`${tcNumber} onAcquiredCallbackB data: ${JSON.stringify(data)}`); + expect(data.event).assertEqual(`FMS_FormOnAcquired_commonEvent`); expect(data.data).assertEqual(formId); - commonEvent.unsubscribe(subscriberOnAcquired, unSubscribeOnDetetedCallback); - let commonEventPublishData = { + commonEvent.unsubscribe(subscriberOnAcquired, () => unsubscribeOnAcquiredCallback(tcNumber)); + const commonEventPublishData = { bundleName: "com.ohos.st.formsystemhostc", data: formId }; - commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallBack); - } - function unSubscribeOnDetetedCallback() { - console.debug("====>FMS_deleteForm_0600 unSubscribeOnDetetedCallback CallBack====>"); - } - - function onAcquiredCallBack(err, data) { - console.info("!!!====>FMS_deleteForm_0600 onAcquiredCallBack data:====>" + JSON.stringify(data)); - expect(data.event).assertEqual("FMS_FormOnAcquired_commonEvent"); - commonEvent.unsubscribe(subscriberOnAcquired, unSubscribeOnAcquiredCallback) + commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallback); + }; + + const onAcquiredCallback = async (_, data) => { + console.info(`${tcNumber} onAcquiredCallback data: ${JSON.stringify(data)}`); + expect(data.event).assertEqual(`FMS_FormOnAcquired_commonEvent`); + commonEvent.unsubscribe(subscriberOnAcquired, () => unsubscribeOnAcquiredCallback(tcNumber)); formId = data.data; - commonEvent.createSubscriber(onAcquiredForm_Event).then(async (data) => { - console.debug("====>FMS_deleteForm_0600 B onAcquiredForm_Event Subscriber====>"); - subscriberOnAcquired = data; - await commonEvent.subscribe(subscriberOnAcquired, onAcquiredCallBackB); - }); + subscriberOnAcquired = await commonEvent.createSubscriber(onAcquiredForm_Event); + await sleep(1000); + commonEvent.subscribe(subscriberOnAcquired, onAcquiredCallbackB); - console.log(`FMS_deleteForm_0600 featureAbility.startAbility again start`); - featureAbility.startAbility({ + console.info(`${tcNumber} featureAbility.startAbility again start`); + await featureAbility.startAbility({ want: { bundleName: "com.ohos.st.formsystemhostd", abilityName: "com.ohos.st.formsystemhostd.MainAbility", parameters: { - "formId" : formId, - "name" : "Form_Js001", - "bundle" : "com.form.formsystemtestservicea.hmservice", - "ability" : "com.form.formsystemtestservicea.hmservice.FormAbility", - "moduleName" : "entry", - "temporary" : false, - "isCreate" : true + formId: formId, + name: "Form_Js001", + bundle: "com.form.formsystemtestservicea.hmservice", + ability: "com.form.formsystemtestservicea.hmservice.FormAbility", + moduleName: "entry", + temporary: false, + isCreate: true } } }).then((res: any) => { - console.log(`FMS_deleteForm_0600 featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); }).catch((err: any) => { - console.log(`FMS_deleteForm_0600 featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); }); - console.log(`FMS_deleteForm_0600 featureAbility.startAbility again end`); - } - function unSubscribeOnAcquiredCallback() { - console.debug("====>FMS_deleteForm_0600 OnAcquired UnSubscribe CallBack====>"); - } - function onSupplyCallBack(err, data) { - if(data.parameters.kind == "onDestroy") { - console.debug("====>FMS_deleteForm_0600 onSupplyCallBack====>" + JSON.stringify(data)); + console.info(`${tcNumber} featureAbility.startAbility again end`); + }; + commonEvent.subscribe(subscriberOnAcquired, onAcquiredCallback); + + const onSupplyCallback = async (_, data) => { + if (data.parameters.kind == "onDestroy") { + console.info(`${tcNumber} onSupplyCallback ${JSON.stringify(data)}`); supplyFlag = true; } - } - function unSubscribeSupplyCallback() { - console.debug("====>FMS_deleteForm_0600 unSubscribeSupplyCallback====>"); - } - commonEvent.createSubscriber(onAcquiredForm_Event).then(async (data) => { - console.debug("====>FMS_deleteForm_0600 Create OnAcquired Subscriber====>"); - subscriberOnAcquired = data; - await commonEvent.subscribe(subscriberOnAcquired, onAcquiredCallBack); - }); - commonEvent.createSubscriber(onSupplyEvent).then(async (data) => { - console.debug("====>FMS_deleteForm_0600 onSupplyEvent Subscriber====>"); - subscriberSupply = data; - await commonEvent.subscribe(subscriberSupply, onSupplyCallBack); - }); - console.log(`FMS_deleteForm_0600 featureAbility.startAbility start`); + }; + commonEvent.subscribe(subscriberSupply, onSupplyCallback); + + console.info(`${tcNumber} featureAbility.startAbility start`); await featureAbility.startAbility({ want: { bundleName: "com.ohos.st.formsystemhostc", abilityName: "com.ohos.st.formsystemhostc.MainAbility", parameters: { - "formId" : "0", - "name" : "Form_Js001", - "bundle" : "com.form.formsystemtestservicea.hmservice", - "ability" : "com.form.formsystemtestservicea.hmservice.FormAbility", - "moduleName" : "entry", - "temporary" : false, - "isCreate" : true + formId: "0", + name: "Form_Js001", + bundle: "com.form.formsystemtestservicea.hmservice", + ability: "com.form.formsystemtestservicea.hmservice.FormAbility", + moduleName: "entry", + temporary: false, + isCreate: true } } }).then((res: any) => { - console.log(`FMS_deleteForm_0600 featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); }).catch((err: any) => { - console.log(`FMS_deleteForm_0600 featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); }); - console.log(`FMS_deleteForm_0600 featureAbility.startAbility end`); + console.info(`${tcNumber} featureAbility.startAbility end`); }); + /** - * @tc.number: FMS_deleteForm_0700 - * @tc.name: After deleting a normal form, the form reference is 0. - * After deleting a form, there are still created normal forms in FMS. - * @tc.desc: 1.host A an host B create one normal card respectively - * 2.host A delete the form and verify the result is true - */ + * @tc.number: FMS_deleteForm_0700 + * @tc.name: After deleting a normal form, the form reference is 0. + * After deleting a form, there are still created normal forms in FMS. + * @tc.desc: 1.host A an host B create one normal card respectively + * 2.host A delete the form and verify the result is true + */ it(`FMS_deleteForm_0700`, 0, async (done) => { - console.log(`FMS_deleteForm_0700 start`); - let subscriberOnDeleted; - let subscriberOnAcquired; + const tcNumber = `FMS_deleteForm_0700`; let formId; let formIdB; - let subscriberSupply; let supplyFlag = false; - function delPublishCallBack() { - console.info("!!!====>FMS_deleteForm_0700 delPublishCallBack====>"); - setTimeout(function () { - commonEvent.unsubscribe(subscriberSupply, unSubscribeSupplyCallback); - if(supplyFlag) { - deleteFormB(); - } else { - deleteFormB(); - expect().assertFail(); - } - console.info('FMS_deleteForm_0700 delPublishCallBack end'); - }, 1000) + async function delPublishCallback() { + console.info(`${tcNumber} delPublishCallback`); + await sleep(1000); + commonEvent.unsubscribe(subscriberSupply, () => unsubscribeSupplyCallback(tcNumber)); + if (supplyFlag) { + deleteFormB(); + } else { + deleteFormB(); + expect().assertFail(); + } + console.info(`${tcNumber} delPublishCallback end`); } - function delPublishCallBackB() { - console.info("!!!====>FMS_deleteForm_0700 delPublishCallBackB====>"); - setTimeout(function () { - console.info('FMS_deleteForm_0700 delPublishCallBackB end'); - console.log(`FMS_deleteForm_0700 end`); - done(); - }, 1000); + async function delPublishCallbackB() { + console.info(`${tcNumber} delPublishCallbackB`); + await sleep(1000); + console.info(`${tcNumber} delPublishCallbackB end`); + console.info(`${tcNumber} end`); + done(); } function deleteFormB() { - console.info("!!!====>FMS_deleteForm_0700 deleteFormB start====>"); - let commonEventPublishData = { + console.info(`${tcNumber} deleteFormB start`); + const commonEventPublishData = { bundleName: "com.ohos.st.formsystemhostd", data: formIdB }; - commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallBackB); - console.info("!!!====>FMS_deleteForm_0700 deleteFormB end====>"); + commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallbackB); + console.info(`${tcNumber} deleteFormB end`); } - function onAcquiredCallBackB(err, data) { - console.info("!!!====>FMS_deleteForm_0700 onAcquiredCallBackB data:====>" + JSON.stringify(data)); - expect(data.event).assertEqual("FMS_FormOnAcquired_commonEvent"); + + const onAcquiredCallbackB = async (_, data) => { + console.info(`${tcNumber} onAcquiredCallbackB data: ${JSON.stringify(data)}`); + expect(data.event).assertEqual(`FMS_FormOnAcquired_commonEvent`); formIdB = data.data; - commonEvent.unsubscribe(subscriberOnAcquired, unSubscribeOnDetetedCallback); - let commonEventPublishData = { + commonEvent.unsubscribe(subscriberOnAcquired, () => unsubscribeOnAcquiredCallback(tcNumber)); + const commonEventPublishData = { bundleName: "com.ohos.st.formsystemhostc", data: formId }; - commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallBack); - } - function unSubscribeOnDetetedCallback() { - console.debug("====>FMS_deleteForm_0700 unSubscribeOnDetetedCallback CallBack====>"); - } - - function onAcquiredCallBack(err, data) { - console.info("!!!====>FMS_deleteForm_0700 onAcquiredCallBack data:====>" + JSON.stringify(data)); - expect(data.event).assertEqual("FMS_FormOnAcquired_commonEvent"); - commonEvent.unsubscribe(subscriberOnAcquired, unSubscribeOnAcquiredCallback) + commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallback); + }; + + const onAcquiredCallback = async (_, data) => { + console.info(`${tcNumber} onAcquiredCallback data: ${JSON.stringify(data)}`); + expect(data.event).assertEqual(`FMS_FormOnAcquired_commonEvent`); + commonEvent.unsubscribe(subscriberOnAcquired, () => unsubscribeOnAcquiredCallback(tcNumber)); formId = data.data; - commonEvent.createSubscriber(onAcquiredForm_Event).then(async (data) => { - console.debug("====>FMS_deleteForm_0700 B onAcquiredForm_Event Subscriber====>"); - subscriberOnAcquired = data; - await commonEvent.subscribe(subscriberOnAcquired, onAcquiredCallBackB); - }); + subscriberOnAcquired = await commonEvent.createSubscriber(onAcquiredForm_Event); + await sleep(1000); + commonEvent.subscribe(subscriberOnAcquired, onAcquiredCallbackB); - console.log(`FMS_deleteForm_0700 featureAbility.startAbility again start`); - featureAbility.startAbility({ + console.info(`${tcNumber} featureAbility.startAbility again start`); + await featureAbility.startAbility({ want: { bundleName: "com.ohos.st.formsystemhostd", abilityName: "com.ohos.st.formsystemhostd.MainAbility", parameters: { - "formId" : "0", - "name" : "Form_Js001", - "bundle" : "com.form.formsystemtestservicea.hmservice", - "ability" : "com.form.formsystemtestservicea.hmservice.FormAbility", - "moduleName" : "entry", - "temporary" : false, - "isCreate" : true + formId: "0", + name: "Form_Js001", + bundle: "com.form.formsystemtestservicea.hmservice", + ability: "com.form.formsystemtestservicea.hmservice.FormAbility", + moduleName: "entry", + temporary: false, + isCreate: true } } }).then((res: any) => { - console.log(`FMS_deleteForm_0700 featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); }).catch((err: any) => { - console.log(`FMS_deleteForm_0700 featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); }); - console.log(`FMS_deleteForm_0700 featureAbility.startAbility again end`); - } - function unSubscribeOnAcquiredCallback() { - console.debug("====>FMS_deleteForm_0700 OnAcquired UnSubscribe CallBack====>"); - } - function onSupplyCallBack(err, data) { - if(data.parameters.kind == "onDestroy") { - console.debug("====>FMS_deleteForm_0700 onSupplyCallBack====>" + JSON.stringify(data)); + console.info(`${tcNumber} featureAbility.startAbility again end`); + }; + commonEvent.subscribe(subscriberOnAcquired, onAcquiredCallback); + + const onSupplyCallback = async (_, data) => { + if (data.parameters.kind == "onDestroy") { + console.info(`${tcNumber} onSupplyCallback ${JSON.stringify(data)}`); expect(data.parameters.parameters).assertEqual(formId); supplyFlag = true; } - } - function unSubscribeSupplyCallback() { - console.debug("====>FMS_deleteForm_0700 unSubscribeSupplyCallback====>"); - } - commonEvent.createSubscriber(onAcquiredForm_Event).then(async (data) => { - console.debug("====>FMS_deleteForm_0700 Create OnAcquired Subscriber====>"); - subscriberOnAcquired = data; - await commonEvent.subscribe(subscriberOnAcquired, onAcquiredCallBack); - }); - commonEvent.createSubscriber(onSupplyEvent).then(async (data) => { - console.debug("====>FMS_deleteForm_0700 onSupplyEvent Subscriber====>"); - subscriberSupply = data; - await commonEvent.subscribe(subscriberSupply, onSupplyCallBack); - }); - console.log(`FMS_deleteForm_0700 featureAbility.startAbility start`); + }; + commonEvent.subscribe(subscriberSupply, onSupplyCallback); + + console.info(`${tcNumber} featureAbility.startAbility start`); await featureAbility.startAbility({ want: { bundleName: "com.ohos.st.formsystemhostc", abilityName: "com.ohos.st.formsystemhostc.MainAbility", parameters: { - "formId" : "0", - "name" : "Form_Js001", - "bundle" : "com.form.formsystemtestservicea.hmservice", - "ability" : "com.form.formsystemtestservicea.hmservice.FormAbility", - "moduleName" : "entry", - "temporary" : false, - "isCreate" : true + formId: "0", + name: "Form_Js001", + bundle: "com.form.formsystemtestservicea.hmservice", + ability: "com.form.formsystemtestservicea.hmservice.FormAbility", + moduleName: "entry", + temporary: false, + isCreate: true } } }).then((res: any) => { - console.log(`FMS_deleteForm_0700 featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); }).catch((err: any) => { - console.log(`FMS_deleteForm_0700 featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); }); - console.log(`FMS_deleteForm_0700 featureAbility.startAbility end`); + console.info(`${tcNumber} featureAbility.startAbility end`); }); + /** - * @tc.number: FMS_deleteForm_0700_1 - * @tc.name: After deleting a normal form, the form reference is 0. - * After deleting a form, there are still created normal forms in FMS. - * @tc.desc: 1.host A an host B create one normal card respectively - * 2.host A delete the form and verify the result is true - */ + * @tc.number: FMS_deleteForm_0700_1 + * @tc.name: After deleting a normal form, the form reference is 0. + * After deleting a form, there are still created normal forms in FMS. + * @tc.desc: 1.host A an host B create one normal card respectively + * 2.host A delete the form and verify the result is true + */ it(`FMS_deleteForm_0700_1`, 0, async (done) => { - console.log(`FMS_deleteForm_0700_1 start`); - let subscriberOnAcquired; + const tcNumber = `FMS_deleteForm_0700_1`; let formId; let formIdB; - let subscriberSupply; let supplyFlag = false; let supplyFlagUpdate = false; // timer speed up commonEvent.publish(`fms.time_speed`, { code: 900 }, () => { - console.log(`FMS_deleteForm_0700_1 time speed up`); + console.info(`${tcNumber} time speed up`); }); await changeTime(10, 29, 55); - function delPublishCallBack() { - console.info("!!!====>FMS_deleteForm_0700_1 delPublishCallBack====>"); - setTimeout(function () { - commonEvent.unsubscribe(subscriberSupply, unSubscribeSupplyCallback); - if(supplyFlag && supplyFlagUpdate) { - deleteFormB(); - } else { - deleteFormB(); - expect().assertFail(); - } - console.info('FMS_deleteForm_0700_1 delPublishCallBack end'); - }, 5000) + + async function delPublishCallback() { + console.info(`${tcNumber} delPublishCallback`); + await sleep(5000); + commonEvent.unsubscribe(subscriberSupply, () => unsubscribeSupplyCallback(tcNumber)); + if (supplyFlag && supplyFlagUpdate) { + deleteFormB(); + } else { + deleteFormB(); + expect().assertFail(); + } + console.info(`${tcNumber} delPublishCallback end`); } - function delPublishCallBackB() { - console.info("!!!====>FMS_deleteForm_0700_1 delPublishCallBackB====>"); - setTimeout(function () { - console.info('FMS_deleteForm_0700_1 delPublishCallBackB end'); - console.log(`FMS_deleteForm_0700_1 end`); - done(); - }, 1000); + async function delPublishCallbackB() { + console.info(`${tcNumber} delPublishCallbackB`); + await sleep(1000); + console.info(`${tcNumber} delPublishCallbackB end`); + console.info(`${tcNumber} end`); + done(); } - function deleteFormB() { - console.info("!!!====>FMS_deleteForm_0700_1 deleteFormB start====>"); + async function deleteFormB() { + console.info(`${tcNumber} deleteFormB start`); // timer speed reset commonEvent.publish(`fms.time_speed`, { code: 1 }, () => { - console.log(`FMS_deleteForm_0700_1 time speed up`); + console.info(`${tcNumber} time speed up`); }); - setTimeout(function () { - let commonEventPublishData = { - bundleName: "com.ohos.st.formsystemhostc", - data: formIdB - }; - commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallBackB); - console.info("!!!====>FMS_deleteForm_0700_1 deleteFormB end====>"); - }, 1000) + await sleep(1000); + const commonEventPublishData = { + bundleName: "com.ohos.st.formsystemhostc", + data: formIdB + }; + commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallbackB); + console.info(`${tcNumber} deleteFormB end`); } - function onAcquiredCallBackB(err, data) { - console.info("!!!====>FMS_deleteForm_0700_1 onAcquiredCallBackB data:====>" + JSON.stringify(data)); - expect(data.event).assertEqual("FMS_FormOnAcquired_commonEvent"); + + const onAcquiredCallbackB = async (_, data) => { + console.info(`${tcNumber} onAcquiredCallbackB data: ${JSON.stringify(data)}`); + expect(data.event).assertEqual(`FMS_FormOnAcquired_commonEvent`); formIdB = data.data; - commonEvent.unsubscribe(subscriberOnAcquired, unSubscribeOnDetetedCallback); - let commonEventPublishData = { + commonEvent.unsubscribe(subscriberOnAcquired, () => unsubscribeOnAcquiredCallback(tcNumber)); + const commonEventPublishData = { bundleName: "com.ohos.st.formsystemhostd", data: formId }; - commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallBack); - } - function unSubscribeOnDetetedCallback() { - console.debug("====>FMS_deleteForm_0700_1 unSubscribeOnDetetedCallback CallBack====>"); - } - - async function onAcquiredCallBack(err, data) { - console.info("!!!====>FMS_deleteForm_0700_1 onAcquiredCallBack data:====>" + JSON.stringify(data)); - expect(data.event).assertEqual("FMS_FormOnAcquired_commonEvent"); - commonEvent.unsubscribe(subscriberOnAcquired, unSubscribeOnAcquiredCallback) + commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallback); + }; + + const onAcquiredCallback = async (_, data) => { + console.info(`${tcNumber} onAcquiredCallback data: ${JSON.stringify(data)}`); + expect(data.event).assertEqual(`FMS_FormOnAcquired_commonEvent`); + commonEvent.unsubscribe(subscriberOnAcquired, () => unsubscribeOnAcquiredCallback(tcNumber)); formId = data.data; - commonEvent.createSubscriber(onAcquiredForm_Event).then(async (data) => { - console.debug("====>FMS_deleteForm_0700_1 B onAcquiredForm_Event Subscriber====>"); - subscriberOnAcquired = data; - await commonEvent.subscribe(subscriberOnAcquired, onAcquiredCallBackB); - }); + subscriberOnAcquired = await commonEvent.createSubscriber(onAcquiredForm_Event); + await sleep(1000); + commonEvent.subscribe(subscriberOnAcquired, onAcquiredCallbackB); - console.log(`FMS_deleteForm_0700_1 featureAbility.startAbility again start`); + console.info(`${tcNumber} featureAbility.startAbility again start`); await featureAbility.startAbility({ want: { bundleName: "com.ohos.st.formsystemhostc", abilityName: "com.ohos.st.formsystemhostc.MainAbility", parameters: { - "formId" : "0", - "name" : "Form_Js001", - "bundle" : "com.form.formsystemtestservicea.hmservice", - "ability" : "com.form.formsystemtestservicea.hmservice.FormAbility", - "moduleName" : "entry", - "temporary" : false, - "isCreate" : true + formId: "0", + name: "Form_Js001", + bundle: "com.form.formsystemtestservicea.hmservice", + ability: "com.form.formsystemtestservicea.hmservice.FormAbility", + moduleName: "entry", + temporary: false, + isCreate: true } } }).then((res: any) => { - console.log(`FMS_deleteForm_0700_1 featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); }).catch((err: any) => { - console.log(`FMS_deleteForm_0700_1 featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); }); - console.log(`FMS_deleteForm_0700_1 featureAbility.startAbility again end`); - } - function unSubscribeOnAcquiredCallback() { - console.debug("====>FMS_deleteForm_0700_1 OnAcquired UnSubscribe CallBack====>"); - } - function onSupplyCallBack(err, data) { + console.info(`${tcNumber} featureAbility.startAbility again end`); + }; + commonEvent.subscribe(subscriberOnAcquired, onAcquiredCallback); + + const onSupplyCallback = async (_, data) => { if (data.parameters.kind == "onDestroy") { - console.debug("====>FMS_deleteForm_0700_1 onSupplyCallBack====>" + JSON.stringify(data)); + console.info(`${tcNumber} onSupplyCallback ${JSON.stringify(data)}`); expect(data.parameters.parameters).assertEqual(formId); supplyFlag = true; } @@ -809,155 +650,135 @@ export default function test() { supplyFlagUpdate = true; } } - } - function unSubscribeSupplyCallback() { - console.debug("====>FMS_deleteForm_0700_1 unSubscribeSupplyCallback====>"); - } - commonEvent.createSubscriber(onAcquiredForm_Event).then(async (data) => { - console.debug("====>FMS_deleteForm_0700_1 Create OnAcquired Subscriber====>"); - subscriberOnAcquired = data; - await commonEvent.subscribe(subscriberOnAcquired, onAcquiredCallBack); - }); - commonEvent.createSubscriber(onSupplyEvent).then(async (data) => { - console.debug("====>FMS_deleteForm_0700_1 onSupplyEvent Subscriber====>"); - subscriberSupply = data; - await commonEvent.subscribe(subscriberSupply, onSupplyCallBack); - }); - console.log(`FMS_deleteForm_0700_1 featureAbility.startAbility start`); + }; + commonEvent.subscribe(subscriberSupply, onSupplyCallback); + + console.info(`${tcNumber} featureAbility.startAbility start`); await featureAbility.startAbility({ want: { bundleName: "com.ohos.st.formsystemhostd", abilityName: "com.ohos.st.formsystemhostd.MainAbility", parameters: { - "formId" : "0", - "name" : "Form_Js002", - "bundle" : "com.form.formsystemtestserviceb.hmservice", - "ability" : "com.form.formsystemtestserviceb.hmservice.FormAbility", - "moduleName" : "entry", - "temporary" : false, - "isCreate" : true + formId: "0", + name: "Form_Js002", + bundle: "com.form.formsystemtestserviceb.hmservice", + ability: "com.form.formsystemtestserviceb.hmservice.FormAbility", + moduleName: "entry", + temporary: false, + isCreate: true } } }).then((res: any) => { - console.log(`FMS_deleteForm_0700_1 featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); }).catch((err: any) => { - console.log(`FMS_deleteForm_0700_1 featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); }); - console.log(`FMS_deleteForm_0700_1 featureAbility.startAbility end`); + console.info(`${tcNumber} featureAbility.startAbility end`); }); + /** - * @tc.number: FMS_deleteForm_0700_2 - * @tc.name: After deleting a normal form, the form reference is 0. - * After deleting a form, there are still created normal forms in FMS. - * @tc.desc: 1.host A an host B create one normal card respectively - * 2.host A delete the form and verify the result is true - */ - it(`FMS_deleteForm_0700_2`, 0, async (done) => { - console.log(`FMS_deleteForm_0700_2 start`); - let subscriberOnAcquired; + * @tc.number: FMS_deleteForm_0700_2 + * @tc.name: After deleting a normal form, the form reference is 0. + * After deleting a form, there are still created normal forms in FMS. + * @tc.desc: 1.host A an host B create one normal card respectively + * 2.host A delete the form and verify the result is true + */ + it(`FMS_deleteForm_0700_2`, 0, async (done) => { + const tcNumber = `FMS_deleteForm_0700_2`; let formId; let formIdB; - let subscriberSupply; let supplyFlag = false; let supplyFlagUpdate = false; // timer speed up commonEvent.publish(`fms.time_speed`, { code: 900 }, () => { - console.log(`FMS_deleteForm_0700_2 time speed up`); + console.info(`${tcNumber} time speed up`); }); await changeTime(10, 29, 55); - function delPublishCallBack() { - console.info("!!!====>FMS_deleteForm_0700_2 delPublishCallBack====>"); - setTimeout(function () { - commonEvent.unsubscribe(subscriberSupply, unSubscribeSupplyCallback); - if(supplyFlag && supplyFlagUpdate) { - deleteFormB(); - } else { - deleteFormB(); - expect().assertFail(); - } - console.info('FMS_deleteForm_0700_2 delPublishCallBack end'); - }, 5000) + async function delPublishCallback() { + console.info(`${tcNumber} delPublishCallback`); + await sleep(5000); + commonEvent.unsubscribe(subscriberSupply, () => unsubscribeSupplyCallback(tcNumber)); + if (supplyFlag && supplyFlagUpdate) { + deleteFormB(); + } else { + deleteFormB(); + expect().assertFail(); + } + console.info(`${tcNumber} delPublishCallback end`); } - function delPublishCallBackB() { - console.info("!!!====>FMS_deleteForm_0700_2 delPublishCallBackB====>"); - setTimeout(function () { - console.info('FMS_deleteForm_0700_2 delPublishCallBackB end'); - console.log(`FMS_deleteForm_0700_2 end`); - done(); - }, 1000); + async function delPublishCallbackB() { + console.info(`${tcNumber} delPublishCallbackB`); + await sleep(1000); + console.info(`${tcNumber} delPublishCallbackB end`); + console.info(`${tcNumber} end`); + done(); } - function deleteFormB() { - console.info("!!!====>FMS_deleteForm_0700_2 deleteFormB start====>"); + async function deleteFormB() { + console.info(`${tcNumber} deleteFormB start`); // timer speed reset commonEvent.publish(`fms.time_speed`, { code: 1 }, () => { - console.log(`FMS_deleteForm_0700_2 time speed up`); + console.info(`${tcNumber} time speed up`); }); - setTimeout(function () { - let commonEventPublishData = { - bundleName: "com.ohos.st.formsystemhostd", - data: formIdB - }; - commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallBackB); - console.info("!!!====>FMS_deleteForm_0700_2 deleteFormB end====>"); - }, 1000) + await sleep(1000); + const commonEventPublishData = { + bundleName: "com.ohos.st.formsystemhostd", + data: formIdB + }; + commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallbackB); + console.info(`${tcNumber} deleteFormB end`); } - function onAcquiredCallBackB(err, data) { - console.info("!!!====>FMS_deleteForm_0700_2 onAcquiredCallBackB data:====>" + JSON.stringify(data)); - expect(data.event).assertEqual("FMS_FormOnAcquired_commonEvent"); + + const onAcquiredCallbackB = async (_, data) => { + console.info(`${tcNumber} onAcquiredCallbackB data: ${JSON.stringify(data)}`); + expect(data.event).assertEqual(`FMS_FormOnAcquired_commonEvent`); formIdB = data.data; - commonEvent.unsubscribe(subscriberOnAcquired, unSubscribeOnDetetedCallback); - let commonEventPublishData = { + commonEvent.unsubscribe(subscriberOnAcquired, () => unsubscribeOnAcquiredCallback(tcNumber)); + const commonEventPublishData = { bundleName: "com.ohos.st.formsystemhostc", data: formId }; - commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallBack); - } - function unSubscribeOnDetetedCallback() { - console.debug("====>FMS_deleteForm_0700_2 unSubscribeOnDetetedCallback CallBack====>"); - } - - async function onAcquiredCallBack(err, data) { - console.info("!!!====>FMS_deleteForm_0700_2 onAcquiredCallBack data:====>" + JSON.stringify(data)); - expect(data.event).assertEqual("FMS_FormOnAcquired_commonEvent"); - commonEvent.unsubscribe(subscriberOnAcquired, unSubscribeOnAcquiredCallback) + commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallback); + }; + + const onAcquiredCallback = async (_, data) => { + console.info(`${tcNumber} onAcquiredCallback data: ${JSON.stringify(data)}`); + expect(data.event).assertEqual(`FMS_FormOnAcquired_commonEvent`); + commonEvent.unsubscribe(subscriberOnAcquired, () => unsubscribeOnAcquiredCallback(tcNumber)); formId = data.data; - commonEvent.createSubscriber(onAcquiredForm_Event).then(async (data) => { - console.debug("====>FMS_deleteForm_0700_2 B onAcquiredForm_Event Subscriber====>"); - subscriberOnAcquired = data; - await commonEvent.subscribe(subscriberOnAcquired, onAcquiredCallBackB); - }); + subscriberOnAcquired = await commonEvent.createSubscriber(onAcquiredForm_Event); + await sleep(1000); + commonEvent.subscribe(subscriberOnAcquired, onAcquiredCallbackB); - console.log(`FMS_deleteForm_0700_2 featureAbility.startAbility again start`); + console.info(`${tcNumber} featureAbility.startAbility again start`); await featureAbility.startAbility({ want: { bundleName: "com.ohos.st.formsystemhostd", abilityName: "com.ohos.st.formsystemhostd.MainAbility", parameters: { - "formId" : "0", - "name" : "Form_Js002", - "bundle" : "com.form.formsystemtestserviceb.hmservice", - "ability" : "com.form.formsystemtestserviceb.hmservice.FormAbility", - "moduleName" : "entry", - "temporary" : false, - "isCreate" : true + formId: "0", + name: "Form_Js002", + bundle: "com.form.formsystemtestserviceb.hmservice", + ability: "com.form.formsystemtestserviceb.hmservice.FormAbility", + moduleName: "entry", + temporary: false, + isCreate: true } } }).then((res: any) => { - console.log(`FMS_deleteForm_0700_2 featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); }).catch((err: any) => { - console.log(`FMS_deleteForm_0700_2 featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); }); - console.log(`FMS_deleteForm_0700_2 featureAbility.startAbility again end`); - } - function unSubscribeOnAcquiredCallback() { - console.debug("====>FMS_deleteForm_0700_2 OnAcquired UnSubscribe CallBack====>"); - } - function onSupplyCallBack(err, data) { + console.info(`${tcNumber} featureAbility.startAbility again end`); + }; + commonEvent.subscribe(subscriberOnAcquired, onAcquiredCallback); + + const onSupplyCallback = async (_, data) => { if (data.parameters.kind == "onDestroy") { - console.debug("====>FMS_deleteForm_0700_2 onSupplyCallBack====>" + JSON.stringify(data)); + console.info(`${tcNumber} onSupplyCallback ${JSON.stringify(data)}`); expect(data.parameters.parameters).assertEqual(formId); supplyFlag = true; } @@ -968,383 +789,380 @@ export default function test() { supplyFlagUpdate = true; } } - } - function unSubscribeSupplyCallback() { - console.debug("====>FMS_deleteForm_0700_2 unSubscribeSupplyCallback====>"); - } - commonEvent.createSubscriber(onAcquiredForm_Event).then(async (data) => { - console.debug("====>FMS_deleteForm_0700_2 Create OnAcquired Subscriber====>"); - subscriberOnAcquired = data; - await commonEvent.subscribe(subscriberOnAcquired, onAcquiredCallBack); - }); - commonEvent.createSubscriber(onSupplyEvent).then(async (data) => { - console.debug("====>FMS_deleteForm_0700_2 onSupplyEvent Subscriber====>"); - subscriberSupply = data; - await commonEvent.subscribe(subscriberSupply, onSupplyCallBack); - }); - console.log(`FMS_deleteForm_0700_2 featureAbility.startAbility start`); + }; + commonEvent.subscribe(subscriberSupply, onSupplyCallback); + + console.info(`${tcNumber} featureAbility.startAbility start`); await featureAbility.startAbility({ want: { bundleName: "com.ohos.st.formsystemhostc", abilityName: "com.ohos.st.formsystemhostc.MainAbility", parameters: { - "formId" : "0", - "name" : "Form_Js001", - "bundle" : "com.form.formsystemtestservicea.hmservice", - "ability" : "com.form.formsystemtestservicea.hmservice.FormAbility", - "moduleName" : "entry", - "temporary" : false, - "isCreate" : true + formId: "0", + name: "Form_Js001", + bundle: "com.form.formsystemtestservicea.hmservice", + ability: "com.form.formsystemtestservicea.hmservice.FormAbility", + moduleName: "entry", + temporary: false, + isCreate: true } } }).then((res: any) => { - console.log(`FMS_deleteForm_0700_2 featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); }).catch((err: any) => { - console.log(`FMS_deleteForm_0700_2 featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); }); - console.log(`FMS_deleteForm_0700_2 featureAbility.startAbility end`); + console.info(`${tcNumber} featureAbility.startAbility end`); }); + /** - * @tc.number: FMS_deleteForm_0900 - * @tc.name: Form ID error (FormID does not exist) - * @tc.desc: 1.host create one normal card - * 2.host delete the form - * 3.host delete the form again and verify the result is false - */ + * @tc.number: FMS_deleteForm_0900 + * @tc.name: Form ID error (FormID does not exist) + * @tc.desc: 1.host create one normal card + * 2.host delete the form + * 3.host delete the form again and verify the result is false + */ it(`FMS_deleteForm_0900`, 0, async (done) => { - console.log(`FMS_deleteForm_0900 start`); - let subscriberOnDeleted; + const tcNumber = `FMS_deleteForm_0900`; let formId; - let formIdB; - function delPublishCallBack() { - console.info("!!!====>FMS_deleteForm_0900 delPublishCallBack====>"); - setTimeout(function () { - console.info('FMS_deleteForm_0900 delPublishCallBack end'); - console.log(`FMS_deleteForm_0900 end`); - done(); - }, 1000); - } - - function onDetetedCallBack2(err, data) { - console.info("!!!====>FMS_deleteForm_0900 onDetetedCallBack2 data:====>" + JSON.stringify(data)); - expect(data.event).assertEqual("FMS_FormOnDeleted_commonEvent"); + function onDeletedCallback2(_, data) { + console.info(`${tcNumber} onDeletedCallback2 data: ${JSON.stringify(data)}`); + expect(data.event).assertEqual(`FMS_FormOnDeleted_commonEvent`); expect(data.data != "0").assertEqual(true); - console.info("!!!====>FMS_deleteForm_0900 failed to delete form again.====>"); - commonEvent.unsubscribe(subscriberOnDeleted, unSubscribeOnDetetedCallback); - let commonEventPublishData = { + console.info(`${tcNumber} failed to delete form again.`); + commonEvent.unsubscribe(subscriberOnDeleted, () => unsubscribeOnDeletedCallback(tcNumber)); + const commonEventPublishData = { bundleName: "com.ohos.st.formsystemhostc", data: formId }; - commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallBack); - } - function unSubscribeOnDetetedCallback() { - console.debug("====>FMS_deleteForm_0900 unSubscribeOnDetetedCallback CallBack====>"); + commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallback(tcNumber, done)); } - - function onDeletedCallBack(err, data) { - console.info("!!!====>FMS_deleteForm_0900 onDeletedCallBack data:====>" + JSON.stringify(data)); - expect(data.event).assertEqual("FMS_FormOnDeleted_commonEvent"); - expect(data.data).assertEqual("0"); - commonEvent.unsubscribe(subscriberOnDeleted, unSubscribeOnDetetedCallback) + + const onDeletedCallback = async (_, data) => { + console.info(`${tcNumber} onDeletedCallback data: ${JSON.stringify(data)}`); + expect(data.event).assertEqual(`FMS_FormOnDeleted_commonEvent`); + expect(data.data).assertEqual(`0`); + commonEvent.unsubscribe(subscriberOnDeleted, () => unsubscribeOnDeletedCallback(tcNumber)); formId = data.parameters.formId; - commonEvent.createSubscriber(onDetetedFormEvent).then(async (data) => { - console.debug("====>FMS_deleteForm_0900 B onDetetedFormEvent Subscriber====>"); - subscriberOnDeleted = data; - await commonEvent.subscribe(subscriberOnDeleted, onDetetedCallBack2); - }); + subscriberOnDeleted = await commonEvent.createSubscriber(onDeletedFormEvent); + await sleep(1000); + commonEvent.subscribe(subscriberOnDeleted, onDeletedCallback2); - console.log(`FMS_deleteForm_0900 featureAbility.startAbility again start`); - featureAbility.startAbility({ + console.info(`${tcNumber} featureAbility.startAbility again start`); + await featureAbility.startAbility({ want: { bundleName: "com.ohos.st.formsystemhostc", abilityName: "com.ohos.st.formsystemhostc.MainAbility", parameters: { - "formId" : "0", - "name" : "Form_Js001", - "bundle" : "com.form.formsystemtestservicea.hmservice", - "ability" : "com.form.formsystemtestservicea.hmservice.FormAbility", - "moduleName" : "entry", - "temporary" : false, - "deleteForm" : true, - "deleteId" : formId, - "isCreate" : false + formId: "0", + name: "Form_Js001", + bundle: "com.form.formsystemtestservicea.hmservice", + ability: "com.form.formsystemtestservicea.hmservice.FormAbility", + moduleName: "entry", + temporary: false, + deleteForm: true, + deleteId: formId, + isCreate: false } } }).then((res: any) => { - console.log(`FMS_deleteForm_0900 featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); }).catch((err: any) => { - console.log(`FMS_deleteForm_0900 featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); }); - console.log(`FMS_deleteForm_0900 featureAbility.startAbility again end`); - } - commonEvent.createSubscriber(onDetetedFormEvent).then(async (data) => { - console.debug("====>FMS_deleteForm_0900 onDetetedFormEvent Subscriber====>"); - subscriberOnDeleted = data; - await commonEvent.subscribe(subscriberOnDeleted, onDeletedCallBack); - }); + console.info(`${tcNumber} featureAbility.startAbility again end`); + }; + commonEvent.subscribe(subscriberOnDeleted, onDeletedCallback); - console.log(`FMS_deleteForm_0900 featureAbility.startAbility start`); + console.info(`${tcNumber} featureAbility.startAbility start`); await featureAbility.startAbility({ want: { bundleName: "com.ohos.st.formsystemhostc", abilityName: "com.ohos.st.formsystemhostc.MainAbility", parameters: { - "formId" : "0", - "name" : "Form_Js001", - "bundle" : "com.form.formsystemtestservicea.hmservice", - "ability" : "com.form.formsystemtestservicea.hmservice.FormAbility", - "moduleName" : "entry", - "temporary" : false, - "deleteForm" : true, - "deleteId" : "self", - "isCreate" : true + formId: "0", + name: "Form_Js001", + bundle: "com.form.formsystemtestservicea.hmservice", + ability: "com.form.formsystemtestservicea.hmservice.FormAbility", + moduleName: "entry", + temporary: false, + deleteForm: true, + deleteId: "self", + isCreate: true } } }).then((res: any) => { - console.log(`FMS_deleteForm_0900 featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); }).catch((err: any) => { - console.log(`FMS_deleteForm_0900 featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); }); - console.log(`FMS_deleteForm_0900 featureAbility.startAbility end`); + console.info(`${tcNumber} featureAbility.startAbility end`); }); + /** - * @tc.number: FMS_deleteForm_1000 - * @tc.name: You can delete a card after releasing it - * @tc.desc: 1.host create one normal card - * 2.host release the form - * 3.host delete the form and verify the result is true - */ + * @tc.number: FMS_deleteForm_1000 + * @tc.name: You can delete a card after releasing it + * @tc.desc: 1.host create one normal card + * 2.host release the form + * 3.host delete the form and verify the result is true + */ it(`FMS_deleteForm_1000`, 0, async (done) => { - console.log(`FMS_deleteForm_1000 start`); - let subscriberOnReleased; + const tcNumber = `FMS_deleteForm_1000`; let formId; - let formIdB; - let subscriberSupply; - - function unSubscribeOnReleasedCallback() { - console.debug("====>FMS_deleteForm_1000 unSubscribeOnReleasedCallback CallBack====>"); - } - function onReleasedCallBack(err, data) { - console.info("!!!====>FMS_deleteForm_1000 onReleasedCallBack data:====>" + JSON.stringify(data)); - expect(data.event).assertEqual("FMS_FormOnReleased_commonEvent"); - expect(data.data).assertEqual("0"); - commonEvent.unsubscribe(subscriberOnReleased, unSubscribeOnReleasedCallback); + + async function onReleasedCallback(_, data) { + console.info(`${tcNumber} onReleasedCallback data: ${JSON.stringify(data)}`); + expect(data.event).assertEqual(`FMS_FormOnReleased_commonEvent`); + expect(data.data).assertEqual(`0`); + commonEvent.unsubscribe(subscriberOnReleased, () => unsubscribeOnReleasedCallback(tcNumber)); formId = data.parameters.formId; - console.log(`FMS_deleteForm_1000 featureAbility.startAbility again start`); - featureAbility.startAbility({ + console.info(`${tcNumber} featureAbility.startAbility again start`); + await featureAbility.startAbility({ want: { bundleName: "com.ohos.st.formsystemhostc", abilityName: "com.ohos.st.formsystemhostc.MainAbility", parameters: { - "formId" : "0", - "name" : "Form_Js001", - "bundle" : "com.form.formsystemtestservicea.hmservice", - "ability" : "com.form.formsystemtestservicea.hmservice.FormAbility", - "moduleName" : "entry", - "temporary" : false, - "deleteForm" : true, - "deleteId" : formId, - "isCreate" : false + formId: "0", + name: "Form_Js001", + bundle: "com.form.formsystemtestservicea.hmservice", + ability: "com.form.formsystemtestservicea.hmservice.FormAbility", + moduleName: "entry", + temporary: false, + deleteForm: true, + deleteId: formId, + isCreate: false } } }).then((res: any) => { - console.log(`FMS_deleteForm_1000 featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); }).catch((err: any) => { - console.log(`FMS_deleteForm_1000 featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); }); - console.log(`FMS_deleteForm_1000 featureAbility.startAbility again end`); + console.info(`${tcNumber} featureAbility.startAbility again end`); } - commonEvent.createSubscriber(onReleasedFormEvent).then(async (data) => { - console.debug("====>FMS_deleteForm_1000 onReleasedFormEvent Subscriber====>"); - subscriberOnReleased = data; - await commonEvent.subscribe(subscriberOnReleased, onReleasedCallBack); - }); - function onSupplyCallBack(err, data) { - if(data.parameters.kind == "onDestroy") { - console.debug("====>FMS_deleteForm_1000 onSupplyCallBack====>" + JSON.stringify(data)); - commonEvent.unsubscribe(subscriberSupply, unSubscribeSupplyCallback); + commonEvent.subscribe(subscriberOnReleased, onReleasedCallback); + + const onSupplyCallback = async (_, data) => { + if (data.parameters.kind == "onDestroy") { + console.info(`${tcNumber} onSupplyCallback ${JSON.stringify(data)}`); + commonEvent.unsubscribe(subscriberSupply, () => unsubscribeSupplyCallback(tcNumber)); expect(data.parameters.parameters).assertEqual(formId); - setTimeout(function () { - console.info('FMS_deleteForm_1000 onDeletedCallback end'); - console.log(`FMS_deleteForm_1000 end`); - done(); - }, 1000); + await sleep(1000); + console.info(`${tcNumber}onDeletedCallback end`); + console.info(`${tcNumber} end`); + done(); } - } - function unSubscribeSupplyCallback() { - console.debug("====>FMS_deleteForm_1000 unSubscribeSupplyCallback====>"); - } + }; + commonEvent.subscribe(subscriberSupply, onSupplyCallback); - commonEvent.createSubscriber(onSupplyEvent).then(async (data) => { - console.debug("====>FMS_deleteForm_1000 onSupplyEvent Subscriber====>"); - subscriberSupply = data; - await commonEvent.subscribe(subscriberSupply, onSupplyCallBack); - }); - console.log(`FMS_deleteForm_1000 featureAbility.startAbility start`); + console.info(`${tcNumber} featureAbility.startAbility start`); await featureAbility.startAbility({ want: { bundleName: "com.ohos.st.formsystemhostc", abilityName: "com.ohos.st.formsystemhostc.MainAbility", parameters: { - "formId" : "0", - "name" : "Form_Js001", - "bundle" : "com.form.formsystemtestservicea.hmservice", - "ability" : "com.form.formsystemtestservicea.hmservice.FormAbility", - "moduleName" : "entry", - "temporary" : false, - "releaseForm" : true, - "releaseId" : "self", - "isCreate" : true + formId: "0", + name: "Form_Js001", + bundle: "com.form.formsystemtestservicea.hmservice", + ability: "com.form.formsystemtestservicea.hmservice.FormAbility", + moduleName: "entry", + temporary: false, + "releaseForm": true, + "releaseId": "self", + isCreate: true } } }).then((res: any) => { - console.log(`FMS_deleteForm_1000 featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); }).catch((err: any) => { - console.log(`FMS_deleteForm_1000 featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); }); - console.log(`FMS_deleteForm_1000 featureAbility.startAbility end`); + console.info(`${tcNumber} featureAbility.startAbility end`); }); + /** - * @tc.number: FMS_deleteForm_1100 - * @tc.name: When deleting a temporary form, cache data is deleted. - * @tc.desc: 1.host a and b create one temporary card respectively - * 2.host a delete the form and verify the result is true - */ + * @tc.number: FMS_deleteForm_1100 + * @tc.name: When deleting a temporary form, cache data is deleted. + * @tc.desc: 1.host a and b create one temporary card respectively + * 2.host a delete the form and verify the result is true + */ it(`FMS_deleteForm_1100`, 0, async (done) => { - console.log(`FMS_deleteForm_1100 start`); - let subscriberOnDeleted; - let subscriberOnAcquired; + const tcNumber = `FMS_deleteForm_1100`; let formId; let formIdB; - let subscriberSupply; let supplyFlag = false; - function delPublishCallBack() { - console.info("!!!====>FMS_deleteForm_1100 delPublishCallBack====>"); - setTimeout(function () { - commonEvent.unsubscribe(subscriberSupply, unSubscribeSupplyCallback); - if(supplyFlag) { - deleteFormB(); - } else { - deleteFormB(); - expect().assertFail(); - } - console.info('FMS_deleteForm_1100 delPublishCallBack end'); - }, 1000); + async function delPublishCallback() { + console.info(`${tcNumber} delPublishCallback`); + await sleep(1000); + commonEvent.unsubscribe(subscriberSupply, () => unsubscribeSupplyCallback(tcNumber)); + if (supplyFlag) { + deleteFormB(); + } else { + deleteFormB(); + expect().assertFail(); + } + console.info(`${tcNumber} delPublishCallback end`); } - function delPublishCallBackB() { - console.info("!!!====>FMS_deleteForm_1100 delPublishCallBackB====>"); - setTimeout(function () { - console.info('FMS_deleteForm_1100 delPublishCallBackB end'); - console.log(`FMS_deleteForm_1100 end`); - done(); - }, 1000); + async function delPublishCallbackB() { + console.info(`${tcNumber} delPublishCallbackB`); + await sleep(1000); + console.info(`${tcNumber} delPublishCallbackB end`); + console.info(`${tcNumber} end`); + done(); } function deleteFormB() { - console.info("!!!====>FMS_deleteForm_1100 deleteFormB start====>"); - let commonEventPublishData = { + console.info(`${tcNumber} deleteFormB start`); + const commonEventPublishData = { bundleName: "com.ohos.st.formsystemhostd", data: formIdB }; - commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallBackB); - console.info("!!!====>FMS_deleteForm_1100 deleteFormB end====>"); + commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallbackB); + console.info(`${tcNumber} deleteFormB end`); } - function onAcquiredCallBackB(err, data) { - console.info("!!!====>FMS_deleteForm_1100 onAcquiredCallBackB data:====>" + JSON.stringify(data)); - expect(data.event).assertEqual("FMS_FormOnAcquired_commonEvent"); + + const onAcquiredCallbackB = async (_, data) => { + console.info(`${tcNumber} onAcquiredCallbackB data: ${JSON.stringify(data)}`); + expect(data.event).assertEqual(`FMS_FormOnAcquired_commonEvent`); formIdB = data.data; - commonEvent.unsubscribe(subscriberOnAcquired, unSubscribeOnDetetedCallback); - let commonEventPublishData = { + commonEvent.unsubscribe(subscriberOnAcquired, () => unsubscribeOnAcquiredCallback(tcNumber)); + const commonEventPublishData = { bundleName: "com.ohos.st.formsystemhostc", data: formId }; - commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallBack); - } - function unSubscribeOnDetetedCallback() { - console.debug("====>FMS_deleteForm_1100 unSubscribeOnDetetedCallback CallBack====>"); - } - - function onAcquiredCallBack(err, data) { - console.info("!!!====>FMS_deleteForm_1100 onAcquiredCallBack data:====>" + JSON.stringify(data)); - expect(data.event).assertEqual("FMS_FormOnAcquired_commonEvent"); - commonEvent.unsubscribe(subscriberOnAcquired, unSubscribeOnAcquiredCallback); + commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallback); + }; + + const onAcquiredCallback = async (_, data) => { + console.info(`${tcNumber} onAcquiredCallback data: ${JSON.stringify(data)}`); + expect(data.event).assertEqual(`FMS_FormOnAcquired_commonEvent`); + commonEvent.unsubscribe(subscriberOnAcquired, () => unsubscribeOnAcquiredCallback(tcNumber)); formId = data.data; - commonEvent.createSubscriber(onAcquiredForm_Event).then(async (data) => { - console.debug("====>FMS_deleteForm_1100 B onAcquiredForm_Event Subscriber====>"); - subscriberOnAcquired = data; - await commonEvent.subscribe(subscriberOnAcquired, onAcquiredCallBackB); - }); + subscriberOnAcquired = await commonEvent.createSubscriber(onAcquiredForm_Event); + await sleep(1000); + commonEvent.subscribe(subscriberOnAcquired, onAcquiredCallbackB); - console.log(`FMS_deleteForm_1100 featureAbility.startAbility again start`); - featureAbility.startAbility({ + console.info(`${tcNumber} featureAbility.startAbility again start`); + await featureAbility.startAbility({ want: { bundleName: "com.ohos.st.formsystemhostd", abilityName: "com.ohos.st.formsystemhostd.MainAbility", parameters: { - "formId" : "0", - "name" : "Form_Js001", - "bundle" : "com.form.formsystemtestservicea.hmservice", - "ability" : "com.form.formsystemtestservicea.hmservice.FormAbility", - "moduleName" : "entry", - "temporary" : true, - "isCreate" : true + formId: "0", + name: "Form_Js001", + bundle: "com.form.formsystemtestservicea.hmservice", + ability: "com.form.formsystemtestservicea.hmservice.FormAbility", + moduleName: "entry", + temporary: true, + isCreate: true } } }).then((res: any) => { - console.log(`FMS_deleteForm_1100 featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); }).catch((err: any) => { - console.log(`FMS_deleteForm_1100 featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); }); - console.log(`FMS_deleteForm_1100 featureAbility.startAbility again end`); - } - function unSubscribeOnAcquiredCallback() { - console.debug("====>FMS_deleteForm_1100 OnAcquired UnSubscribe CallBack====>"); - } - function onSupplyCallBack(err, data) { - if(data.parameters.kind == "onDestroy") { - console.debug("====>FMS_deleteForm_1100 onSupplyCallBack====>" + JSON.stringify(data)); + console.info(`${tcNumber} featureAbility.startAbility again end`); + }; + commonEvent.subscribe(subscriberOnAcquired, onAcquiredCallback); + + const onSupplyCallback = async (_, data) => { + if (data.parameters.kind == "onDestroy") { + console.info(`${tcNumber} onSupplyCallback ${JSON.stringify(data)}`); expect(data.parameters.parameters).assertEqual(formId); supplyFlag = true; } - } - function unSubscribeSupplyCallback() { - console.debug("====>FMS_deleteForm_1100 unSubscribeSupplyCallback====>"); - } - commonEvent.createSubscriber(onAcquiredForm_Event).then(async (data) => { - console.debug("====>FMS_deleteForm_1100 Create OnAcquired Subscriber====>"); - subscriberOnAcquired = data; - await commonEvent.subscribe(subscriberOnAcquired, onAcquiredCallBack); - }); - commonEvent.createSubscriber(onSupplyEvent).then(async (data) => { - console.debug("====>FMS_deleteForm_1100 onSupplyEvent Subscriber====>"); - subscriberSupply = data; - await commonEvent.subscribe(subscriberSupply, onSupplyCallBack); - }); - console.log(`FMS_deleteForm_1100 featureAbility.startAbility start`); + }; + commonEvent.subscribe(subscriberSupply, onSupplyCallback); + + console.info(`${tcNumber} featureAbility.startAbility start`); await featureAbility.startAbility({ want: { bundleName: "com.ohos.st.formsystemhostc", abilityName: "com.ohos.st.formsystemhostc.MainAbility", parameters: { - "formId" : "0", - "name" : "Form_Js001", - "bundle" : "com.form.formsystemtestservicea.hmservice", - "ability" : "com.form.formsystemtestservicea.hmservice.FormAbility", - "moduleName" : "entry", - "temporary" : true, - "isCreate" : true + formId: "0", + name: "Form_Js001", + bundle: "com.form.formsystemtestservicea.hmservice", + ability: "com.form.formsystemtestservicea.hmservice.FormAbility", + moduleName: "entry", + temporary: true, + isCreate: true } } }).then((res: any) => { - console.log(`FMS_deleteForm_1100 featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); }).catch((err: any) => { - console.log(`FMS_deleteForm_1100 featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); }); - console.log(`FMS_deleteForm_1100 featureAbility.startAbility end`); + console.info(`${tcNumber} featureAbility.startAbility end`); }); }); } + +/** + * Set time + * + * @param hour hour of 24H clock + * @param min minute + * @param second second + */ +const changeTime = async (hour, min, second) => { + console.info(`FMS_deleteForm changeTime start`); + const datetime = new Date(); + const year = datetime.getFullYear(); + const month = datetime.getMonth() + 1; + const day = datetime.getDate(); + const formatTime = year + '-' + fill(month) + '-' + fill(day) + + 'T' + fill(hour) + ':' + fill(min) + ':' + fill(second); + const s = (new Date(formatTime)).getTime(); + console.info(`FMS_deleteForm changeTime formatTime: ${formatTime}`); + console.info(`FMS_deleteForm changeTime s: ${s}`); + + try { + await setTime(s); + console.info(`FMS_deleteForm set time success: ${formatTime}`); + } catch (error) { + console.info(`FMS_deleteForm set time failure: ${error}`); + } + console.info(`FMS_deleteForm changeTime end`); +}; + +const fill = value => { + return (value > 9 ? "" : "0") + value; +}; + +const sleep = async delay => { + return new Promise((resolve, _) => { + setTimeout(async () => { + resolve(0); + }, delay); + }); +}; + +const delPublishCallback = async (tcNumber, done) => { + await sleep(1000); + console.info(`${tcNumber} delPublishCallback end`); + console.info(`${tcNumber} end`); + done(); +}; + +const unsubscribeOnAcquiredCallback = (tcNumber) => { + console.info(`${tcNumber} Unsubscribe OnAcquired Callback`); +}; + +const unsubscribeOnDeletedCallback = (tcNumber) => { + console.info(`${tcNumber} Unsubscribe OnDeleted Callback`); +}; + +const unsubscribeSupplyCallback = (tcNumber) => { + console.info(`${tcNumber} Unsubscribe Supply Callback`); +}; + +const unsubscribeOnReleasedCallback = (tcNumber) => { + console.info(`${tcNumber} Unsubscribe OnReleased Callback`); +}; diff --git a/aafwk/aafwk_standard/formmanager/fa/formsystemtest_ets/formdynamicrefreshtest/entry/src/main/ets/MainAbility/model/FormViewModel.ets b/aafwk/aafwk_standard/formmanager/fa/formsystemtest_ets/formdynamicrefreshtest/entry/src/main/ets/MainAbility/model/FormViewModel.ets deleted file mode 100644 index 659108ce439cf2b927fdf1801539f3dddbd851d6..0000000000000000000000000000000000000000 --- a/aafwk/aafwk_standard/formmanager/fa/formsystemtest_ets/formdynamicrefreshtest/entry/src/main/ets/MainAbility/model/FormViewModel.ets +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import formManager from '@ohos.ability.formmanager'; -import bundleManager from '@ohos.bundle'; - -export default class FormViewModel { - private static sFormViewModel: FormViewModel = null; - - public static getInstance(): FormViewModel { - if (FormViewModel.sFormViewModel == null) { - FormViewModel.sFormViewModel = new FormViewModel(); - } - return FormViewModel.sFormViewModel; - } - - public async requestForm(formId: string) { - formManager.requestForm(formId) - .then((data) => { - console.info( '[FormComponent] requestForm result:' + data); - }); - } - - public async deleteCard(formId: string) { - formManager.deleteForm(formId) - .then((data) => { - console.info('[FormComponent] deleteForm result:' + data); - }); - } - - public async releaseCard(formId: string) { - formManager.releaseForm(formId) - .then((data) => { - console.info('[FormComponent] releaseForm result:' + data); - }); - } - - public async castTempToNormal(formId: string) { - formManager.castTempForm(formId) - .then((data) => { - console.info('[FormComponent] castTempToNormal result:' + data); - }); - } - - public async enableCard(formId: string) { - formManager.enableFormsUpdate([formId]) - .then((data) => { - console.info('[FormComponent] enableFormsUpdate result:' + data); - }); - } - - public async disableCard(formId: string) { - formManager.disableFormsUpdate([formId]) - .then((data) => { - console.info('[FormComponent] disableCard result:' + data); - }); - } - - public async changeCardVisible(formId: string, isVisible: boolean) { - if (isVisible) { - formManager.notifyVisibleForms([formId]) - .then((data) => { - console.info('[FormComponent] changeCardVisible result:' + data + ', isVisible:' + isVisible); - }); - } else { - formManager.notifyInvisibleForms([formId]) - .then((data) => { - console.info('[FormComponent] changeCardVisible result:' + data + ', isVisible:' + isVisible); - }); - } - } - - public async isFmsReady() { - formManager.isSystemReady() - .then((data) => { - console.info('[FormComponent] isFmsReady result:' + data); - }); - } - - public async getAllFormsInfo() { - console.info("[FormComponent] getAllFormsInfo start"); - formManager.getAllFormsInfo() - .then((data) => { - console.info('[FormComponent] getAllFormsInfo result:' + JSON.stringify(data)); - }) - .catch((err) => { - console.info('[FormComponent] getAllFormsInfo error:' + JSON.stringify(err)); - }); - console.info("[FormComponent] getAllFormsInfo end"); - } - - public async getFormsInfoByApp(bundle: string) { - formManager.getFormsInfo(bundle) - .then((data) => { - console.info('[FormComponent] getFormsInfoByApp result:' + JSON.stringify(data)); - }); - } - - public async getFormsInfoByModule(bundle: string, moduleName: string) { - formManager.getFormsInfo(bundle, moduleName) - .then((data) => { - console.info('[FormComponent] getFormsInfoByModule result:' + JSON.stringify(data)); - }); - } - - public async clearFormUserCache() { - bundleManager.cleanBundleCacheFiles('com.ohos.myapplicationform') - .then((data) => { - console.info('[FormComponent] cleanBundleCacheFiles result:' + JSON.stringify(data)); - }); - } - - public async clearFormProviderCache(bundle: string) { - bundleManager.cleanBundleCacheFiles(bundle) - .then((data) => { - console.info('[FormComponent] cleanBundleCacheFiles result:' + JSON.stringify(data)); - }); - } -} \ No newline at end of file diff --git a/aafwk/aafwk_standard/formmanager/fa/formsystemtest_ets/formdynamicrefreshtest/entry/src/main/ets/MainAbility/test/FmsDynamicRefreshForm.test.ets b/aafwk/aafwk_standard/formmanager/fa/formsystemtest_ets/formdynamicrefreshtest/entry/src/main/ets/MainAbility/test/FmsDynamicRefreshForm.test.ets index 14d364e2499205a49422a5424383af401400312f..5e59daae31f49efe032dc359dd4a25095014060b 100644 --- a/aafwk/aafwk_standard/formmanager/fa/formsystemtest_ets/formdynamicrefreshtest/entry/src/main/ets/MainAbility/test/FmsDynamicRefreshForm.test.ets +++ b/aafwk/aafwk_standard/formmanager/fa/formsystemtest_ets/formdynamicrefreshtest/entry/src/main/ets/MainAbility/test/FmsDynamicRefreshForm.test.ets @@ -13,31 +13,44 @@ * limitations under the License. */ -import featureAbility from "@ohos.ability.featureAbility"; +import featureAbility from '@ohos.ability.featureAbility'; import commonEvent from '@ohos.commonEvent'; -import { describe, expect, it } from "deccjsunit/index.ets"; +import { beforeEach, describe, expect, it } from 'deccjsunit/index.ets'; -var onAcquiredForm_Event = { +const onAcquiredForm_Event = { events: ["FMS_FormOnAcquired_commonEvent"], }; -var onDetetedFormEvent = { +const onDeletedFormEvent = { events: ["FMS_FormOnDeleted_commonEvent"], }; -var onRefreshFormEvent = { +const onRefreshFormEvent = { events: ["FMS_FormDynamicRefresh_commonEvent"], }; -var onSupplyEvent = { +const onSupplyEvent = { events: ["FMS_FormSupply_commonEvent"], }; -var deleteForm_Event = "FMS_FormDelete_commonEvent"; +const deleteForm_Event = "FMS_FormDelete_commonEvent"; + +let subscriberOnAcquired; +let subscriberOnDeleted; +let subscriberOnRefresh; +let subscriberSupply; export default function test() { describe(`FmsTimeRefreshFormTest`, () => { + beforeEach(async () => { + subscriberOnAcquired = await commonEvent.createSubscriber(onAcquiredForm_Event); + subscriberOnDeleted = await commonEvent.createSubscriber(onDeletedFormEvent); + subscriberOnRefresh = await commonEvent.createSubscriber(onRefreshFormEvent); + subscriberSupply = await commonEvent.createSubscriber(onSupplyEvent); + await sleep(1000); + }); + /** * @tc.number: FMS_timedRefresh_0100 * @tc.name: formID id is error(formID < 0) @@ -45,64 +58,46 @@ export default function test() { * 2.Verify the result of the dynamic timed refresh interface. */ it(`FMS_timedRefresh_0100`, 0, async (done) => { - console.log(`FMS_timedRefresh_0100 start`); - let subscriberOnRefresh; - let formId; - - function delPublishCallBack() { - console.info("!!!====>FMS_timedRefresh_0100 delPublishCallBack====>"); - setTimeout(function () { - console.info('FMS_timedRefresh_0100 delPublishCallBack end'); - console.log(`FMS_timedRefresh_0100 end`); - done(); - }, 1000) - } - - function onRefreshCallBack(err, data) { - console.info("!!!====>FMS_timedRefresh_0100 onRefreshCallBack data:====>" + JSON.stringify(data)); - expect(data.event).assertEqual("FMS_FormDynamicRefresh_commonEvent"); - expect(data.data).assertEqual("7"); - commonEvent.unsubscribe(subscriberOnRefresh, unSubscribeOnRefreshCallback) - - let commonEventPublishData = { + const tcNumber = `FMS_timedRefresh_0100`; + + const onRefreshCallback = async (_, data) => { + console.info(`${tcNumber} onRefreshCallback data: ${JSON.stringify(data)}`); + expect(data.event).assertEqual(`FMS_FormDynamicRefresh_commonEvent`); + expect(data.data).assertEqual(`7`); + commonEvent.unsubscribe(subscriberOnRefresh, () => unsubscribeOnRefreshCallback(tcNumber)); + const commonEventPublishData = { data: data.parameters.formId }; - commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallBack); - } - function unSubscribeOnRefreshCallback() { - console.debug("====>FMS_timedRefresh_0100 unSubscribeOnRefreshCallback CallBack====>"); - } - - commonEvent.createSubscriber(onRefreshFormEvent).then(async (data) => { - console.debug("====>FMS_timedRefresh_0100 onRefreshFormEvent Subscriber====>"); - subscriberOnRefresh = data; - await commonEvent.subscribe(subscriberOnRefresh, onRefreshCallBack); - }); - console.log(`FMS_timedRefresh_0100 featureAbility.startAbility start`); + commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallback(tcNumber, done)); + }; + commonEvent.subscribe(subscriberOnRefresh, onRefreshCallback); + + console.info(`${tcNumber} featureAbility.startAbility start`); await featureAbility.startAbility({ want: { bundleName: "com.ohos.st.formsystemhoste", abilityName: "com.ohos.st.formsystemhoste.MainAbility", parameters: { - "formId": "0", - "name": "Form_Js001", - "bundle": "com.form.formsystemtestservicea.hmservice", - "ability": "com.form.formsystemtestservicea.hmservice.MainAbility", - "moduleName": "entry", - "temporary": false, - "refreshForm": true, - "refreshId": "-1", - "refreshTime": 5, - "isCreate": true + formId: "0", + name: "Form_Js001", + bundle: "com.form.formsystemtestservicea.hmservice", + ability: "com.form.formsystemtestservicea.hmservice.MainAbility", + moduleName: "entry", + temporary: false, + refreshForm: true, + refreshId: "-1", + refreshTime: 5, + isCreate: true } } }).then((res: any) => { - console.log(`FMS_timedRefresh_0100 featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); }).catch((err: any) => { - console.log(`FMS_timedRefresh_0100 featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); }); - console.log(`FMS_timedRefresh_0100 featureAbility.startAbility end`); + console.info(`${tcNumber} featureAbility.startAbility end`); }); + /** * @tc.number: FMS_timedRefresh_0200 * @tc.name: formID id is error(formID == 0) @@ -110,63 +105,44 @@ export default function test() { * 2.Verify the result of the dynamic timed refresh interface. */ it(`FMS_timedRefresh_0200`, 0, async (done) => { - console.log(`FMS_timedRefresh_0200 start`); - let subscriberOnRefresh; - let formId; - - function delPublishCallBack() { - console.info("!!!====>FMS_timedRefresh_0200 delPublishCallBack====>"); - setTimeout(function () { - console.info('FMS_timedRefresh_0200 delPublishCallBack end'); - console.log(`FMS_timedRefresh_0200 end`); - done(); - }, 1000) - } - - function onRefreshCallBack(err, data) { - console.info("!!!====>FMS_timedRefresh_0200 onRefreshCallBack data:====>" + JSON.stringify(data)); - expect(data.event).assertEqual("FMS_FormDynamicRefresh_commonEvent"); - expect(data.data).assertEqual("7"); - commonEvent.unsubscribe(subscriberOnRefresh, unSubscribeOnRefreshCallback) - - let commonEventPublishData = { + const tcNumber = `FMS_timedRefresh_0200`; + + const onRefreshCallback = async (_, data) => { + console.info(`${tcNumber} onRefreshCallback data: ${JSON.stringify(data)}`); + expect(data.event).assertEqual(`FMS_FormDynamicRefresh_commonEvent`); + expect(data.data).assertEqual(`7`); + commonEvent.unsubscribe(subscriberOnRefresh, () => unsubscribeOnRefreshCallback(tcNumber)); + const commonEventPublishData = { data: data.parameters.formId }; - commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallBack); - } - function unSubscribeOnRefreshCallback() { - console.debug("====>FMS_timedRefresh_0200 unSubscribeOnRefreshCallback CallBack====>"); - } - - commonEvent.createSubscriber(onRefreshFormEvent).then(async (data) => { - console.debug("====>FMS_timedRefresh_0200 onRefreshFormEvent Subscriber====>"); - subscriberOnRefresh = data; - await commonEvent.subscribe(subscriberOnRefresh, onRefreshCallBack); - }); - console.log(`FMS_timedRefresh_0200 featureAbility.startAbility start`); + commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallback(tcNumber, done)); + }; + commonEvent.subscribe(subscriberOnRefresh, onRefreshCallback); + + console.info(`${tcNumber} featureAbility.startAbility start`); await featureAbility.startAbility({ want: { bundleName: "com.ohos.st.formsystemhoste", abilityName: "com.ohos.st.formsystemhoste.MainAbility", parameters: { - "formId": "0", - "name": "Form_Js001", - "bundle": "com.form.formsystemtestservicea.hmservice", - "ability": "com.form.formsystemtestservicea.hmservice.MainAbility", - "moduleName": "entry", - "temporary": false, - "refreshForm": true, - "refreshId": "0", - "refreshTime": 5, - "isCreate": true + formId: "0", + name: "Form_Js001", + bundle: "com.form.formsystemtestservicea.hmservice", + ability: "com.form.formsystemtestservicea.hmservice.MainAbility", + moduleName: "entry", + temporary: false, + refreshForm: true, + refreshId: "0", + refreshTime: 5, + isCreate: true } } }).then((res: any) => { - console.log(`FMS_timedRefresh_0200 featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); }).catch((err: any) => { - console.log(`FMS_timedRefresh_0200 featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); }); - console.log(`FMS_timedRefresh_0200 featureAbility.startAbility end`); + console.info(`${tcNumber} featureAbility.startAbility end`); }); /** @@ -176,101 +152,77 @@ export default function test() { * 2.Verify the result of the dynamic timed refresh interface. */ it(`FMS_timedRefresh_0300`, 0, async (done) => { - console.log(`FMS_timedRefresh_0300 start`); - let subscriberOnRefresh; - let subscriberOnAcquired; + const tcNumber = `FMS_timedRefresh_0300`; let formId; - function delPublishCallBack() { - console.info("!!!====>FMS_timedRefresh_0300 delPublishCallBack====>"); - setTimeout(function () { - console.info('FMS_timedRefresh_0300 delPublishCallBack end'); - console.log(`FMS_timedRefresh_0300 end`); - done(); - }, 1000) - } - - function onRefreshCallBack(err, data) { - console.info("!!!====>FMS_timedRefresh_0300 onRefreshCallBack data:====>" + JSON.stringify(data)); - expect(data.event).assertEqual("FMS_FormDynamicRefresh_commonEvent"); - expect(data.data).assertEqual("13"); - commonEvent.unsubscribe(subscriberOnRefresh, unsubscribeOnRefreshCallback); - let commonEventPublishData = { + const onRefreshCallback = async (_, data) => { + console.info(`${tcNumber} onRefreshCallback data: ${JSON.stringify(data)}`); + expect(data.event).assertEqual(`FMS_FormDynamicRefresh_commonEvent`); + expect(data.data).assertEqual(`13`); + commonEvent.unsubscribe(subscriberOnRefresh, () => unsubscribeOnRefreshCallback(tcNumber)); + const commonEventPublishData = { data: formId }; - commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallBack); - } - function unsubscribeOnRefreshCallback() { - console.debug("====>FMS_timedRefresh_0300 unsubscribeOnRefreshCallback====>"); - } - - function onAcquiredCallBack(err, data) { - console.info("!!!====>FMS_timedRefresh_0300 onAcquiredCallBack data:====>" + JSON.stringify(data)); - expect(data.event).assertEqual("FMS_FormOnAcquired_commonEvent"); - commonEvent.unsubscribe(subscriberOnAcquired, unSubscribeOnAcquiredCallback) + commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallback(tcNumber, done)); + }; + commonEvent.subscribe(subscriberOnRefresh, onRefreshCallback); + + const onAcquiredCallback = async (_, data) => { + console.info(`${tcNumber} onAcquiredCallback data: ${JSON.stringify(data)}`); + expect(data.event).assertEqual(`FMS_FormOnAcquired_commonEvent`); + commonEvent.unsubscribe(subscriberOnAcquired, () => unsubscribeOnAcquiredCallback(tcNumber)); formId = data.data; - commonEvent.createSubscriber(onRefreshFormEvent).then(async (data) => { - console.debug("====>FMS_timedRefresh_0300 onRefreshFormEvent Subscriber====>"); - subscriberOnRefresh = data; - await commonEvent.subscribe(subscriberOnRefresh, onRefreshCallBack); - }); - console.log(`FMS_timedRefresh_0300 featureAbility.startAbility again start`); - featureAbility.startAbility({ + console.info(`${tcNumber} featureAbility.startAbility again start`); + await featureAbility.startAbility({ want: { bundleName: "com.ohos.st.formsystemhoste", abilityName: "com.ohos.st.formsystemhoste.MainAbility", parameters: { - "formId": "0", - "name": "Form_Js001", - "bundle": "com.form.formsystemtestservicea.hmservice", - "ability": "com.form.formsystemtestservicea.hmservice.MainAbility", - "moduleName": "entry", - "temporary": false, - "refreshForm": true, - "refreshId": formId, - "refreshTime": 5, - "isCreate": false + formId: "0", + name: "Form_Js001", + bundle: "com.form.formsystemtestservicea.hmservice", + ability: "com.form.formsystemtestservicea.hmservice.MainAbility", + moduleName: "entry", + temporary: false, + refreshForm: true, + refreshId: formId, + refreshTime: 5, + isCreate: false } } }).then((res: any) => { - console.log(`FMS_timedRefresh_0300 featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); }).catch((err: any) => { - console.log(`FMS_timedRefresh_0300 featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); }); - console.log(`FMS_timedRefresh_0300 featureAbility.startAbility again end`); - } - function unSubscribeOnAcquiredCallback() { - console.debug("====>FMS_timedRefresh_0300 OnAcquired UnSubscribe CallBack====>"); - } - - commonEvent.createSubscriber(onAcquiredForm_Event).then(async (data) => { - console.debug("====>FMS_timedRefresh_0300 Create OnAcquired Subscriber====>"); - subscriberOnAcquired = data; - await commonEvent.subscribe(subscriberOnAcquired, onAcquiredCallBack); - }); - console.log(`FMS_timedRefresh_0300 featureAbility.startAbility start`); + console.info(`${tcNumber} featureAbility.startAbility again end`); + }; + commonEvent.subscribe(subscriberOnAcquired, onAcquiredCallback); + + console.info(`${tcNumber} featureAbility.startAbility start`); await featureAbility.startAbility({ want: { bundleName: "com.ohos.st.formsystemhostf", abilityName: "com.ohos.st.formsystemhostf.MainAbility", parameters: { - "formId": "0", - "name": "Form_Js001", - "bundle": "com.form.formsystemtestservicea.hmservice", - "ability": "com.form.formsystemtestservicea.hmservice.MainAbility", - "moduleName": "entry", - "temporary": false, - "isCreate": true + formId: "0", + name: "Form_Js001", + bundle: "com.form.formsystemtestservicea.hmservice", + ability: "com.form.formsystemtestservicea.hmservice.MainAbility", + moduleName: "entry", + temporary: false, + isCreate: true } } }).then((res: any) => { - console.log(`FMS_timedRefresh_0300 featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); }).catch((err: any) => { - console.log(`FMS_timedRefresh_0300 featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); }); - console.log(`FMS_timedRefresh_0300 featureAbility.startAbility end`); + console.info(`${tcNumber} featureAbility.startAbility end`); }); + /** * @tc.number: FMS_timedRefresh_0400 * @tc.name: Form ID error (FormID does not exist) @@ -278,103 +230,79 @@ export default function test() { * 2.Verify the result of the dynamic timed refresh interface. */ it(`FMS_timedRefresh_0400`, 0, async (done) => { - console.log(`FMS_timedRefresh_0400 start`); - let subscriberOnRefresh; - let subscriberOnDeleted; + const tcNumber = `FMS_timedRefresh_0400`; let formId; - function delPublishCallBack() { - console.info("!!!====>FMS_timedRefresh_0400 delPublishCallBack====>"); - setTimeout(function () { - console.info('FMS_timedRefresh_0400 delPublishCallBack end'); - console.log(`FMS_timedRefresh_0400 end`); - done(); - }, 1000); - } - - function onRefreshCallBack(err, data) { - console.info("!!!====>FMS_timedRefresh_0400 onRefreshCallBack data:====>" + JSON.stringify(data)); - expect(data.event).assertEqual("FMS_FormDynamicRefresh_commonEvent"); - expect(data.data).assertEqual("9"); - commonEvent.unsubscribe(subscriberOnRefresh, unSubscribeOnRefreshCallback); - let commonEventPublishData = { + const onRefreshCallback = async (_, data) => { + console.info(`${tcNumber} onRefreshCallback data: ${JSON.stringify(data)}`); + expect(data.event).assertEqual(`FMS_FormDynamicRefresh_commonEvent`); + expect(data.data).assertEqual(`9`); + commonEvent.unsubscribe(subscriberOnRefresh, () => unsubscribeOnRefreshCallback(tcNumber)); + const commonEventPublishData = { bundleName: "com.ohos.st.formsystemhostc", data: formId }; - commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallBack); - } - function unSubscribeOnRefreshCallback() { - console.debug("====>FMS_timedRefresh_0400 unSubscribeOnRefreshCallback CallBack====>"); - } - - function onDeletedCallBack(err, data) { - console.info("!!!====>FMS_timedRefresh_0400 onDeletedCallBack data:====>" + JSON.stringify(data)); - expect(data.event).assertEqual("FMS_FormOnDeleted_commonEvent"); - expect(data.data).assertEqual("0"); - commonEvent.unsubscribe(subscriberOnDeleted, unSubscribeDeletedCallback) + commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallback(tcNumber, done)); + }; + commonEvent.subscribe(subscriberOnRefresh, onRefreshCallback); + + const onDeletedCallback = async (_, data) => { + console.info(`${tcNumber} onDeletedCallback data: ${JSON.stringify(data)}`); + expect(data.event).assertEqual(`FMS_FormOnDeleted_commonEvent`); + expect(data.data).assertEqual(`0`); + commonEvent.unsubscribe(subscriberOnDeleted, () => unsubscribeDeletedCallback(tcNumber)); formId = data.parameters.formId; - commonEvent.createSubscriber(onRefreshFormEvent).then(async (data) => { - console.debug("====>FMS_timedRefresh_0400 B onRefreshFormEvent Subscriber====>"); - subscriberOnRefresh = data; - await commonEvent.subscribe(subscriberOnRefresh, onRefreshCallBack); - }); - console.log(`FMS_timedRefresh_0400 featureAbility.startAbility again start`); - featureAbility.startAbility({ + console.info(`${tcNumber} featureAbility.startAbility again start`); + await featureAbility.startAbility({ want: { bundleName: "com.ohos.st.formsystemhoste", abilityName: "com.ohos.st.formsystemhoste.MainAbility", parameters: { - "formId": "0", - "name": "Form_Js001", - "bundle": "com.form.formsystemtestservicea.hmservice", - "ability": "com.form.formsystemtestservicea.hmservice.MainAbility", - "moduleName": "entry", - "temporary": false, - "refreshForm": true, - "refreshId": formId, - "refreshTime": 5, - "isCreate": false + formId: "0", + name: "Form_Js001", + bundle: "com.form.formsystemtestservicea.hmservice", + ability: "com.form.formsystemtestservicea.hmservice.MainAbility", + moduleName: "entry", + temporary: false, + refreshForm: true, + refreshId: formId, + refreshTime: 5, + isCreate: false } } }).then((res: any) => { - console.log(`FMS_timedRefresh_0400 featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); }).catch((err: any) => { - console.log(`FMS_timedRefresh_0400 featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); }); - console.log(`FMS_timedRefresh_0400 featureAbility.startAbility again end`); - } - function unSubscribeDeletedCallback() { - console.debug("====>FMS_timedRefresh_0400 unSubscribeDeletedCallback====>"); - } - commonEvent.createSubscriber(onDetetedFormEvent).then(async (data) => { - console.debug("====>FMS_releaseForm_1400 onDetetedFormEvent Subscriber====>"); - subscriberOnDeleted = data; - await commonEvent.subscribe(subscriberOnDeleted, onDeletedCallBack); - }); - console.log(`FMS_timedRefresh_0400 featureAbility.startAbility start`); + console.info(`${tcNumber} featureAbility.startAbility again end`); + }; + commonEvent.subscribe(subscriberOnDeleted, onDeletedCallback); + + console.info(`${tcNumber} featureAbility.startAbility start`); await featureAbility.startAbility({ want: { bundleName: "com.ohos.st.formsystemhostf", abilityName: "com.ohos.st.formsystemhostf.MainAbility", parameters: { - "formId": "0", - "name": "Form_Js001", - "bundle": "com.form.formsystemtestservicea.hmservice", - "ability": "com.form.formsystemtestservicea.hmservice.MainAbility", - "moduleName": "entry", - "temporary": false, - "deleteForm": true, + formId: "0", + name: "Form_Js001", + bundle: "com.form.formsystemtestservicea.hmservice", + ability: "com.form.formsystemtestservicea.hmservice.MainAbility", + moduleName: "entry", + temporary: false, + deleteForm: true, "deleteId": "self", - "isCreate": true + isCreate: true } } }).then((res: any) => { - console.log(`FMS_timedRefresh_0400 featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); }).catch((err: any) => { - console.log(`FMS_timedRefresh_0400 featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); }); - console.log(`FMS_timedRefresh_0400 featureAbility.startAbility end`); + console.info(`${tcNumber} featureAbility.startAbility end`); }); /** @@ -384,63 +312,44 @@ export default function test() { * 2.Verify the result of the dynamic timed refresh interface. */ it(`FMS_timedRefresh_0500`, 0, async (done) => { - console.log(`FMS_timedRefresh_0500 start`); - let subscriberOnRefresh; - let formId; - - function delPublishCallBack() { - console.info("!!!====>FMS_timedRefresh_0500 delPublishCallBack====>"); - setTimeout(function () { - console.info('FMS_timedRefresh_0500 delPublishCallBack end'); - console.log(`FMS_timedRefresh_0500 end`); - done(); - }, 1000) - } - - function onRefreshCallBack(err, data) { - console.info("!!!====>FMS_timedRefresh_0500 onRefreshCallBack data:====>" + JSON.stringify(data)); - expect(data.event).assertEqual("FMS_FormDynamicRefresh_commonEvent"); - expect(data.data).assertEqual("7"); - commonEvent.unsubscribe(subscriberOnRefresh, unSubscribeOnRefreshCallback) - - let commonEventPublishData = { + const tcNumber = `FMS_timedRefresh_0500`; + + const onRefreshCallback = async (_, data) => { + console.info(`${tcNumber} onRefreshCallback data: ${JSON.stringify(data)}`); + expect(data.event).assertEqual(`FMS_FormDynamicRefresh_commonEvent`); + expect(data.data).assertEqual(`7`); + commonEvent.unsubscribe(subscriberOnRefresh, () => unsubscribeOnRefreshCallback(tcNumber)); + const commonEventPublishData = { data: data.parameters.formId }; - commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallBack); - } - function unSubscribeOnRefreshCallback() { - console.debug("====>FMS_timedRefresh_0500 unSubscribeOnRefreshCallback CallBack====>"); - } - - commonEvent.createSubscriber(onRefreshFormEvent).then(async (data) => { - console.debug("====>FMS_timedRefresh_0500 onRefreshFormEvent Subscriber====>"); - subscriberOnRefresh = data; - await commonEvent.subscribe(subscriberOnRefresh, onRefreshCallBack); - }); - console.log(`FMS_timedRefresh_0500 featureAbility.startAbility start`); + commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallback(tcNumber, done)); + }; + commonEvent.subscribe(subscriberOnRefresh, onRefreshCallback); + + console.info(`${tcNumber} featureAbility.startAbility start`); await featureAbility.startAbility({ want: { bundleName: "com.ohos.st.formsystemhoste", abilityName: "com.ohos.st.formsystemhoste.MainAbility", parameters: { - "formId": "0", - "name": "Form_Js001", - "bundle": "com.form.formsystemtestservicea.hmservice", - "ability": "com.form.formsystemtestservicea.hmservice.MainAbility", - "moduleName": "entry", - "temporary": false, - "refreshForm": true, - "refreshId": "self", - "refreshTime": 1, - "isCreate": true + formId: "0", + name: "Form_Js001", + bundle: "com.form.formsystemtestservicea.hmservice", + ability: "com.form.formsystemtestservicea.hmservice.MainAbility", + moduleName: "entry", + temporary: false, + refreshForm: true, + refreshId: "self", + refreshTime: 1, + isCreate: true } } }).then((res: any) => { - console.log(`FMS_timedRefresh_0500 featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); }).catch((err: any) => { - console.log(`FMS_timedRefresh_0500 featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); }); - console.log(`FMS_timedRefresh_0500 featureAbility.startAbility end`); + console.info(`${tcNumber} featureAbility.startAbility end`); }); /** @@ -450,66 +359,78 @@ export default function test() { * 2.Verify the result of the dynamic timed refresh interface. */ it(`FMS_timedRefresh_0600`, 0, async (done) => { - console.log(`FMS_timedRefresh_0600 start`); - let formId; - let subscriberSupply; - - function delPublishCallBack() { - console.info("!!!====>FMS_timedRefresh_0600 delPublishCallBack====>"); - setTimeout(function () { - console.info('FMS_timedRefresh_0600 delPublishCallBack end'); - console.log(`FMS_timedRefresh_0600 end`); - done(); - }, 1000) - } - - function onRefreshCallBack(err, data) { - console.info("!!!====>FMS_timedRefresh_0600 onRefreshCallBack data:====>" + JSON.stringify(data)); - expect(data.event).assertEqual("FMS_FormSupply_commonEvent"); - if (data.parameters.kind == "onVisibilityChange") { - console.info("!!!====>FMS_timedRefresh_0600 onRefreshCallBack kind:====>" + data.parameters.kind); - console.info("!!!====>FMS_timedRefresh_0600 onRefreshCallBack error:====>" + data.parameters.errorData); - expect(data.parameters.errorData).assertEqual("0"); - commonEvent.unsubscribe(subscriberSupply, unSubscribeOnRefreshCallback) + const tcNumber = `FMS_timedRefresh_0600`; - let commonEventPublishData = { + const onSupplyCallback = async (_, data) => { + console.info(`${tcNumber} onSupplyCallback data: ${JSON.stringify(data)}`); + expect(data.event).assertEqual(`FMS_FormSupply_commonEvent`); + if (data.parameters.kind == "onVisibilityChange") { + console.info(`${tcNumber} onSupplyCallback kind: data.parameters.kind`); + console.info(`${tcNumber} onSupplyCallback error: data.parameters.errorData`); + expect(data.parameters.errorData).assertEqual(`0`); + commonEvent.unsubscribe(subscriberSupply, () => unsubscribeSupplyCallback(tcNumber)); + const commonEventPublishData = { data: data.parameters.formId }; - commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallBack); + commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallback(tcNumber, done)); } - } - function unSubscribeOnRefreshCallback() { - console.debug("====>FMS_timedRefresh_0600 unSubscribeOnRefreshCallback CallBack====>"); - } - - commonEvent.createSubscriber(onSupplyEvent).then(async (data) => { - console.debug("====>FMS_timedRefresh_0600 onSupplyEvent Subscriber====>"); - subscriberSupply = data; - await commonEvent.subscribe(subscriberSupply, onRefreshCallBack); - }); - console.log(`FMS_timedRefresh_0600 featureAbility.startAbility start`); + }; + commonEvent.subscribe(subscriberSupply, onSupplyCallback); + + console.info(`${tcNumber} featureAbility.startAbility start`); await featureAbility.startAbility({ want: { bundleName: "com.ohos.st.formsystemhoste", abilityName: "com.ohos.st.formsystemhoste.MainAbility", parameters: { - "formId": "0", - "name": "Form_Js001", - "bundle": "com.form.formsystemtestservicec.hmservice", - "ability": "com.form.formsystemtestservicec.hmservice.MainAbility", - "moduleName": "entry", - "temporary": false, + formId: "0", + name: "Form_Js001", + bundle: "com.form.formsystemtestservicec.hmservice", + ability: "com.form.formsystemtestservicec.hmservice.MainAbility", + moduleName: "entry", + temporary: false, "notifyVisibleForms": true, "notifyVisibleId": "self", - "isCreate": true + isCreate: true } } }).then((res: any) => { - console.log(`FMS_timedRefresh_0600 featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost res: ${JSON.stringify(res)}`); }).catch((err: any) => { - console.log(`FMS_timedRefresh_0600 featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); + console.info(`${tcNumber} featureAbility.startAbilityhost error: ${JSON.stringify(err)}`); }); - console.log(`FMS_timedRefresh_0600 featureAbility.startAbility end`); + console.info(`${tcNumber} featureAbility.startAbility end`); }); }); } + +const sleep = async delay => { + return new Promise((resolve, _) => { + setTimeout(async () => { + resolve(0); + }, delay); + }); +}; + +const delPublishCallback = async (tcNumber, done) => { + await sleep(1000); + console.info(`${tcNumber} delPublishCallback end`); + console.info(`${tcNumber} end`); + done(); +}; + +const unsubscribeOnAcquiredCallback = (tcNumber) => { + console.info(`${tcNumber} Unsubscribe OnAcquired Callback`); +}; + +const unsubscribeDeletedCallback = (tcNumber) => { + console.info(`${tcNumber} Unsubscribe Deleted Callback`); +}; + +const unsubscribeSupplyCallback = (tcNumber) => { + console.info(`${tcNumber} Unsubscribe Supply Callback`); +}; + +const unsubscribeOnRefreshCallback = (tcNumber) => { + console.info(`${tcNumber} Unsubscribe OnRefresh Callback`); +}; diff --git a/aafwk/aafwk_standard/formmanager/fa/formsystemtest_ets/formreleasetest/entry/src/main/ets/MainAbility/model/FormViewModel.ets b/aafwk/aafwk_standard/formmanager/fa/formsystemtest_ets/formreleasetest/entry/src/main/ets/MainAbility/model/FormViewModel.ets deleted file mode 100644 index 659108ce439cf2b927fdf1801539f3dddbd851d6..0000000000000000000000000000000000000000 --- a/aafwk/aafwk_standard/formmanager/fa/formsystemtest_ets/formreleasetest/entry/src/main/ets/MainAbility/model/FormViewModel.ets +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import formManager from '@ohos.ability.formmanager'; -import bundleManager from '@ohos.bundle'; - -export default class FormViewModel { - private static sFormViewModel: FormViewModel = null; - - public static getInstance(): FormViewModel { - if (FormViewModel.sFormViewModel == null) { - FormViewModel.sFormViewModel = new FormViewModel(); - } - return FormViewModel.sFormViewModel; - } - - public async requestForm(formId: string) { - formManager.requestForm(formId) - .then((data) => { - console.info( '[FormComponent] requestForm result:' + data); - }); - } - - public async deleteCard(formId: string) { - formManager.deleteForm(formId) - .then((data) => { - console.info('[FormComponent] deleteForm result:' + data); - }); - } - - public async releaseCard(formId: string) { - formManager.releaseForm(formId) - .then((data) => { - console.info('[FormComponent] releaseForm result:' + data); - }); - } - - public async castTempToNormal(formId: string) { - formManager.castTempForm(formId) - .then((data) => { - console.info('[FormComponent] castTempToNormal result:' + data); - }); - } - - public async enableCard(formId: string) { - formManager.enableFormsUpdate([formId]) - .then((data) => { - console.info('[FormComponent] enableFormsUpdate result:' + data); - }); - } - - public async disableCard(formId: string) { - formManager.disableFormsUpdate([formId]) - .then((data) => { - console.info('[FormComponent] disableCard result:' + data); - }); - } - - public async changeCardVisible(formId: string, isVisible: boolean) { - if (isVisible) { - formManager.notifyVisibleForms([formId]) - .then((data) => { - console.info('[FormComponent] changeCardVisible result:' + data + ', isVisible:' + isVisible); - }); - } else { - formManager.notifyInvisibleForms([formId]) - .then((data) => { - console.info('[FormComponent] changeCardVisible result:' + data + ', isVisible:' + isVisible); - }); - } - } - - public async isFmsReady() { - formManager.isSystemReady() - .then((data) => { - console.info('[FormComponent] isFmsReady result:' + data); - }); - } - - public async getAllFormsInfo() { - console.info("[FormComponent] getAllFormsInfo start"); - formManager.getAllFormsInfo() - .then((data) => { - console.info('[FormComponent] getAllFormsInfo result:' + JSON.stringify(data)); - }) - .catch((err) => { - console.info('[FormComponent] getAllFormsInfo error:' + JSON.stringify(err)); - }); - console.info("[FormComponent] getAllFormsInfo end"); - } - - public async getFormsInfoByApp(bundle: string) { - formManager.getFormsInfo(bundle) - .then((data) => { - console.info('[FormComponent] getFormsInfoByApp result:' + JSON.stringify(data)); - }); - } - - public async getFormsInfoByModule(bundle: string, moduleName: string) { - formManager.getFormsInfo(bundle, moduleName) - .then((data) => { - console.info('[FormComponent] getFormsInfoByModule result:' + JSON.stringify(data)); - }); - } - - public async clearFormUserCache() { - bundleManager.cleanBundleCacheFiles('com.ohos.myapplicationform') - .then((data) => { - console.info('[FormComponent] cleanBundleCacheFiles result:' + JSON.stringify(data)); - }); - } - - public async clearFormProviderCache(bundle: string) { - bundleManager.cleanBundleCacheFiles(bundle) - .then((data) => { - console.info('[FormComponent] cleanBundleCacheFiles result:' + JSON.stringify(data)); - }); - } -} \ No newline at end of file diff --git a/aafwk/aafwk_standard/formmanager/fa/formsystemtest_ets/formreleasetest/entry/src/main/ets/MainAbility/test/FmsReleaseForm.test.ets b/aafwk/aafwk_standard/formmanager/fa/formsystemtest_ets/formreleasetest/entry/src/main/ets/MainAbility/test/FmsReleaseForm.test.ets index b56ad4efd77b6742c4c4b788fc5a61098ffe2f47..ad9b44ba3cb08b9a4ef4eda585035101ca7a93dd 100644 --- a/aafwk/aafwk_standard/formmanager/fa/formsystemtest_ets/formreleasetest/entry/src/main/ets/MainAbility/test/FmsReleaseForm.test.ets +++ b/aafwk/aafwk_standard/formmanager/fa/formsystemtest_ets/formreleasetest/entry/src/main/ets/MainAbility/test/FmsReleaseForm.test.ets @@ -13,37 +13,38 @@ * limitations under the License. */ -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "deccjsunit/index.ets" import featureAbility from "@ohos.ability.featureAbility"; -import commonEvent from '@ohos.commonEvent' +import commonEvent from '@ohos.commonEvent'; +import { beforeAll, beforeEach, describe, expect, it } from "deccjsunit/index.ets"; -var onErrorForm_Event = { - events: ["FMS_FormOnError_commonEvent"], -}; var onAcquiredForm_Event = { events: ["FMS_FormOnAcquired_commonEvent"], }; - -var onDetetedFormEvent = { +var onDeletedFormEvent = { events: ["FMS_FormOnDeleted_commonEvent"], }; var onReleasedFormEvent = { events: ["FMS_FormOnReleased_commonEvent"], }; - -var onSupplyEvent = { - events: ["FMS_FormSupply_commonEvent"], -}; - var deleteForm_Event = "FMS_FormDelete_commonEvent"; +var subscriberOnAcquired; +var subscriberOnDeleted; +var subscriberOnReleased; + export default function test() { - describe(`FmsDeleteFormTest`, () => { + describe(`FmsReleaseFormTest`, () => { beforeAll(async (done) => { done(); }) + beforeEach(async () => { + subscriberOnAcquired = await commonEvent.createSubscriber(onAcquiredForm_Event); + subscriberOnDeleted = await commonEvent.createSubscriber(onDeletedFormEvent); + subscriberOnReleased = await commonEvent.createSubscriber(onReleasedFormEvent); + }) + /** * @tc.number: FMS_releaseForm_0200 * @tc.name: host does not have permission @@ -52,43 +53,25 @@ export default function test() { */ it(`FMS_releaseForm_0200`, 0, async (done) => { console.log(`FMS_releaseForm_0200 start`); - let subscriberOnReleased; - let subscriberOnAcquired; let formId; - function delPublishCallBack() { - console.info("!!!====>FMS_releaseForm_0200 delPublishCallBack====>"); - setTimeout(function () { - console.info('FMS_releaseForm_0200 delPublishCallBack end'); - console.log(`FMS_releaseForm_0200 end`); - done(); - }, 1000) - } - - function onReleasedCallBack(err, data) { + function onReleasedCallBack(_, data) { console.info("!!!====>FMS_releaseForm_0200 onReleasedCallBack data:====>" + JSON.stringify(data)); expect(data.event).assertEqual("FMS_FormOnReleased_commonEvent"); expect(data.data != "0").assertEqual(true); - commonEvent.unsubscribe(subscriberOnReleased, unSubscribeOnReleasedCallback); + commonEvent.unsubscribe(subscriberOnReleased, () => unsubscribeOnReleasedCallback("FMS_releaseForm_0200")); let commonEventPublishData = { data: formId }; - commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallBack); + commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallBack("FMS_releaseForm_0200", done)); } - function unSubscribeOnReleasedCallback() { - console.debug("====>FMS_releaseForm_0200 unSubscribeOnReleasedCallback====>"); - } - - function onAcquiredCallBack(err, data) { + + function onAcquiredCallBack(_, data) { console.info("!!!====>FMS_releaseForm_0200 onAcquiredCallBack data:====>" + JSON.stringify(data)); - expect(data.event).assertEqual("FMS_FormOnAcquired_commonEvent"); - commonEvent.unsubscribe(subscriberOnAcquired, unSubscribeOnAcquiredCallback) + expect(data.event).assertEqual("FMS_FormOnAcquired_commonEvent"); + commonEvent.unsubscribe(subscriberOnAcquired, () => unsubscribeOnAcquiredCallback("FMS_releaseForm_0200")) formId = data.data; - commonEvent.createSubscriber(onReleasedFormEvent).then(async (data) => { - console.debug("====>FMS_releaseForm_0200 onReleasedFormEvent Subscriber====>"); - subscriberOnReleased = data; - await commonEvent.subscribe(subscriberOnReleased, onReleasedCallBack); - }); + commonEvent.subscribe(subscriberOnReleased, onReleasedCallBack); console.log(`FMS_releaseForm_0200 featureAbility.startAbility again start`); featureAbility.startAbility({ @@ -114,15 +97,8 @@ export default function test() { }); console.log(`FMS_releaseForm_0200 featureAbility.startAbility again end`); } - function unSubscribeOnAcquiredCallback() { - console.debug("====>FMS_releaseForm_0200 OnAcquired UnSubscribe CallBack====>"); - } - - commonEvent.createSubscriber(onAcquiredForm_Event).then(async (data) => { - console.debug("====>FMS_releaseForm_0200 Create OnAcquired Subscriber====>"); - subscriberOnAcquired = data; - await commonEvent.subscribe(subscriberOnAcquired, onAcquiredCallBack); - }); + commonEvent.subscribe(subscriberOnAcquired, onAcquiredCallBack); + console.log(`FMS_releaseForm_0200 featureAbility.startAbility start`); await featureAbility.startAbility({ want: { @@ -153,28 +129,19 @@ export default function test() { */ it(`FMS_releaseForm_0300`, 0, async (done) => { console.log(`FMS_releaseForm_0300 start`); - let subscriberOnReleased; - let subscriberOnAcquired; - function onReleasedCallBack(err, data) { + function onReleasedCallBack(_, data) { console.info("!!!====>FMS_releaseForm_0300 onReleasedCallBack data:====>" + JSON.stringify(data)); expect(data.event).assertEqual("FMS_FormOnReleased_commonEvent"); expect(data.data != "0").assertEqual(true); - commonEvent.unsubscribe(subscriberOnReleased, unSubscribeOnReleasedCallback); - setTimeout(function () { - console.info('FMS_releaseForm_0300 delPublishCallBack end'); + commonEvent.unsubscribe(subscriberOnReleased, () => unsubscribeOnReleasedCallback("FMS_releaseForm_0300")); + setTimeout(function () { + console.info('FMS_releaseForm_0300 onReleasedCallBack end'); console.log(`FMS_releaseForm_0300 end`); done(); }, 100); } - function unSubscribeOnReleasedCallback() { - console.debug("====>FMS_releaseForm_0300 unSubscribeOnReleasedCallback CallBack====>"); - } - commonEvent.createSubscriber(onReleasedFormEvent).then(async (data) => { - console.debug("====>FMS_releaseForm_0300 onReleasedFormEvent Subscriber====>"); - subscriberOnReleased = data; - await commonEvent.subscribe(subscriberOnReleased, onReleasedCallBack); - }); + commonEvent.subscribe(subscriberOnReleased, onReleasedCallBack); console.log(`FMS_releaseForm_0300 featureAbility.startAbility start`); await featureAbility.startAbility({ @@ -208,29 +175,19 @@ export default function test() { */ it(`FMS_releaseForm_0400`, 0, async (done) => { console.log(`FMS_releaseForm_0400 start`); - let subscriberOnReleased; - let subscriberOnAcquired; - function onReleaseCallBack(err, data) { + function onReleaseCallBack(_, data) { console.info("!!!====>FMS_releaseForm_0400 onReleaseCallBack data:====>" + JSON.stringify(data)); expect(data.event).assertEqual("FMS_FormOnReleased_commonEvent"); expect(data.data != "0").assertEqual(true); - commonEvent.unsubscribe(subscriberOnReleased, unSubscribeOnReleasedCallback); + commonEvent.unsubscribe(subscriberOnReleased, () => unsubscribeOnReleasedCallback("FMS_releaseForm_0400")); setTimeout(function () { - console.info('FMS_releaseForm_0400 delPublishCallBack end'); + console.info('FMS_releaseForm_0400 onReleaseCallBack end'); console.log(`FMS_releaseForm_0400 end`); done(); }, 100); } - function unSubscribeOnReleasedCallback() { - console.debug("====>FMS_releaseForm_0400 unSubscribeOnReleasedCallback CallBack====>"); - } - commonEvent.createSubscriber(onReleasedFormEvent).then(async (data) => { - console.debug("====>FMS_releaseForm_0400 onReleasedFormEvent Subscriber====>"); - subscriberOnReleased = data; - await commonEvent.subscribe(subscriberOnReleased, onReleaseCallBack); - }); - + commonEvent.subscribe(subscriberOnReleased, onReleaseCallBack); console.log(`FMS_releaseForm_0400 featureAbility.startAbility start`); await featureAbility.startAbility({ want: { @@ -264,44 +221,24 @@ export default function test() { */ it(`FMS_releaseForm_0500`, 0, async (done) => { console.log(`FMS_releaseForm_0500 start`); - let subscriberOnReleased; - let subscriberOnAcquired; let formId; - function delPublishCallBack() { - console.info("!!!====>FMS_releaseForm_0500 delPublishCallBack====>"); - setTimeout(function () { - console.info('FMS_releaseForm_0500 delPublishCallBack end'); - console.log(`FMS_releaseForm_0500 end`); - done(); - }, 1000) - } - - function onReleasedCallBack(err, data) { + function onReleasedCallBack(_, data) { console.info("!!!====>FMS_releaseForm_0500 onReleasedCallBack data:====>" + JSON.stringify(data)); expect(data.event).assertEqual("FMS_FormOnReleased_commonEvent"); expect(data.data != "0").assertEqual(true); - commonEvent.unsubscribe(subscriberOnReleased, unSubscribeOnReleasedCallback); + commonEvent.unsubscribe(subscriberOnReleased, () => unsubscribeOnReleasedCallback("FMS_releaseForm_0500")); let commonEventPublishData = { data: formId }; - commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallBack); + commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallBack("FMS_releaseForm_0500", done)); } - function unSubscribeOnReleasedCallback() { - console.debug("====>FMS_releaseForm_0500 unSubscribeOnReleasedCallback CallBack====>"); - } - - function onAcquiredCallBack(err, data) { + function onAcquiredCallBack(_, data) { console.info("!!!====>FMS_releaseForm_0500 onAcquiredCallBack data:====>" + JSON.stringify(data)); - expect(data.event).assertEqual("FMS_FormOnAcquired_commonEvent"); - commonEvent.unsubscribe(subscriberOnAcquired, unSubscribeOnAcquiredCallback) + expect(data.event).assertEqual("FMS_FormOnAcquired_commonEvent"); + commonEvent.unsubscribe(subscriberOnAcquired, () => unsubscribeOnAcquiredCallback("FMS_releaseForm_0500")); formId = data.data; - commonEvent.createSubscriber(onReleasedFormEvent).then(async (data) => { - console.debug("====>FMS_releaseForm_0500 onReleasedFormEvent Subscriber====>"); - subscriberOnReleased = data; - await commonEvent.subscribe(subscriberOnReleased, onReleasedCallBack); - }); - + commonEvent.subscribe(subscriberOnReleased, onReleasedCallBack); console.log(`FMS_releaseForm_0500 featureAbility.startAbility again start`); featureAbility.startAbility({ want: { @@ -326,15 +263,7 @@ export default function test() { }); console.log(`FMS_releaseForm_0500 featureAbility.startAbility again end`); } - function unSubscribeOnAcquiredCallback() { - console.debug("====>FMS_releaseForm_0500 OnAcquired UnSubscribe CallBack====>"); - } - - commonEvent.createSubscriber(onAcquiredForm_Event).then(async (data) => { - console.debug("====>FMS_releaseForm_0500 Create OnAcquired Subscriber====>"); - subscriberOnAcquired = data; - await commonEvent.subscribe(subscriberOnAcquired, onAcquiredCallBack); - }); + commonEvent.subscribe(subscriberOnAcquired, onAcquiredCallBack); console.log(`FMS_releaseForm_0500 featureAbility.startAbility start`); await featureAbility.startAbility({ want: { @@ -366,45 +295,26 @@ export default function test() { */ it(`FMS_releaseForm_0600`, 0, async (done) => { console.log(`FMS_releaseForm_0600 start`); - let subscriberOnReleased; - let subscriberOnDeleted; let formId; - function delPublishCallBack() { - console.info("!!!====>FMS_releaseForm_0600 delPublishCallBack====>"); - setTimeout(function () { - console.info('FMS_releaseForm_0600 delPublishCallBack end'); - console.log(`FMS_releaseForm_0600 end`); - done(); - }, 1000); - } - - function onReleasedCallBack(err, data) { + function onReleasedCallBack(_, data) { console.info("!!!====>FMS_releaseForm_0600 onReleasedCallBack data:====>" + JSON.stringify(data)); expect(data.event).assertEqual("FMS_FormOnReleased_commonEvent"); expect(data.data != "0").assertEqual(true); - commonEvent.unsubscribe(subscriberOnReleased, unSubscribeOnReleasedCallback); + commonEvent.unsubscribe(subscriberOnReleased, () => unsubscribeOnReleasedCallback("FMS_releaseForm_0600")); let commonEventPublishData = { bundleName: "com.ohos.st.formsystemhostc", data: formId }; - commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallBack); + commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallBack("FMS_releaseForm_0600", done)); } - function unSubscribeOnReleasedCallback() { - console.debug("====>FMS_releaseForm_0600 unSubscribeOnReleasedCallback CallBack====>"); - } - - function onDeletedCallBack(err, data) { + function onDeletedCallBack(_, data) { console.info("!!!====>FMS_releaseForm_0600 onDeletedCallBack data:====>" + JSON.stringify(data)); expect(data.event).assertEqual("FMS_FormOnDeleted_commonEvent"); expect(data.data).assertEqual("0"); - commonEvent.unsubscribe(subscriberOnDeleted, unSubscribeDeletedCallback) + commonEvent.unsubscribe(subscriberOnDeleted, unsubscribeDeletedCallback) formId = data.parameters.formId; - commonEvent.createSubscriber(onReleasedFormEvent).then(async (data) => { - console.debug("====>FMS_releaseForm_0600 B onReleasedFormEvent Subscriber====>"); - subscriberOnReleased = data; - await commonEvent.subscribe(subscriberOnReleased, onReleasedCallBack); - }); + commonEvent.subscribe(subscriberOnReleased, onReleasedCallBack); console.log(`FMS_releaseForm_0600 featureAbility.startAbility again start`); featureAbility.startAbility({ @@ -430,14 +340,10 @@ export default function test() { }); console.log(`FMS_releaseForm_0600 featureAbility.startAbility again end`); } - function unSubscribeDeletedCallback() { - console.debug("====>FMS_releaseForm_0600 unSubscribeDeletedCallback====>"); + function unsubscribeDeletedCallback() { + console.debug("====>FMS_releaseForm_0600 unsubscribeDeletedCallback====>"); } - commonEvent.createSubscriber(onDetetedFormEvent).then(async (data) => { - console.debug("====>FMS_releaseForm_0600 onDetetedFormEvent Subscriber====>"); - subscriberOnDeleted = data; - await commonEvent.subscribe(subscriberOnDeleted, onDeletedCallBack); - }); + commonEvent.subscribe(subscriberOnDeleted, onDeletedCallBack); console.log(`FMS_releaseForm_0600 featureAbility.startAbility start`); await featureAbility.startAbility({ want: { @@ -470,8 +376,6 @@ export default function test() { */ it(`FMS_releaseForm_1300`, 0, async (done) => { console.log(`FMS_releaseForm_1300 start`); - let subscriberOnReleased; - let subscriberOnAcquired; let formIdList = []; let releasedIdList = []; let formCount = 2; @@ -483,13 +387,13 @@ export default function test() { if(delCount == formCount) { setTimeout(function () { console.info('FMS_releaseForm_1300 delPublishCallBack end'); - console.log(`FMS_releaseForm_1300 end`); + console.log(`FMS_releaseForm_1300 end`); done(); }, 1000); } } - function onReleasedCallBack(err, data) { + function onReleasedCallBack(_, data) { console.info("!!!====>FMS_releaseForm_1300 onReleasedCallBack data:====>" + JSON.stringify(data)); expect(data.event).assertEqual("FMS_FormOnReleased_commonEvent"); expect(data.data).assertEqual("0"); @@ -500,7 +404,7 @@ export default function test() { } }); if(releasedIdList.length == formCount) { - commonEvent.unsubscribe(subscriberOnReleased, unSubscribeOnReleasedCallback); + commonEvent.unsubscribe(subscriberOnReleased, () => unsubscribeOnReleasedCallback("FMS_releaseForm_1300")); for(var iIndex = 0; iIndex < releasedIdList.length; iIndex++) { let commonEventPublishData = { bundleName: "com.ohos.st.formsystemhostc", @@ -510,16 +414,9 @@ export default function test() { } } } - function unSubscribeOnReleasedCallback() { - console.debug("====>FMS_releaseForm_1300 unSubscribeOnReleasedCallback CallBack====>"); - } function releaseForms() { console.debug("====>FMS_releaseForm_1300 releaseForms====>"); - commonEvent.createSubscriber(onReleasedFormEvent).then(async (data) => { - console.debug("====>FMS_releaseForm_1300 B onReleasedFormEvent Subscriber====>"); - subscriberOnReleased = data; - await commonEvent.subscribe(subscriberOnReleased, onReleasedCallBack); - }); + commonEvent.subscribe(subscriberOnReleased, onReleasedCallBack); for(var iIndex = 0; iIndex < formIdList.length; iIndex++) { console.log(`FMS_releaseForm_1300 featureAbility.startAbility start`); featureAbility.startAbility({ @@ -546,29 +443,25 @@ export default function test() { console.log(`FMS_releaseForm_1300 featureAbility.startAbility end`); } } - function onAcquiredCallBack1(err, data) { + function onAcquiredCallBack1(_, data) { console.info("!!!====>FMS_releaseForm_1300 onAcquiredCallBack data:====>" + JSON.stringify(data)); expect(data.event).assertEqual("FMS_FormOnAcquired_commonEvent"); - commonEvent.unsubscribe(subscriberOnAcquired, unSubscribeOnAcquiredCallback); + commonEvent.unsubscribe(subscriberOnAcquired, () => unsubscribeOnAcquiredCallback("FMS_releaseForm_1300")); formIdList.push(data.data); releaseForms(); } - function onAcquiredCallBack(err, data) { + async function onAcquiredCallBack(_, data) { console.info("!!!====>FMS_releaseForm_1300 onAcquiredCallBack data:====>" + JSON.stringify(data)); expect(data.event).assertEqual("FMS_FormOnAcquired_commonEvent"); - commonEvent.unsubscribe(subscriberOnAcquired, unSubscribeOnAcquiredCallback); + commonEvent.unsubscribe(subscriberOnAcquired, () => unsubscribeOnAcquiredCallback("FMS_releaseForm_1300")); formIdList.push(data.data); + subscriberOnAcquired = await commonEvent.createSubscriber(onAcquiredForm_Event); + commonEvent.subscribe(subscriberOnAcquired, onAcquiredCallBack1); - commonEvent.createSubscriber(onAcquiredForm_Event).then(async (data) => { - console.debug("====>FMS_releaseForm_1300 Create OnAcquired Subscriber====>"); - subscriberOnAcquired = data; - await commonEvent.subscribe(subscriberOnAcquired, onAcquiredCallBack1); - }); - console.log(`FMS_releaseForm_1300 featureAbility.startAbility start`); - featureAbility.startAbility({ + await featureAbility.startAbility({ want: { bundleName: "com.ohos.st.formsystemhostc", abilityName: "com.ohos.st.formsystemhostc.MainAbility", @@ -589,15 +482,8 @@ export default function test() { }); console.log(`FMS_releaseForm_1300 featureAbility.startAbility end`); } - function unSubscribeOnAcquiredCallback() { - console.debug("====>FMS_releaseForm_1300 OnAcquired UnSubscribe CallBack====>"); - } - commonEvent.createSubscriber(onAcquiredForm_Event).then(async (data) => { - console.debug("====>FMS_releaseForm_1300 Create OnAcquired Subscriber====>"); - subscriberOnAcquired = data; - await commonEvent.subscribe(subscriberOnAcquired, onAcquiredCallBack); - }); - + commonEvent.subscribe(subscriberOnAcquired, onAcquiredCallBack); + console.log(`FMS_releaseForm_1300 featureAbility.startAbility start`); await featureAbility.startAbility({ want: { @@ -629,38 +515,20 @@ export default function test() { */ it(`FMS_releaseForm_1400`, 0, async (done) => { console.log(`FMS_releaseForm_1400 start`); - let subscriberOnReleased; - function delPublishCallBack() { - console.info("!!!====>FMS_releaseForm_1400 delPublishCallBack====>"); - setTimeout(function () { - console.info('FMS_releaseForm_1400 delPublishCallBack end'); - console.log(`FMS_releaseForm_1400 end`); - done(); - }, 1000); - } - - function unSubscribeOnReleasedCallback() { - console.debug("====>FMS_releaseForm_1400 unSubscribeOnReleasedCallback CallBack====>"); - } - - function onReleasedCallBack(err, data) { + function onReleasedCallBack(_, data) { console.info("!!!====>FMS_releaseForm_1400 onReleasedCallBack data:====>" + JSON.stringify(data)); expect(data.event).assertEqual("FMS_FormOnReleased_commonEvent"); expect(data.data).assertEqual("0"); - commonEvent.unsubscribe(subscriberOnReleased, unSubscribeOnReleasedCallback); + commonEvent.unsubscribe(subscriberOnReleased, () => unsubscribeOnReleasedCallback("FMS_releaseForm_1400")); let commonEventPublishData = { bundleName: "com.ohos.st.formsystemhostc", data: data.parameters.formId }; - commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallBack); + commonEvent.publish(deleteForm_Event, commonEventPublishData, (delPublishCallBack("FMS_releaseForm_1400", done))); } - commonEvent.createSubscriber(onReleasedFormEvent).then(async (data) => { - console.debug("====>FMS_releaseForm_1400 onReleasedFormEvent Subscriber====>"); - subscriberOnReleased = data; - await commonEvent.subscribe(subscriberOnReleased, onReleasedCallBack); - }); + commonEvent.subscribe(subscriberOnReleased, onReleasedCallBack); console.log(`FMS_releaseForm_1400 featureAbility.startAbility start`); await featureAbility.startAbility({ @@ -688,3 +556,19 @@ export default function test() { }); }); } + +const delPublishCallBack = async (tcNumber, done) { + console.info(`${tcNumber} delPublishCallBack start`); + setTimeout(function () { + console.info(`${tcNumber} delPublishCallBack end`); + done(); + }, 1000); +} + +const unsubscribeOnReleasedCallback = (tcNumber) { + console.debug(`====>${tcNumber} unsubscribeOnReleasedCallback====>`); +} + +const unsubscribeOnAcquiredCallback = (tcNumber) { + console.debug(`====>${tcNumber} unsubscribeOnAcquiredCallback====>`); +} diff --git a/aafwk/aafwk_standard/formmanager/fa/formsystemtest_ets/formupdatefreshtest/entry/src/main/ets/MainAbility/model/FormViewModel.ets b/aafwk/aafwk_standard/formmanager/fa/formsystemtest_ets/formupdatefreshtest/entry/src/main/ets/MainAbility/model/FormViewModel.ets deleted file mode 100644 index 659108ce439cf2b927fdf1801539f3dddbd851d6..0000000000000000000000000000000000000000 --- a/aafwk/aafwk_standard/formmanager/fa/formsystemtest_ets/formupdatefreshtest/entry/src/main/ets/MainAbility/model/FormViewModel.ets +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import formManager from '@ohos.ability.formmanager'; -import bundleManager from '@ohos.bundle'; - -export default class FormViewModel { - private static sFormViewModel: FormViewModel = null; - - public static getInstance(): FormViewModel { - if (FormViewModel.sFormViewModel == null) { - FormViewModel.sFormViewModel = new FormViewModel(); - } - return FormViewModel.sFormViewModel; - } - - public async requestForm(formId: string) { - formManager.requestForm(formId) - .then((data) => { - console.info( '[FormComponent] requestForm result:' + data); - }); - } - - public async deleteCard(formId: string) { - formManager.deleteForm(formId) - .then((data) => { - console.info('[FormComponent] deleteForm result:' + data); - }); - } - - public async releaseCard(formId: string) { - formManager.releaseForm(formId) - .then((data) => { - console.info('[FormComponent] releaseForm result:' + data); - }); - } - - public async castTempToNormal(formId: string) { - formManager.castTempForm(formId) - .then((data) => { - console.info('[FormComponent] castTempToNormal result:' + data); - }); - } - - public async enableCard(formId: string) { - formManager.enableFormsUpdate([formId]) - .then((data) => { - console.info('[FormComponent] enableFormsUpdate result:' + data); - }); - } - - public async disableCard(formId: string) { - formManager.disableFormsUpdate([formId]) - .then((data) => { - console.info('[FormComponent] disableCard result:' + data); - }); - } - - public async changeCardVisible(formId: string, isVisible: boolean) { - if (isVisible) { - formManager.notifyVisibleForms([formId]) - .then((data) => { - console.info('[FormComponent] changeCardVisible result:' + data + ', isVisible:' + isVisible); - }); - } else { - formManager.notifyInvisibleForms([formId]) - .then((data) => { - console.info('[FormComponent] changeCardVisible result:' + data + ', isVisible:' + isVisible); - }); - } - } - - public async isFmsReady() { - formManager.isSystemReady() - .then((data) => { - console.info('[FormComponent] isFmsReady result:' + data); - }); - } - - public async getAllFormsInfo() { - console.info("[FormComponent] getAllFormsInfo start"); - formManager.getAllFormsInfo() - .then((data) => { - console.info('[FormComponent] getAllFormsInfo result:' + JSON.stringify(data)); - }) - .catch((err) => { - console.info('[FormComponent] getAllFormsInfo error:' + JSON.stringify(err)); - }); - console.info("[FormComponent] getAllFormsInfo end"); - } - - public async getFormsInfoByApp(bundle: string) { - formManager.getFormsInfo(bundle) - .then((data) => { - console.info('[FormComponent] getFormsInfoByApp result:' + JSON.stringify(data)); - }); - } - - public async getFormsInfoByModule(bundle: string, moduleName: string) { - formManager.getFormsInfo(bundle, moduleName) - .then((data) => { - console.info('[FormComponent] getFormsInfoByModule result:' + JSON.stringify(data)); - }); - } - - public async clearFormUserCache() { - bundleManager.cleanBundleCacheFiles('com.ohos.myapplicationform') - .then((data) => { - console.info('[FormComponent] cleanBundleCacheFiles result:' + JSON.stringify(data)); - }); - } - - public async clearFormProviderCache(bundle: string) { - bundleManager.cleanBundleCacheFiles(bundle) - .then((data) => { - console.info('[FormComponent] cleanBundleCacheFiles result:' + JSON.stringify(data)); - }); - } -} \ No newline at end of file diff --git a/aafwk/aafwk_standard/formmanager/fa/formsystemtest_ets/formupdatefreshtest/entry/src/main/ets/MainAbility/test/FmsUpdateRefreshForm.test.ets b/aafwk/aafwk_standard/formmanager/fa/formsystemtest_ets/formupdatefreshtest/entry/src/main/ets/MainAbility/test/FmsUpdateRefreshForm.test.ets index 907a7325f336f74ea9e7f96f42dd3e18c8bb17fc..7920c84b59fbb99a8e26904d35d93574ca735e5f 100644 --- a/aafwk/aafwk_standard/formmanager/fa/formsystemtest_ets/formupdatefreshtest/entry/src/main/ets/MainAbility/test/FmsUpdateRefreshForm.test.ets +++ b/aafwk/aafwk_standard/formmanager/fa/formsystemtest_ets/formupdatefreshtest/entry/src/main/ets/MainAbility/test/FmsUpdateRefreshForm.test.ets @@ -13,18 +13,14 @@ * limitations under the License. */ -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "deccjsunit/index.ets" import featureAbility from "@ohos.ability.featureAbility"; import commonEvent from '@ohos.commonEvent'; +import { beforeAll, beforeEach, describe, expect, it } from "deccjsunit/index.ets"; -var onErrorForm_Event = { - events: ["FMS_FormOnError_commonEvent"], -}; var onAcquiredForm_Event = { events: ["FMS_FormOnAcquired_commonEvent"], }; - -var onDetetedFormEvent = { +var onDeletedFormEvent = { events: ["FMS_FormOnDeleted_commonEvent"], }; var onUpdateRefreshEvent = { @@ -36,6 +32,12 @@ var onRequestFormEvent = { var deleteForm_Event = "FMS_FormDelete_commonEvent"; + +var subscriberOnAcquired; +var subscriberOnDeleted; +var subscriberOnRefresh; +var subscriberOnRequest; + export default function test() { describe(`FmsUpdateRefreshFormTest`, () => { @@ -43,6 +45,13 @@ export default function test() { done(); }) + beforeEach(async () => { + subscriberOnAcquired = await commonEvent.createSubscriber(onAcquiredForm_Event); + subscriberOnDeleted = await commonEvent.createSubscriber(onDeletedFormEvent); + subscriberOnRefresh = await commonEvent.createSubscriber(onUpdateRefreshEvent); + subscriberOnRequest = await commonEvent.createSubscriber(onRequestFormEvent); + }) + /** * @tc.number: FMS_updateForm_0100 * @tc.name: formID id is error(formID < 0) @@ -51,39 +60,19 @@ export default function test() { */ it(`FMS_updateForm_0100`, 0, async (done) => { console.log(`FMS_updateForm_0100 start`); - let subscriberOnRefresh; - let formId; - function delPublishCallBack() { - console.info("!!!====>FMS_updateForm_0100 delPublishCallBack====>"); - setTimeout(function () { - console.info('FMS_updateForm_0100 delPublishCallBack end'); - console.log(`FMS_updateForm_0100 end`); - done(); - }, 1000) - } - - function onRefreshCallBack(err, data) { + function onRefreshCallBack(_, data) { console.info("!!!====>FMS_updateForm_0100 onRefreshCallBack data:====>" + JSON.stringify(data)); expect(data.event).assertEqual("FMS_FormUpdateRefresh_commonEvent"); - // expect(data.data).assertEqual("8585224"); expect(data.data != "0").assertEqual(true); - commonEvent.unsubscribe(subscriberOnRefresh, unSubscribeOnRefreshCallback) + commonEvent.unsubscribe(subscriberOnRefresh, () => unsubscribeOnRefreshCallback("FMS_updateForm_0100")); let commonEventPublishData = { data: data.parameters.formId }; - commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallBack); - } - function unSubscribeOnRefreshCallback() { - console.debug("====>FMS_updateForm_0100 unSubscribeOnRefreshCallback CallBack====>"); + commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallBack("FMS_updateForm_0100", done)); } - - commonEvent.createSubscriber(onUpdateRefreshEvent).then(async (data) => { - console.debug("====>FMS_updateForm_0100 onUpdateRefreshEvent Subscriber====>"); - subscriberOnRefresh = data; - await commonEvent.subscribe(subscriberOnRefresh, onRefreshCallBack); - }); + commonEvent.subscribe(subscriberOnRefresh, onRefreshCallBack); console.log(`FMS_updateForm_0100 featureAbility.startAbility start`); await featureAbility.startAbility({ want: { @@ -116,39 +105,19 @@ export default function test() { */ it(`FMS_updateForm_0200`, 0, async (done) => { console.log(`FMS_updateForm_0200 start`); - let subscriberOnRefresh; - let formId; - function delPublishCallBack() { - console.info("!!!====>FMS_updateForm_0200 delPublishCallBack====>"); - setTimeout(function () { - console.info('FMS_updateForm_0200 delPublishCallBack end'); - console.log(`FMS_updateForm_0200 end`); - done(); - }, 1000) - } - - function onRefreshCallBack(err, data) { + function onRefreshCallBack(_, data) { console.info("!!!====>FMS_updateForm_0200 onRefreshCallBack data:====>" + JSON.stringify(data)); expect(data.event).assertEqual("FMS_FormUpdateRefresh_commonEvent"); - // expect(data.data).assertEqual("8585224"); expect(data.data != "0").assertEqual(true); - commonEvent.unsubscribe(subscriberOnRefresh, unSubscribeOnRefreshCallback) + commonEvent.unsubscribe(subscriberOnRefresh, () => unsubscribeOnRefreshCallback("FMS_updateForm_0200")); let commonEventPublishData = { data: data.parameters.formId }; - commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallBack); + commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallBack("FMS_updateForm_0200", done)); } - function unSubscribeOnRefreshCallback() { - console.debug("====>FMS_updateForm_0200 unSubscribeOnRefreshCallback CallBack====>"); - } - - commonEvent.createSubscriber(onUpdateRefreshEvent).then(async (data) => { - console.debug("====>FMS_updateForm_0200 onUpdateRefreshEvent Subscriber====>"); - subscriberOnRefresh = data; - await commonEvent.subscribe(subscriberOnRefresh, onRefreshCallBack); - }); + commonEvent.subscribe(subscriberOnRefresh, onRefreshCallBack); console.log(`FMS_updateForm_0200 featureAbility.startAbility start`); await featureAbility.startAbility({ want: { @@ -182,44 +151,24 @@ export default function test() { */ it(`FMS_updateForm_0300`, 0, async (done) => { console.log(`FMS_updateForm_0300 start`); - let subscriberOnRefresh; - let subscriberOnAcquired; let formId; - function delPublishCallBack() { - console.info("!!!====>FMS_updateForm_0300 delPublishCallBack====>"); - setTimeout(function () { - console.info('FMS_updateForm_0300 delPublishCallBack end'); - console.log(`FMS_updateForm_0300 end`); - done(); - }, 1000) - } - - function onRefreshCallBack(err, data) { + function onRefreshCallBack(_, data) { console.info("!!!====>FMS_updateForm_0300 onRefreshCallBack data:====>" + JSON.stringify(data)); expect(data.event).assertEqual("FMS_FormUpdateRefresh_commonEvent"); - // expect(data.data).assertEqual("8585223"); expect(data.data != "0").assertEqual(true); - commonEvent.unsubscribe(subscriberOnRefresh, unsubscribeOnRefreshCallback); + commonEvent.unsubscribe(subscriberOnRefresh, () => unsubscribeOnRefreshCallback("FMS_updateForm_0300")); let commonEventPublishData = { data: formId }; - commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallBack); + commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallBack("FMS_updateForm_0300", done)); } - function unsubscribeOnRefreshCallback() { - console.debug("====>FMS_updateForm_0300 unsubscribeOnRefreshCallback====>"); - } - - function onAcquiredCallBack(err, data) { + function onAcquiredCallBack(_, data) { console.info("!!!====>FMS_updateForm_0300 onAcquiredCallBack data:====>" + JSON.stringify(data)); expect(data.event).assertEqual("FMS_FormOnAcquired_commonEvent"); - commonEvent.unsubscribe(subscriberOnAcquired, unSubscribeOnAcquiredCallback) + commonEvent.unsubscribe(subscriberOnAcquired, () => unsubscribeOnAcquiredCallback("FMS_updateForm_0300")); formId = data.data; - commonEvent.createSubscriber(onUpdateRefreshEvent).then(async (data) => { - console.debug("====>FMS_updateForm_0300 onUpdateRefreshEvent Subscriber====>"); - subscriberOnRefresh = data; - await commonEvent.subscribe(subscriberOnRefresh, onRefreshCallBack); - }); + commonEvent.subscribe(subscriberOnRefresh, onRefreshCallBack); console.log(`FMS_updateForm_0300 featureAbility.startAbility again start`); featureAbility.startAbility({ @@ -245,15 +194,7 @@ export default function test() { }); console.log(`FMS_updateForm_0300 featureAbility.startAbility again end`); } - function unSubscribeOnAcquiredCallback() { - console.debug("====>FMS_updateForm_0300 OnAcquired UnSubscribe CallBack====>"); - } - - commonEvent.createSubscriber(onAcquiredForm_Event).then(async (data) => { - console.debug("====>FMS_updateForm_0300 Create OnAcquired Subscriber====>"); - subscriberOnAcquired = data; - await commonEvent.subscribe(subscriberOnAcquired, onAcquiredCallBack); - }); + commonEvent.subscribe(subscriberOnAcquired, onAcquiredCallBack); console.log(`FMS_updateForm_0300 featureAbility.startAbility start`); await featureAbility.startAbility({ want: { @@ -284,37 +225,26 @@ export default function test() { */ it(`FMS_updateForm_0400`, 0, async (done) => { console.log(`FMS_updateForm_0400 start`); - let subscriberOnRefresh; - let subscriberOnDeleted; let formId; - function onRefreshCallBack(err, data) { + function onRefreshCallBack(_, data) { console.info("!!!====>FMS_updateForm_0400 onRefreshCallBack data:====>" + JSON.stringify(data)); expect(data.event).assertEqual("FMS_FormUpdateRefresh_commonEvent"); - // expect(data.data).assertEqual("8585236"); expect(data.data != "0").assertEqual(true); - commonEvent.unsubscribe(subscriberOnRefresh, unSubscribeOnRefreshCallback); + commonEvent.unsubscribe(subscriberOnRefresh, () => unsubscribeOnRefreshCallback("FMS_updateForm_0400")); setTimeout(function () { - console.info('FMS_updateForm_0400 delPublishCallBack end'); + console.info('FMS_updateForm_0400 onRefreshCallBack end'); console.log(`FMS_updateForm_0400 end`); done(); }, 1000); } - function unSubscribeOnRefreshCallback() { - console.debug("====>FMS_updateForm_0400 unSubscribeOnRefreshCallback CallBack====>"); - } - - function onDeletedCallBack(err, data) { + function onDeletedCallBack(_, data) { console.info("!!!====>FMS_updateForm_0400 onDeletedCallBack data:====>" + JSON.stringify(data)); expect(data.event).assertEqual("FMS_FormOnDeleted_commonEvent"); expect(data.data).assertEqual("0"); - commonEvent.unsubscribe(subscriberOnDeleted, unSubscribeDeletedCallback) + commonEvent.unsubscribe(subscriberOnDeleted, () => unsubscribeDeletedCallback("FMS_updateForm_0400")); formId = data.parameters.formId; - commonEvent.createSubscriber(onUpdateRefreshEvent).then(async (data) => { - console.debug("====>FMS_updateForm_0400 B onUpdateRefreshEvent Subscriber====>"); - subscriberOnRefresh = data; - await commonEvent.subscribe(subscriberOnRefresh, onRefreshCallBack); - }); + commonEvent.subscribe(subscriberOnRefresh, onRefreshCallBack); console.log(`FMS_updateForm_0400 featureAbility.startAbility again start`); featureAbility.startAbility({ @@ -340,14 +270,7 @@ export default function test() { }); console.log(`FMS_updateForm_0400 featureAbility.startAbility again end`); } - function unSubscribeDeletedCallback() { - console.debug("====>FMS_updateForm_0400 unSubscribeDeletedCallback====>"); - } - commonEvent.createSubscriber(onDetetedFormEvent).then(async (data) => { - console.debug("====>FMS_releaseForm_1400 onDetetedFormEvent Subscriber====>"); - subscriberOnDeleted = data; - await commonEvent.subscribe(subscriberOnDeleted, onDeletedCallBack); - }); + commonEvent.subscribe(subscriberOnDeleted, onDeletedCallBack); console.log(`FMS_updateForm_0400 featureAbility.startAbility start`); await featureAbility.startAbility({ want: { @@ -379,39 +302,19 @@ export default function test() { */ it(`FMS_updateForm_0500`, 0, async (done) => { console.log(`FMS_updateForm_0500 start`); - let subscriberOnRefresh; - let formId; - function delPublishCallBack() { - console.info("!!!====>FMS_updateForm_0500 delPublishCallBack====>"); - setTimeout(function () { - console.info('FMS_updateForm_0500 delPublishCallBack end'); - console.log(`FMS_updateForm_0500 end`); - done(); - }, 1000) - } - - function onRefreshCallBack(err, data) { + function onRefreshCallBack(_, data) { console.info("!!!====>FMS_updateForm_0500 onRefreshCallBack data:====>" + JSON.stringify(data)); expect(data.event).assertEqual("FMS_FormUpdateRefresh_commonEvent"); - // expect(data.data).assertEqual("8585225"); expect(data.data != "0").assertEqual(true); - commonEvent.unsubscribe(subscriberOnRefresh, unSubscribeOnRefreshCallback) + commonEvent.unsubscribe(subscriberOnRefresh, () => unsubscribeOnRefreshCallback("FMS_updateForm_0500")); let commonEventPublishData = { data: data.parameters.formId }; - commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallBack); - } - function unSubscribeOnRefreshCallback() { - console.debug("====>FMS_updateForm_0500 unSubscribeOnRefreshCallback CallBack====>"); + commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallBack("FMS_updateForm_0500", done)); } - - commonEvent.createSubscriber(onUpdateRefreshEvent).then(async (data) => { - console.debug("====>FMS_updateForm_0500 onUpdateRefreshEvent Subscriber====>"); - subscriberOnRefresh = data; - await commonEvent.subscribe(subscriberOnRefresh, onRefreshCallBack); - }); + commonEvent.subscribe(subscriberOnRefresh, onRefreshCallBack); console.log(`FMS_updateForm_0500 featureAbility.startAbility start`); await featureAbility.startAbility({ want: { @@ -445,39 +348,19 @@ export default function test() { */ it(`FMS_hostRefresh_0100`, 0, async (done) => { console.log(`FMS_hostRefresh_0100 start`); - let subscriberOnReQuest; - let formId; - function delPublishCallBack() { - console.info("!!!====>FMS_hostRefresh_0100 delPublishCallBack====>"); - setTimeout(function () { - console.info('FMS_hostRefresh_0100 delPublishCallBack end'); - console.log(`FMS_hostRefresh_0100 end`); - done(); - }, 1000) - } - - function onRequestCallBack(err, data) { + function onRequestCallBack(_, data) { console.info("!!!====>FMS_hostRefresh_0100 onRequestCallBack data:====>" + JSON.stringify(data)); expect(data.event).assertEqual("FMS_FormOnRequest_commonEvent"); - // expect(data.data).assertEqual("8585224"); expect(data.data != "0").assertEqual(true); - commonEvent.unsubscribe(subscriberOnReQuest, unSubscribeOnRequestCallback) + commonEvent.unsubscribe(subscriberOnRequest, () => unsubscribeOnRequestCallback("FMS_hostRefresh_0100")); let commonEventPublishData = { data: data.parameters.formId }; - commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallBack); + commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallBack("FMS_hostRefresh_0100", done)); } - function unSubscribeOnRequestCallback() { - console.debug("====>FMS_hostRefresh_0100 unSubscribeOnRequestCallback CallBack====>"); - } - - commonEvent.createSubscriber(onRequestFormEvent).then(async (data) => { - console.debug("====>FMS_hostRefresh_0100 onRequestFormEvent Subscriber====>"); - subscriberOnReQuest = data; - await commonEvent.subscribe(subscriberOnReQuest, onRequestCallBack); - }); + commonEvent.subscribe(subscriberOnRequest, onRequestCallBack); console.log(`FMS_hostRefresh_0100 featureAbility.startAbility start`); await featureAbility.startAbility({ want: { @@ -510,39 +393,19 @@ export default function test() { */ it(`FMS_hostRefresh_0200`, 0, async (done) => { console.log(`FMS_hostRefresh_0200 start`); - let subscriberOnReQuest; - let formId; - function delPublishCallBack() { - console.info("!!!====>FMS_hostRefresh_0200 delPublishCallBack====>"); - setTimeout(function () { - console.info('FMS_hostRefresh_0200 delPublishCallBack end'); - console.log(`FMS_hostRefresh_0200 end`); - done(); - }, 1000) - } - - function onRequestCallBack(err, data) { + function onRequestCallBack(_, data) { console.info("!!!====>FMS_hostRefresh_0200 onRequestCallBack data:====>" + JSON.stringify(data)); expect(data.event).assertEqual("FMS_FormOnRequest_commonEvent"); - // expect(data.data).assertEqual("8585224"); expect(data.data != "0").assertEqual(true); - commonEvent.unsubscribe(subscriberOnReQuest, unSubscribeOnRequestCallback) + commonEvent.unsubscribe(subscriberOnRequest, () => unsubscribeOnRequestCallback("FMS_hostRefresh_0200")); let commonEventPublishData = { data: data.parameters.formId }; - commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallBack); - } - function unSubscribeOnRequestCallback() { - console.debug("====>FMS_hostRefresh_0200 unSubscribeOnRequestCallback CallBack====>"); + commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallBack("FMS_hostRefresh_0200", done)); } - - commonEvent.createSubscriber(onRequestFormEvent).then(async (data) => { - console.debug("====>FMS_hostRefresh_0200 onRequestFormEvent Subscriber====>"); - subscriberOnReQuest = data; - await commonEvent.subscribe(subscriberOnReQuest, onRequestCallBack); - }); + commonEvent.subscribe(subscriberOnRequest, onRequestCallBack); console.log(`FMS_hostRefresh_0200 featureAbility.startAbility start`); await featureAbility.startAbility({ want: { @@ -576,43 +439,25 @@ export default function test() { */ it(`FMS_hostRefresh_0300`, 0, async (done) => { console.log(`FMS_hostRefresh_0300 start`); - let subscriberOnReQuest; - let subscriberOnAcquired; let formId; - function delPublishCallBack() { - console.info("!!!====>FMS_hostRefresh_0300 delPublishCallBack====>"); - setTimeout(function () { - console.info('FMS_hostRefresh_0300 delPublishCallBack end'); - console.log(`FMS_hostRefresh_0300 end`); - done(); - }, 1000) - } - - function onRequestCallBack(err, data) { + function onRequestCallBack(_, data) { console.info("!!!====>FMS_hostRefresh_0300 onRequestCallBack data:====>" + JSON.stringify(data)); expect(data.event).assertEqual("FMS_FormOnRequest_commonEvent"); expect(data.data != "0").assertEqual(true); - commonEvent.unsubscribe(subscriberOnReQuest, unsubscribeOnRefreshCallback); + commonEvent.unsubscribe(subscriberOnRequest, () => unsubscribeOnRefreshCallback("FMS_hostRefresh_0300")); let commonEventPublishData = { data: formId }; - commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallBack); + commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallBack("FMS_hostRefresh_0300", done)); } - function unsubscribeOnRefreshCallback() { - console.debug("====>FMS_hostRefresh_0300 unsubscribeOnRefreshCallback====>"); - } - - function onAcquiredCallBack(err, data) { + + function onAcquiredCallBack(_, data) { console.info("!!!====>FMS_hostRefresh_0300 onAcquiredCallBack data:====>" + JSON.stringify(data)); expect(data.event).assertEqual("FMS_FormOnAcquired_commonEvent"); - commonEvent.unsubscribe(subscriberOnAcquired, unSubscribeOnAcquiredCallback) + commonEvent.unsubscribe(subscriberOnAcquired, () => unsubscribeOnAcquiredCallback("FMS_hostRefresh_0300")); formId = data.data; - commonEvent.createSubscriber(onRequestFormEvent).then(async (data) => { - console.debug("====>FMS_hostRefresh_0300 onRequestFormEvent Subscriber====>"); - subscriberOnReQuest = data; - await commonEvent.subscribe(subscriberOnReQuest, onRequestCallBack); - }); + commonEvent.subscribe(subscriberOnRequest, onRequestCallBack); console.log(`FMS_hostRefresh_0300 featureAbility.startAbility again start`); featureAbility.startAbility({ @@ -638,15 +483,7 @@ export default function test() { }); console.log(`FMS_hostRefresh_0300 featureAbility.startAbility again end`); } - function unSubscribeOnAcquiredCallback() { - console.debug("====>FMS_hostRefresh_0300 OnAcquired UnSubscribe CallBack====>"); - } - - commonEvent.createSubscriber(onAcquiredForm_Event).then(async (data) => { - console.debug("====>FMS_hostRefresh_0300 Create OnAcquired Subscriber====>"); - subscriberOnAcquired = data; - await commonEvent.subscribe(subscriberOnAcquired, onAcquiredCallBack); - }); + commonEvent.subscribe(subscriberOnAcquired, onAcquiredCallBack); console.log(`FMS_hostRefresh_0300 featureAbility.startAbility start`); await featureAbility.startAbility({ want: { @@ -677,38 +514,26 @@ export default function test() { */ it(`FMS_hostRefresh_0400`, 0, async (done) => { console.log(`FMS_hostRefresh_0400 start`); - let subscriberOnReQuest; - let subscriberOnDeleted; let formId; - function onRequestCallBack(err, data) { + function onRequestCallBack(_, data) { console.info("!!!====>FMS_hostRefresh_0400 onRequestCallBack data:====>" + JSON.stringify(data)); expect(data.event).assertEqual("FMS_FormOnRequest_commonEvent"); - // expect(data.data).assertEqual("8585236"); expect(data.data != "0").assertEqual(true); - commonEvent.unsubscribe(subscriberOnReQuest, unSubscribeOnRequestCallback); + commonEvent.unsubscribe(subscriberOnRequest, () => unsubscribeOnRequestCallback("FMS_hostRefresh_0400")); setTimeout(function () { console.info('FMS_hostRefresh_0400 onRequestCallBack end'); console.log(`FMS_hostRefresh_0400 end`); done(); }, 10); - } - function unSubscribeOnRequestCallback() { - console.debug("====>FMS_hostRefresh_0400 unSubscribeOnRequestCallback CallBack====>"); - } - - function onDeletedCallBack(err, data) { + function onDeletedCallBack(_, data) { console.info("!!!====>FMS_hostRefresh_0400 onDeletedCallBack data:====>" + JSON.stringify(data)); expect(data.event).assertEqual("FMS_FormOnDeleted_commonEvent"); expect(data.data).assertEqual("0"); - commonEvent.unsubscribe(subscriberOnDeleted, unSubscribeDeletedCallback) + commonEvent.unsubscribe(subscriberOnDeleted, () => unsubscribeDeletedCallback("FMS_hostRefresh_0400")); formId = data.parameters.formId; - commonEvent.createSubscriber(onRequestFormEvent).then(async (data) => { - console.debug("====>FMS_hostRefresh_0400 onRequestFormEvent Subscriber====>"); - subscriberOnReQuest = data; - await commonEvent.subscribe(subscriberOnReQuest, onRequestCallBack); - }); + commonEvent.subscribe(subscriberOnRequest, onRequestCallBack); console.log(`FMS_hostRefresh_0400 featureAbility.startAbility again start`); featureAbility.startAbility({ @@ -734,14 +559,7 @@ export default function test() { }); console.log(`FMS_hostRefresh_0400 featureAbility.startAbility again end`); } - function unSubscribeDeletedCallback() { - console.debug("====>FMS_hostRefresh_0400 unSubscribeDeletedCallback====>"); - } - commonEvent.createSubscriber(onDetetedFormEvent).then(async (data) => { - console.debug("====>FMS_hostRefresh_0400 onDetetedFormEvent Subscriber====>"); - subscriberOnDeleted = data; - await commonEvent.subscribe(subscriberOnDeleted, onDeletedCallBack); - }); + commonEvent.subscribe(subscriberOnDeleted, onDeletedCallBack); console.log(`FMS_hostRefresh_0400 featureAbility.startAbility start`); await featureAbility.startAbility({ want: { @@ -774,29 +592,21 @@ export default function test() { */ it(`FMS_hostRefresh_0600`, 0, async (done) => { console.log(`FMS_hostRefresh_0600 start`); - let subscriberOnReQuest; - function onRequestCallBack(err, data) { + function onRequestCallBack(_, data) { console.info("!!!====>FMS_hostRefresh_0600 onRequestCallBack data:====>" + JSON.stringify(data)); expect(data.event).assertEqual("FMS_FormOnRequest_commonEvent"); expect(data.data != "0").assertEqual(true); - commonEvent.unsubscribe(subscriberOnReQuest, unSubscribeOnRequestCallback) + commonEvent.unsubscribe(subscriberOnRequest, () => unsubscribeOnRequestCallback("FMS_hostRefresh_0600")); setTimeout(function () { - console.info('FMS_hostRefresh_0600 delPublishCallBack end'); + console.info('FMS_hostRefresh_0600 onRequestCallBack end'); console.log(`FMS_hostRefresh_0600 end`); done(); }, 1000) } - function unSubscribeOnRequestCallback() { - console.debug("====>FMS_hostRefresh_0600 unSubscribeOnRequestCallback CallBack====>"); - } - - commonEvent.createSubscriber(onRequestFormEvent).then(async (data) => { - console.debug("====>FMS_hostRefresh_0600 onRequestFormEvent Subscriber====>"); - subscriberOnReQuest = data; - await commonEvent.subscribe(subscriberOnReQuest, onRequestCallBack); - }); + + commonEvent.subscribe(subscriberOnRequest, onRequestCallBack); console.log(`FMS_hostRefresh_0600 featureAbility.startAbility start`); await featureAbility.startAbility({ want: { @@ -829,38 +639,21 @@ export default function test() { */ it(`FMS_hostRefresh_0700`, 0, async (done) => { console.log(`FMS_hostRefresh_0700 start`); - let subscriberOnReQuest; let formId; - - function delPublishCallBack() { - console.info("!!!====>FMS_hostRefresh_0700 delPublishCallBack====>"); - setTimeout(function () { - console.info('FMS_hostRefresh_0700 delPublishCallBack end'); - console.log(`FMS_hostRefresh_0700 end`); - done(); - }, 1000) - } - function onRequestCallBack(err, data) { + function onRequestCallBack(_, data) { console.info("!!!====>FMS_hostRefresh_0700 onRequestCallBack data:====>" + JSON.stringify(data)); expect(data.event).assertEqual("FMS_FormOnRequest_commonEvent"); expect(data.data).assertEqual("0"); - commonEvent.unsubscribe(subscriberOnReQuest, unSubscribeOnRequestCallback) + commonEvent.unsubscribe(subscriberOnRequest, () => unsubscribeOnRequestCallback("FMS_hostRefresh_0700")); formId = data.parameters.formId; let commonEventPublishData = { data: formId }; - commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallBack); - } - function unSubscribeOnRequestCallback() { - console.debug("====>FMS_hostRefresh_0700 unSubscribeOnRequestCallback CallBack====>"); + commonEvent.publish(deleteForm_Event, commonEventPublishData, delPublishCallBack("FMS_hostRefresh_0700", done)); } - - commonEvent.createSubscriber(onRequestFormEvent).then(async (data) => { - console.debug("====>FMS_hostRefresh_0700 onRequestFormEvent Subscriber====>"); - subscriberOnReQuest = data; - await commonEvent.subscribe(subscriberOnReQuest, onRequestCallBack); - }); + + commonEvent.subscribe(subscriberOnRequest, onRequestCallBack); console.log(`FMS_hostRefresh_0700 featureAbility.startAbility start`); await featureAbility.startAbility({ @@ -888,3 +681,27 @@ export default function test() { }); }); } + +const delPublishCallBack = async (tcNumber, done) => { + console.info(`${tcNumber} delPublishCallBack start`); + setTimeout(function () { + console.info(`${tcNumber} delPublishCallBack end`); + done(); + }, 1000) +} + +const unsubscribeOnRequestCallback = (tcNumber) => { + console.debug(`====>${tcNumber} unsubscribeOnRequestCallback CallBack====>`); +} + +const unsubscribeOnRefreshCallback = (tcNumber) => { + console.debug(`====>${tcNumber} unsubscribeOnRefreshCallback CallBack====>`); +} + +const unsubscribeDeletedCallback = (tcNumber) => { + console.debug(`====>${tcNumber} unsubscribeDeletedCallback====>`); +} + +const unsubscribeOnAcquiredCallback = (tcNumber) => { + console.debug(`====>${tcNumber} unsubscribeOnAcquiredCallback CallBack====>`); +}