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

!3333 添加卡片的xts测试

Merge pull request !3333 from chengxingzhen/master
......@@ -16,42 +16,6 @@ import("//test/xts/tools/build/suite.gni")
group("formmanager") {
testonly = true
if (is_standard_system) {
deps = [
"formhostst_ets/formsystemhostc:FormSystemHostC",
"formhostst_ets/formsystemhostf:FormSystemHostF",
"formhostst_ets/formsystemhostg:FormSystemHostG",
"formhostst_ets/formsystemhostk:FormSystemHostK",
"formhostst_ets/formsystemhostl:FormSystemHostL",
"formhostst_ets/formsystemhostn:FormSystemHostN",
"formhostst_ets/formsystemhostnoperm:FormSystemHostNoPerm",
"formhostst_ets/formsystemhosto:FormSystemHostO",
"formhostst_ets/formsystemhostp:FormSystemHostP",
"formproviderst_ets/formsupplyapplicationA:FormSupplyAppA",
"formproviderst_ets/formsupplyapplicationB:FormSupplyAppB",
"formproviderst_ets/formsupplyapplicationD:FormSupplyAppD",
"formproviderst_ets/formsupplyapplicationE:FormSupplyAppE",
"formproviderst_ets/formsupplyapplicationF:FormSupplyAppF",
"formproviderst_ets/formsupplyapplicationG:FormSupplyAppG",
"formproviderst_ets/formsupplyapplicationH:FormSupplyAppH",
"formproviderst_ets/formsupplyapplicationNotSysApp:FormSupplyAppNS",
"formproviderst_ets/formsystemprovidera:FormSystemProviderA",
"formproviderst_ets/formsystemproviderb:FormSystemProviderB",
"formproviderst_ets/formsystemproviderc:FormSystemProviderC",
"formproviderst_ets/formsystemproviderd:FormSystemProviderD",
"formsystemtest_ets/formfuzztest:ActsFormFuzzTest",
"formsystemtest_ets/formgetformsinfotest/formsoneandonetest:FormsOneAndOneTest",
"formsystemtest_ets/formgetformsinfotest/formsoneandtwotest:FormsOneAndTwoTest",
"formsystemtest_ets/formgetformsinfotest/formsoneandzerotest:FormsOneAndZeroTest",
"formsystemtest_ets/formgetformsinfotest/formswithoutpermtest:FormsWithoutPermTest",
"formsystemtest_ets/formgetformsinfotest/formszerotest:FormsZeroTest",
"formsystemtest_ets/formhostdeathrecipienttest:FormHostDeathRecipientTest",
"formsystemtest_ets/formperformancetest:FormPerformanceTest",
"formsystemtest_ets/formstatetest_disable:FormStateDisableTest",
"formsystemtest_ets/formstatetest_enable:FormStateEnableTest",
"formsystemtest_ets/formstatetest_notifyinvisible:FormStateNotifyInvisibleTest",
"formsystemtest_ets/formstatetest_notifyinvisible2:FormStateNotifyInvisibleTest2",
"formsystemtest_ets/formstatetest_notifyvisible:FormStateNotifyVisibleTest",
"formsystemtest_ets/formstresstest:FormStressTest",
]
deps = [ "fa:formmanager" ]
}
}
# 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("//test/xts/tools/build/suite.gni")
group("formmanager") {
testonly = true
if (is_standard_system) {
deps = [
"formhostst_ets/formsystemhost:FormSystemHost",
"formhostst_ets/formsystemhostb:FormSystemHostB",
"formhostst_ets/formsystemhostc:FormSystemHostC",
"formhostst_ets/formsystemhostf:FormSystemHostF",
"formhostst_ets/formsystemhostg:FormSystemHostG",
"formhostst_ets/formsystemhosti:FormSystemHostI",
"formhostst_ets/formsystemhostj:FormSystemHostJ",
"formhostst_ets/formsystemhostk:FormSystemHostK",
"formhostst_ets/formsystemhostl:FormSystemHostL",
"formhostst_ets/formsystemhostn:FormSystemHostN",
"formhostst_ets/formsystemhostnoperm:FormSystemHostNoPerm",
"formhostst_ets/formsystemhosto:FormSystemHostO",
"formhostst_ets/formsystemhostp:FormSystemHostP",
"formproviderst_ets/formsupplyapplicationA:FormSupplyAppA",
"formproviderst_ets/formsupplyapplicationB:FormSupplyAppB",
"formproviderst_ets/formsupplyapplicationD:FormSupplyAppD",
"formproviderst_ets/formsupplyapplicationE:FormSupplyAppE",
"formproviderst_ets/formsupplyapplicationF:FormSupplyAppF",
"formproviderst_ets/formsupplyapplicationG:FormSupplyAppG",
"formproviderst_ets/formsupplyapplicationH:FormSupplyAppH",
"formproviderst_ets/formsupplyapplicationNotSysApp:FormSupplyAppNS",
"formproviderst_ets/formsystemprovidera:FormSystemProviderA",
"formproviderst_ets/formsystemproviderb:FormSystemProviderB",
"formproviderst_ets/formsystemproviderc:FormSystemProviderC",
"formproviderst_ets/formsystemproviderd:FormSystemProviderD",
"formsystemtest_ets/formacquiretest:FormAcquireTest",
"formsystemtest_ets/formacquiretest2:FormAcquireTest2",
"formsystemtest_ets/formfuzztest:ActsFormFuzzTest",
"formsystemtest_ets/formgetformsinfotest/formsoneandonetest:FormsOneAndOneTest",
"formsystemtest_ets/formgetformsinfotest/formsoneandtwotest:FormsOneAndTwoTest",
"formsystemtest_ets/formgetformsinfotest/formsoneandzerotest:FormsOneAndZeroTest",
"formsystemtest_ets/formgetformsinfotest/formswithoutpermtest:FormsWithoutPermTest",
"formsystemtest_ets/formgetformsinfotest/formszerotest:FormsZeroTest",
"formsystemtest_ets/formhostdeathrecipienttest:FormHostDeathRecipientTest",
"formsystemtest_ets/formperformancetest:FormPerformanceTest",
"formsystemtest_ets/formstatetest_disable:FormStateDisableTest",
"formsystemtest_ets/formstatetest_enable:FormStateEnableTest",
"formsystemtest_ets/formstatetest_notifyinvisible:FormStateNotifyInvisibleTest",
"formsystemtest_ets/formstatetest_notifyinvisible2:FormStateNotifyInvisibleTest2",
"formsystemtest_ets/formstatetest_notifyvisible:FormStateNotifyVisibleTest",
"formsystemtest_ets/formstresstest:FormStressTest",
]
}
}
# 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("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("FormSystemHost") {
hap_profile = "./entry/src/main/config.json"
deps = [
":hjs_demo_js_assets",
":hjs_demo_resources",
]
ets2abc = true
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "FormSystemHost"
}
ohos_js_assets("hjs_demo_js_assets") {
source_dir = "./entry/src/main/ets/MainAbility"
}
ohos_resources("hjs_demo_resources") {
sources = [ "./entry/src/main/resources" ]
hap_profile = "./entry/src/main/config.json"
}
{
"description": "Configuration for hjunit demo Tests"
}
{
"app": {
"bundleName": "com.ohos.st.formsystemhost",
"vendor": "ohos",
"version": {
"code": 1000000,
"name": "1.0.0"
},
"apiVersion": {
"compatible": 7,
"releaseType": "Release",
"target": 7
}
},
"deviceConfig": {},
"module": {
"package": "com.ohos.st.formsystemhost",
"name": ".FormStHostApp",
"mainAbility": ".MainAbility",
"deviceType": [
"phone"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "entry",
"moduleType": "entry",
"installationFree": false
},
"abilities": [
{
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
],
"visible": true,
"name": ".MainAbility",
"srcLanguage": "ets",
"icon": "$media:icon",
"description": "$string:description_mainability",
"label": "$string:entry_MainAbility",
"type": "page",
"launchType": "standard"
}
],
"js": [
{
"mode": {
"syntax": "ets",
"type": "pageAbility"
},
"pages": [
"pages/index"
],
"name": ".MainAbility",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
}
],
"defPermissions": [
{
"availableScope": [],
"grantMode": "system_grant",
"name": "FMS_FormDelete_commonEvent"
},
{
"availableScope": [],
"grantMode": "system_grant",
"name": "FMS_FormOnAcquired_commonEvent"
},
{
"availableScope": [],
"grantMode": "system_grant",
"name": "FMS_FormOnError_commonEvent"
},
{
"availableScope": [],
"grantMode": "system_grant",
"name": "FMS_FormCast_commonEvent"
},
{
"availableScope": [],
"grantMode": "system_grant",
"name": "FMS_FormOnUninstall_commonEvent"
}
],
"reqPermissions": [
{
"name": "FMS_FormOnAcquired_commonEvent"
},
{
"name": "FMS_FormDelete_commonEvent"
},
{
"name": "FMS_FormOnError_commonEvent"
},
{
"name": "FMS_FormCast_commonEvent"
},
{
"name": "FMS_FormOnUninstall_commonEvent"
},
{
"name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"
},
{
"name": "ohos.permission.INSTALL_BUNDLE"
},
{
"name": "ohos.permission.LISTEN_BUNDLE_CHANGE"
},
{
"name": "ohos.permission.REQUIRE_FORM"
}
]
}
}
\ No newline at end of file
/*
* 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.
*/
export default {
onCreate() {
console.info('[FormComponent.host] Application onCreate')
},
onDestroy() {
console.info('[FormComponent.host] Application onDestroy')
},
}
\ No newline at end of file
/*
* 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 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 formOnAcquiredEvent = "FMS_FormOnAcquired_commonEvent";
private formCastEvent = "FMS_FormCast_commonEvent";
private formOnErrorEvent = "FMS_FormOnError_commonEvent";
private formOnUninstallEvent = "FMS_FormOnUninstall_commonEvent";
private subscriberDel;
private subscriberFormDeleteEvent = {
events: ["FMS_FormDelete_commonEvent"],
};
private publishOnErrorCallBack() {
this.canCreateForm = false;
console.debug("====>formOnErrorEvent Publish CallBack ====>");
}
private publishOnAcquiredCallBack() {
console.debug("====>formOnAcquiredEvent Publish CallBack ====>");
}
private publishCastCallBack() {
console.debug("====>formCastEvent Publish CallBack ====>");
}
private publishOnUninstallCallBack() {
console.debug("====>formOnUninstallEvent Publish CallBack ====>");
}
private deleteCallBack(err, data) {
console.info("!!!====>formsystemhost deleteCallBack start:====>" + JSON.stringify(data));
if (data.bundleName && data.bundleName != "com.ohos.st.formsystemhost") {
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;
}
console.log("formsystemhost dimension1:" + this.dimension);
if (want.parameters.dimension) {
this.dimension = want.parameters.dimension;
}
console.log("formsystemhost dimension2:" + this.dimension);
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;
}
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: data || `0`,
parameters: {
"formId": this.deleteId.toString()
}
};
commonEvent.publish(this.formOnErrorEvent, commonEventPublishData, this.publishOnErrorCallBack);
})
.catch((error) => {
console.info('[FormComponent] deleteForm error:' + error);
let commonEventPublishData = {
data: error.code.toString(),
parameters: {
"formId": this.deleteId.toString()
}
};
commonEvent.publish(this.formOnErrorEvent, commonEventPublishData, this.publishOnErrorCallBack);
});
console.log("formsystemhost deleteForm end");
}
if (!want.parameters.isCreate && this.castForm) {
console.log("[FormComponent.host] castTempForm start");
formManager.castTempForm(this.temporaryId)
.then((data) => {
console.info('[FormComponent] castTempForm result:' + data);
setTimeout(() => {
let commonEventPublishData = {
data: data || `0`,
parameters: {
"formId": this.temporaryId.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.temporaryId.toString()
}
};
commonEvent.publish(this.formCastEvent, commonEventPublishData, this.publishCastCallBack);
}, 5);
});
console.log("[FormComponent.host] castTempForm 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: 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.temporaryId.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);
let commonEventPublishData = {
data: data || `0`,
parameters: {
"formId": this.deleteId.toString()
}
};
commonEvent.publish(this.formOnErrorEvent, commonEventPublishData, this.publishOnErrorCallBack);
})
.catch((error) => {
console.info('[FormComponent] deleteForm error:' + error);
let commonEventPublishData = {
data: error.code.toString(),
parameters: {
"formId": this.deleteId.toString()
}
};
commonEvent.publish(this.formOnErrorEvent, commonEventPublishData, this.publishOnErrorCallBack);
});
console.log("[FormComponent.host] deleteForm end");
}, 1000);
} else {
let commonEventPublishData = {
data: this.formId.toString(),
parameters: {
"formId": this.deleteId.toString()
}
};
commonEvent.publish(this.formOnAcquiredEvent, commonEventPublishData, this.publishOnAcquiredCallBack);
}
})
.onUninstall((info) => {
console.log("[FormComponent] onUninstall:" + JSON.stringify(info));
let commonEventPublishData = {
data: this.formId.toString(),
parameters: {
"formId": info.id.toString()
}
};
commonEvent.publish(this.formOnUninstallEvent, commonEventPublishData, this.publishOnUninstallCallBack);
})
.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.formOnErrorEvent, commonEventPublishData, this.publishOnErrorCallBack);
} 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
{
"string": [
{
"name": "entry_MainAbility",
"value": "formhostA"
},
{
"name": "description_mainability",
"value": "ETS_Empty Ability"
}
]
}
\ No newline at end of file
# 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("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("FormSystemHostB") {
hap_profile = "./entry/src/main/config.json"
deps = [
":hjs_demo_js_assets",
":hjs_demo_resources",
]
ets2abc = true
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "FormSystemHostB"
}
ohos_js_assets("hjs_demo_js_assets") {
source_dir = "./entry/src/main/ets/MainAbility"
}
ohos_resources("hjs_demo_resources") {
sources = [ "./entry/src/main/resources" ]
hap_profile = "./entry/src/main/config.json"
}
{
"description": "Configuration for hjunit demo Tests"
}
{
"app": {
"bundleName": "com.ohos.st.formsystemhostb",
"vendor": "ohos",
"version": {
"code": 1000000,
"name": "1.0.0"
},
"apiVersion": {
"compatible": 7,
"releaseType": "Release",
"target": 7
}
},
"deviceConfig": {},
"module": {
"package": "com.ohos.st.formsystemhostb",
"name": ".FormStHostAppB",
"mainAbility": ".MainAbility",
"deviceType": [
"phone"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "entry",
"moduleType": "entry",
"installationFree": false
},
"abilities": [
{
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
],
"visible": true,
"name": ".MainAbility",
"srcLanguage": "ets",
"icon": "$media:icon",
"description": "$string:description_mainability",
"label": "$string:entry_MainAbility",
"type": "page",
"launchType": "standard"
}
],
"js": [
{
"mode": {
"syntax": "ets",
"type": "pageAbility"
},
"pages": [
"pages/index"
],
"name": ".MainAbility",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
}
],
"defPermissions": [
{
"availableScope": [],
"grantMode": "system_grant",
"name": "FMS_FormDelete_commonEvent"
},
{
"availableScope": [],
"grantMode": "system_grant",
"name": "FMS_FormOnAcquired_commonEvent"
},
{
"availableScope": [],
"grantMode": "system_grant",
"name": "FMS_FormOnError_commonEvent"
}
],
"reqPermissions": [
{
"name": "FMS_FormOnAcquired_commonEvent"
},
{
"name": "FMS_FormDelete_commonEvent",
"reason": "need use FMS_FormDelete_commonEvent"
},
{
"name": "FMS_FormOnError_commonEvent",
"reason": "need use delete commonEvent"
},
{
"name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"
},
{
"name": "ohos.permission.INSTALL_BUNDLE"
},
{
"name": "ohos.permission.LISTEN_BUNDLE_CHANGE"
},
{
"name": "ohos.permission.REQUIRE_FORM"
}
]
}
}
\ No newline at end of file
/*
* 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.
*/
export default {
onCreate() {
console.info('[FormComponent.host] Application onCreate')
},
onDestroy() {
console.info('[FormComponent.host] Application onDestroy')
},
}
\ No newline at end of file
/*
* 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
/*
* 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 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 formOnAcquiredEvent = "FMS_FormOnAcquired_commonEvent";
private formCastEvent = "FMS_FormCast_commonEvent";
private formOnErrorEvent = "FMS_FormOnError_commonEvent";
private subscriberFormDeleteEvent = {
events: ["FMS_FormDelete_commonEvent"],
};
private subscriberDle;
private publishOnErrorCallBack() {
this.canCreateForm = false;
console.debug("====>formOnErrorEvent Publish CallBack ====>");
}
private publishOnAcquiredCallBack() {
console.debug("====>formOnAcquiredEvent Publish CallBack ====>");
}
private publishCastCallBack() {
console.debug("====>formCastEvent Publish CallBack ====>");
}
private deleteCallBack(err, data) {
console.info("!!!====>formsystemhost deleteCallBack start:====>" + JSON.stringify(data));
if(data.bundleName && data.bundleName != "com.ohos.st.formsystemhostb") {
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.subscriberDle = data;
await commonEvent.subscribe(this.subscriberDle, 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.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;
}
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("formsystemhostb deleteForm start");
formManager.deleteForm(this.deleteId)
.then((data) => {
console.info('formsystemhostb deleteForm result:' + data);
let commonEventPublishData = {
data: data.toString(),
parameters: {
"formId" : this.deleteId.toString()
}
};
commonEvent.publish(this.formOnErrorEvent, commonEventPublishData, this.publishOnErrorCallBack);
})
.catch((error) => {
console.info('[FormComponent] deleteForm error:' + error);
let commonEventPublishData = {
data: error.code.toString(),
parameters: {
"formId" : this.deleteId.toString()
}
};
commonEvent.publish(this.formOnErrorEvent, commonEventPublishData, this.publishOnErrorCallBack);
});
console.log("formsystemhostb deleteForm 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: data.toString(),
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.temporaryId.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);
let commonEventPublishData = {
data: data.toString(),
parameters: {
"formId" : this.deleteId.toString()
}
};
commonEvent.publish(this.formOnErrorEvent, commonEventPublishData, this.publishOnErrorCallBack);
})
.catch((error) => {
console.info('[FormComponent] deleteForm error:' + error);
let commonEventPublishData = {
data: error.code.toString(),
parameters: {
"formId" : this.deleteId.toString()
}
};
commonEvent.publish(this.formOnErrorEvent, commonEventPublishData, this.publishOnErrorCallBack);
});
console.log("[FormComponent.host] deleteForm end");
}, 1000);
} else {
let 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.deleteId.toString()
}
};
commonEvent.publish(this.formOnErrorEvent, commonEventPublishData, this.publishOnErrorCallBack);
} 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
{
"string": [
{
"name": "entry_MainAbility",
"value": "formhostB"
},
{
"name": "description_mainability",
"value": "ETS_Empty Ability"
}
]
}
\ No newline at end of file
# 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("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("FormSystemHostI") {
hap_profile = "./entry/src/main/config.json"
deps = [
":hjs_demo_js_assets",
":hjs_demo_resources",
]
ets2abc = true
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "FormSystemHostI"
}
ohos_js_assets("hjs_demo_js_assets") {
source_dir = "./entry/src/main/ets/MainAbility"
}
ohos_resources("hjs_demo_resources") {
sources = [ "./entry/src/main/resources" ]
hap_profile = "./entry/src/main/config.json"
}
{
"description": "Configuration for hjunit demo Tests"
}
{
"app": {
"bundleName": "com.ohos.st.formsystemhosti",
"vendor": "ohos",
"version": {
"code": 1000000,
"name": "1.0.0"
},
"apiVersion": {
"compatible": 7,
"releaseType": "Release",
"target": 7
}
},
"deviceConfig": {},
"module": {
"package": "com.ohos.st.formsystemhosti",
"name": ".FormStHostAppI",
"mainAbility": ".MainAbility",
"deviceType": [
"phone"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "entry",
"moduleType": "entry",
"installationFree": false
},
"abilities": [
{
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
],
"visible": true,
"name": ".MainAbility",
"srcLanguage": "ets",
"icon": "$media:icon",
"description": "$string:description_mainability",
"label": "$string:entry_MainAbility",
"type": "page",
"launchType": "standard"
}
],
"js": [
{
"mode": {
"syntax": "ets",
"type": "pageAbility"
},
"pages": [
"pages/index"
],
"name": ".MainAbility",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
}
],
"defPermissions": [
{
"availableScope": [],
"grantMode": "system_grant",
"name": "FMS_FormDelete_commonEvent"
},
{
"availableScope": [],
"grantMode": "system_grant",
"name": "FMS_FormOnAcquired_commonEvent"
},
{
"availableScope": [],
"grantMode": "system_grant",
"name": "FMS_FormOnError_commonEvent"
},
{
"availableScope": [],
"grantMode": "system_grant",
"name": "FMS_FormOnDeleted_commonEvent"
},
{
"availableScope": [],
"grantMode": "system_grant",
"name": "FMS_FormOnState_commonEvent"
}
],
"reqPermissions": [
{
"name": "FMS_FormOnAcquired_commonEvent"
},
{
"name": "FMS_FormDelete_commonEvent"
},
{
"name": "FMS_FormOnError_commonEvent"
},
{
"name": "FMS_FormOnDeleted_commonEvent"
},
{
"name": "FMS_FormOnState_commonEvent"
},
{
"name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"
},
{
"name": "ohos.permission.INSTALL_BUNDLE"
},
{
"name": "ohos.permission.LISTEN_BUNDLE_CHANGE"
},
{
"name": "ohos.permission.REQUIRE_FORM"
}
]
}
}
\ No newline at end of file
/*
* 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.
*/
export default {
onCreate() {
console.info('[FormComponent.host] Application onCreate')
},
onDestroy() {
console.info('[FormComponent.host] Application onDestroy')
},
}
\ No newline at end of file
/*
* 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
/*
* 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';
import FormViewModel from './FormViewModel.ets';
@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 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 formOnAcquiredEvent = "FMS_FormOnAcquired_commonEvent";
private formCastEvent = "FMS_FormCast_commonEvent";
private formOnErrorEvent = "FMS_FormOnError_commonEvent";
private subscriberDel;
private subscriberFormDeleteEvent = {
events: ["FMS_FormDelete_commonEvent"],
};
private publishOnErrorCallBack() {
this.canCreateForm = false;
console.info("====>formOnErrorEvent Publish CallBack ====>");
}
private publishOnAcquiredCallBack() {
console.info("====>formOnAcquiredEvent Publish CallBack ====>");
}
private publishCastCallBack() {
console.info("====>formCastEvent Publish CallBack ====>");
}
private deleteCallBack(err, data) {
console.info("!!!====>formsystemhost deleteCallBack start:====>" + JSON.stringify(data));
if (data.bundleName && data.bundleName != "com.ohos.st.formsystemhost") {
return;
}
formManager.deleteForm(data.data)
.then((data2) => {
console.info('[FormComponent] deleteForm result:' + data2);
});
this.canCreateForm = false;
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;
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.castForm) {
this.castForm = want.parameters.castForm;
}
if (want.parameters.dimension) {
this.dimension = want.parameters.dimension;
}
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;
}
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.info("formsystemhost deleteForm start");
formManager.deleteForm(this.deleteId)
.then((data) => {
console.info('formsystemhost deleteForm result:' + data);
let commonEventPublishData = {
data: data.toString(),
parameters: {
"formId": this.deleteId.toString()
}
};
commonEvent.publish(this.formOnErrorEvent, commonEventPublishData, this.publishOnErrorCallBack);
})
.catch((error) => {
console.info('[FormComponent] deleteForm error:' + error);
let commonEventPublishData = {
data: error.code.toString(),
parameters: {
"formId": this.deleteId.toString()
}
};
commonEvent.publish(this.formOnErrorEvent, commonEventPublishData, this.publishOnErrorCallBack);
});
console.info("formsystemhost deleteForm end");
}
if (!want.parameters.isCreate && this.castForm) {
console.info("[FormComponent.host] castTempForm start");
formManager.castTempForm(this.temporaryId)
.then((data) => {
console.info('[FormComponent] castTempForm result:' + data);
setTimeout(() => {
let commonEventPublishData = {
data: data.toString(),
parameters: {
"formId": this.temporaryId.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.temporaryId.toString()
}
};
commonEvent.publish(this.formCastEvent, commonEventPublishData, this.publishCastCallBack);
}, 5);
});
console.info("[FormComponent.host] castTempForm end");
}
})
.catch((error: any) => {
console.error('[FormComponent] Operation failed. Cause: ' + JSON.stringify(error));
})
console.info(`[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.info("[FormComponent.host] get form, form id:" + form.id);
this.formId = form.id;
if (this.castForm) {
console.info("[FormComponent.host] castTempForm start");
formManager.castTempForm(this.temporaryId)
.then((data) => {
console.info('[FormComponent] castTempForm result:' + data);
setTimeout(() => {
let commonEventPublishData = {
data: data.toString(),
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.temporaryId.toString()
}
};
commonEvent.publish(this.formCastEvent, commonEventPublishData, this.publishCastCallBack);
}, 5);
});
console.info("[FormComponent.host] castTempForm end");
} else if (this.deleteForm) {
console.info("[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: data.toString(),
parameters: {
"formId": this.deleteId.toString()
}
};
commonEvent.publish(this.formOnErrorEvent, commonEventPublishData, this.publishOnErrorCallBack);
})
.catch((error) => {
console.info('[FormComponent] deleteForm error:' + error);
let commonEventPublishData = {
data: error.code.toString(),
parameters: {
"formId": this.deleteId.toString()
}
};
commonEvent.publish(this.formOnErrorEvent, commonEventPublishData, this.publishOnErrorCallBack);
});
console.info("[FormComponent.host] deleteForm end");
}, 1000);
} else {
let commonEventPublishData = {
data: this.formId.toString(),
parameters: {
"formId": this.deleteId.toString()
}
};
commonEvent.publish(this.formOnAcquiredEvent, commonEventPublishData, this.publishOnAcquiredCallBack);
}
})
.onUninstall((info) => {
console.info("[FormComponent] onUninstall:" + JSON.stringify(info));
})
.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,
parameters: {
"formId": this.formId.toString()
}
};
commonEvent.publish(this.formOnErrorEvent, commonEventPublishData, this.publishOnErrorCallBack);
} 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
{
"string": [
{
"name": "entry_MainAbility",
"value": "formhostI"
},
{
"name": "description_mainability",
"value": "ETS_Empty Ability"
}
]
}
\ No newline at end of file
# 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("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("FormSystemHostJ") {
hap_profile = "./entry/src/main/config.json"
deps = [
":hjs_demo_js_assets",
":hjs_demo_resources",
]
ets2abc = true
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "FormSystemHostJ"
}
ohos_js_assets("hjs_demo_js_assets") {
source_dir = "./entry/src/main/ets/MainAbility"
}
ohos_resources("hjs_demo_resources") {
sources = [ "./entry/src/main/resources" ]
hap_profile = "./entry/src/main/config.json"
}
{
"description": "Configuration for hjunit demo Tests"
}
{
"app": {
"bundleName": "com.ohos.st.formsystemhostj",
"vendor": "ohos",
"version": {
"code": 1000000,
"name": "1.0.0"
},
"apiVersion": {
"compatible": 7,
"releaseType": "Release",
"target": 7
}
},
"deviceConfig": {},
"module": {
"package": "com.ohos.st.formsystemhostj",
"name": ".FormStHostApp",
"mainAbility": ".MainAbility",
"deviceType": [
"phone"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "entry",
"moduleType": "entry",
"installationFree": false
},
"abilities": [
{
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
],
"visible": true,
"name": ".MainAbility",
"srcLanguage": "ets",
"icon": "$media:icon",
"description": "$string:description_mainability",
"label": "$string:entry_MainAbility",
"type": "page",
"launchType": "standard"
}
],
"js": [
{
"mode": {
"syntax": "ets",
"type": "pageAbility"
},
"pages": [
"pages/index"
],
"name": ".MainAbility",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
}
],
"defPermissions": [
{
"availableScope": [],
"grantMode": "system_grant",
"name": "FMS_FormDelete_commonEvent"
},
{
"availableScope": [],
"grantMode": "system_grant",
"name": "FMS_FormOnAcquired_commonEvent"
},
{
"availableScope": [],
"grantMode": "system_grant",
"name": "FMS_FormOnError_commonEvent"
},
{
"availableScope": [],
"grantMode": "system_grant",
"name": "FMS_FormCast_commonEvent"
}
],
"reqPermissions": [
{
"name": "FMS_FormOnAcquired_commonEvent"
},
{
"name": "FMS_FormDelete_commonEvent"
},
{
"name": "FMS_FormOnError_commonEvent"
},
{
"name": "FMS_FormCast_commonEvent"
},
{
"name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"
},
{
"name": "ohos.permission.INSTALL_BUNDLE"
},
{
"name": "ohos.permission.LISTEN_BUNDLE_CHANGE"
},
{
"name": "ohos.permission.REQUIRE_FORM"
}
]
}
}
\ No newline at end of file
/*
* 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.
*/
export default {
onCreate() {
console.info('[FormComponent.host] Application onCreate')
},
onDestroy() {
console.info('[FormComponent.host] Application onDestroy')
},
}
\ No newline at end of file
/*
* 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
/*
* 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 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 formOnAcquiredEvent = "FMS_FormOnAcquired_commonEvent";
private formCastEvent = "FMS_FormCast_commonEvent";
private formOnErrorEvent = "FMS_FormOnError_commonEvent";
private subscriberDel;
private subscriberFormDeleteEvent = {
events: ["FMS_FormDelete_commonEvent"],
};
private publishOnErrorCallBack() {
this.canCreateForm = false;
console.debug("====>formOnErrorEvent Publish CallBack ====>");
}
private publishOnAcquiredCallBack() {
console.debug("====>formOnAcquiredEvent Publish CallBack ====>");
}
private publishCastCallBack() {
console.debug("====>formCastEvent Publish CallBack ====>");
}
private deleteCallBack(err, data) {
console.info("!!!====>formsystemhostj deleteCallBack start:====>" + JSON.stringify(data));
if(data.bundleName && data.bundleName != "com.ohos.st.formsystemhostj") {
return;
}
formManager.deleteForm(data.data)
.then((data2) => {
console.info('[FormComponent] deleteForm result:' + data2);
});
this.canCreateForm = false;
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;
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;
this.moduleName = want.parameters.moduleName;
if(want.parameters.temporary) {
this.temporary = want.parameters.temporary;
}
console.log("formsystemhostj dimension1:" + this.dimension);
if(want.parameters.dimension) {
this.dimension = want.parameters.dimension;
}
console.log("formsystemhostj dimension2:" + this.dimension);
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;
}
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("formsystemhostj deleteForm start");
formManager.deleteForm(this.deleteId)
.then((data) => {
console.info('formsystemhostj deleteForm result:' + data);
let commonEventPublishData = {
data: data.toString(),
parameters: {
"formId" : this.deleteId.toString()
}
};
commonEvent.publish(this.formOnErrorEvent, commonEventPublishData, this.publishOnErrorCallBack);
})
.catch((error) => {
console.info('[FormComponent] deleteForm error:' + error);
let commonEventPublishData = {
data: error.code.toString(),
parameters: {
"formId" : this.deleteId.toString()
}
};
commonEvent.publish(this.formOnErrorEvent, commonEventPublishData, this.publishOnErrorCallBack);
});
console.log("formsystemhostj deleteForm end");
}
if(!want.parameters.isCreate && this.castForm) {
console.log("[FormComponent.host] castTempForm start");
formManager.castTempForm(this.temporaryId)
.then((data) => {
console.info('[FormComponent] castTempForm result:' + data);
setTimeout(() => {
let commonEventPublishData = {
data: data.toString(),
parameters: {
"formId" : this.temporaryId.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.temporaryId.toString()
}
};
commonEvent.publish(this.formCastEvent, commonEventPublishData, this.publishCastCallBack);
}, 5);
});
console.log("[FormComponent.host] castTempForm 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: data.toString(),
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.temporaryId.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);
let commonEventPublishData = {
data: data.toString(),
parameters: {
"formId" : this.deleteId.toString()
}
};
commonEvent.publish(this.formOnErrorEvent, commonEventPublishData, this.publishOnErrorCallBack);
})
.catch((error) => {
console.info('[FormComponent] deleteForm error:' + error);
let commonEventPublishData = {
data: error.code.toString(),
parameters: {
"formId" : this.deleteId.toString()
}
};
commonEvent.publish(this.formOnErrorEvent, commonEventPublishData, this.publishOnErrorCallBack);
});
console.log("[FormComponent.host] deleteForm end");
}, 1000);
} else {
let commonEventPublishData = {
data: this.formId.toString(),
parameters: {
"formId" : this.deleteId.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.formOnErrorEvent, commonEventPublishData, this.publishOnErrorCallBack);
} 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
{
"string": [
{
"name": "entry_MainAbility",
"value": "formhostJ"
},
{
"name": "description_mainability",
"value": "ETS_Empty Ability"
}
]
}
\ No newline at end of file
/*
* 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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册