diff --git a/ability/BUILD.gn b/ability/BUILD.gn index d0cd55395e5270d126378ae55e0369a20224a053..140c0479ca397fcde1b088c38d8a0cbd3c79d3ab 100644 --- a/ability/BUILD.gn +++ b/ability/BUILD.gn @@ -18,6 +18,7 @@ group("ability") { if (is_standard_system) { deps = [ "ability_runtime:ability_runtime", + "crossplatform:ability_crossplatform", "dmsfwk:dmsfwk", ] } diff --git a/ability/crossplatform/BUILD.gn b/ability/crossplatform/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..2bb825978c46925ebac7ad2c75c9fff6cac16561 --- /dev/null +++ b/ability/crossplatform/BUILD.gn @@ -0,0 +1,21 @@ +# Copyright (c) 2023 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("//build/ohos_var.gni") + +group("ability_crossplatform") { + testonly = true + if (is_standard_system) { + deps = [ "ability_runtime:ability_crossplatform_runtime" ] + } +} diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsFeatureTest/AppScope/app.json b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsFeatureTest/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..c3e76e00eb5f0cc7c1cd5afdaec67e802bff6dba --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsFeatureTest/AppScope/app.json @@ -0,0 +1,16 @@ +{ + "app": { + "bundleName": "com.test.lifecycle_crossplatform_xts", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name", + "minAPIVersion": 10, + "targetAPIVersion": 10, + "car": { + "apiCompatibleVersion": 10, + "singleUser": false + } + } +} diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsFeatureTest/AppScope/resources/base/element/string.json b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsFeatureTest/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..3811bc441fc0f128eb4d14c53ed463ffb8dc3811 --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsFeatureTest/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "xtsDemo1" + } + ] +} diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsFeatureTest/AppScope/resources/base/media/app_icon.png b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsFeatureTest/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsFeatureTest/AppScope/resources/base/media/app_icon.png differ diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsFeatureTest/BUILD.gn b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsFeatureTest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..38754c9cbf51ec1b06483b59ff022855b2d14c6a --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsFeatureTest/BUILD.gn @@ -0,0 +1,40 @@ +# Copyright (c) 2023 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_hap_assist_suite("ActsLifeCycleEtsFeatureTest") { + hap_profile = "src/main/module.json" + deps = [ + ":windowStage_js_assets", + ":windowStage_resources", + ] + ets2abc = true + certificate_profile = "./signature/openharmony_sx.p7b" + + hap_name = "ActsLifeCycleEtsFeatureTest" + subsystem_name = "ability" + part_name = "ability_runtime" +} +ohos_app_scope("windowStage_app_profile") { + app_profile = "AppScope/app.json" + sources = [ "AppScope/resources" ] +} +ohos_js_assets("windowStage_js_assets") { + source_dir = "src/main/ets" +} +ohos_resources("windowStage_resources") { + sources = [ "src/main/resources" ] + deps = [ ":windowStage_app_profile" ] + hap_profile = "src/main/module.json" +} diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsFeatureTest/signature/openharmony_sx.p7b b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsFeatureTest/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..88ab852518707e61edaf4e1c84bbbf431333bf4f Binary files /dev/null and b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsFeatureTest/signature/openharmony_sx.p7b differ diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsFeatureTest/src/main/ets/Application/AbilityStage.ts b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsFeatureTest/src/main/ets/Application/AbilityStage.ts new file mode 100644 index 0000000000000000000000000000000000000000..5f781eef66760e9268ec99f02a6d758a49983cfc --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsFeatureTest/src/main/ets/Application/AbilityStage.ts @@ -0,0 +1,7 @@ +import AbilityStage from '@ohos.app.ability.AbilityStage'; + +export default class MyAbilityStage extends AbilityStage { + onCreate() { + console.log("[Demo] MyAbilityStage onCreate") + } +} \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsFeatureTest/src/main/ets/mainability/MainAbility.ts b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsFeatureTest/src/main/ets/mainability/MainAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..3270d9cdfd70b020b363ca7edb0b8c94606dbf9c --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsFeatureTest/src/main/ets/mainability/MainAbility.ts @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2023 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 Ability from '@ohos.app.ability.UIAbility' +const abilityname = 'FeatureMainAbility'; + +export default class MainAbility extends Ability { + onCreate(want, launchParam) { + console.log("[Demo] MainAbility onCreate") + globalThis.abilityWant1 = want; + console.log("[Demo] MainAbility context: " + JSON.stringify(this.context)); + var listKey1 = []; + let AbilityLifecycleCallback = { + onAbilityCreate(ability) { + console.log("[Demo] AbilityLifecycleCallback1 onAbilityCreate ability:" + + JSON.stringify(ability)); + console.log("[Demo] AbilityLifecycleCallback1 onAbilityCreate abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityCreate"); + listKey1.push(abilityname + " onAbilityCreate"); + console.log("[Demo] 1listKey1:" + JSON.stringify(listKey1)); + }, + onWindowStageCreate(ability, windowStage) { + console.log("[Demo] AbilityLifecycleCallback1 onWindowStageCreate ability:" + + JSON.stringify(ability)); + console.log("[Demo] AbilityLifecycleCallback1 onWindowStageCreate abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onWindowStageCreate"); + listKey1.push(abilityname + " onWindowStageCreate"); + console.log("[Demo] 2listKey1:" + JSON.stringify(listKey1)); + }, + onWindowStageActive(ability, windowStage) { + console.log(abilityname + " onWindowStageActive") + }, + onWindowStageInactive(ability, windowStage) { + console.log(abilityname + " onWindowStageInactive") + }, + onWindowStageDestroy(ability, windowStage) { + console.log("[Demo] AbilityLifecycleCallback1 onWindowStageDestroy ability:" + + JSON.stringify(ability)); + listKey1.push(abilityname + " onWindowStageDestroy"); + console.log("[Demo] 3listKey1:" + JSON.stringify(listKey1)); + }, + onAbilityDestroy(ability) { + console.log("[Demo] AbilityLifecycleCallback1 onAbilityDestroy ability:" + + JSON.stringify(ability)); + console.log("[Demo] AbilityLifecycleCallback1 onAbilityDestroy abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityDestroy"); + listKey1.push(abilityname + " onAbilityDestroy"); + console.log("[Demo] 4listKey1:" + JSON.stringify(listKey1)); + }, + onAbilityForeground(ability) { + console.log("[Demo] AbilityLifecycleCallback1 onAbilityForeground ability:" + + JSON.stringify(ability)); + console.log("[Demo] AbilityLifecycleCallback1 onAbilityForeground abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityForeground"); + listKey1.push(abilityname + " onAbilityForeground"); + console.log("[Demo] 5listKey1:" + JSON.stringify(listKey1)); + }, + onAbilityBackground(ability) { + console.log("[Demo] AbilityLifecycleCallback1 onAbilityBackground ability:" + + JSON.stringify(ability)); + console.log("[Demo] AbilityLifecycleCallback1 onAbilityBackground abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityBackground"); + listKey1.push(abilityname + " onAbilityBackground"); + console.log("[Demo] 6listKey1:" + JSON.stringify(listKey1)); + }, + onAbilityContinue(ability) { + console.log("[Demo] AbilityLifecycleCallback1 onAbilityContinue ability:" + + JSON.stringify(ability)); + console.log("[Demo] AbilityLifecycleCallback1 onAbilityContinue abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityContinue"); + listKey1.push(abilityname + " onAbilityContinue"); + console.log("[Demo] 7listKey1:" + JSON.stringify(listKey1)); + } + } + globalThis.applicationContext1 = this.context.getApplicationContext(); + let lifecycleid = globalThis.applicationContext1.on('abilityLifecycle', AbilityLifecycleCallback); + console.log("[Demo] registerAbilityLifecycleCallback1 number: " + JSON.stringify(lifecycleid)); + setTimeout(function () { + console.log("[Demo] registerAbilityLifecycleCallback1 listKey: " + JSON.stringify(listKey1)); + globalThis.featureList1 = listKey1; + globalThis.featureCallbackid1 = lifecycleid; + }, 1500); + } + + onDestroy() { + console.log("[Demo] MainAbility onDestroy") + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log("[Demo] MainAbility onWindowStageCreate") + globalThis.featureAbilityContext = this.context; + + windowStage.loadContent('pages/Index', (err, data) => { + if (err.code) { + console.log('MainAbility loadContent error'); + return; + } + console.log('MainAbility loadContent success'); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + console.log("[Demo] MainAbility onWindowStageDestroy") + } + + onForeground() { + // Ability has brought to foreground + console.log("[Demo] MainAbility onForeground") + } + + onBackground() { + // Ability has back to background + console.log("[Demo] MainAbility onBackground") + } +}; diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsFeatureTest/src/main/ets/pages/Index.ets b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsFeatureTest/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..326276b9ddb3dd8a930d0bbc8677d5aaad64834b --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsFeatureTest/src/main/ets/pages/Index.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2023 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. + */ + +@Entry +@Component +struct Index { + @State message: string = 'Hello World' + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + } + .height('100%') + } +} \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsFeatureTest/src/main/module.json b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsFeatureTest/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..0c57771e0a6064ad649d2df63cea338c55f2f46d --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsFeatureTest/src/main/module.json @@ -0,0 +1,36 @@ +{ + "module": { + "name": "feature", + "type": "feature", + "description": "$string:module_test_desc", + "mainElement": "MainAbility", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "MainAbility", + "srcEntry": "./ets/mainability/MainAbility.ts", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "exported": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsFeatureTest/src/main/resources/base/element/color.json b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsFeatureTest/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsFeatureTest/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsFeatureTest/src/main/resources/base/element/string.json b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsFeatureTest/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..65d8fa5a7cf54aa3943dcd0214f58d1771bc1f6c --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsFeatureTest/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_test_desc", + "value": "test ability description" + }, + { + "name": "TestAbility_desc", + "value": "the test ability" + }, + { + "name": "TestAbility_label", + "value": "test label" + } + ] +} \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsFeatureTest/src/main/resources/base/media/icon.png b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsFeatureTest/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsFeatureTest/src/main/resources/base/media/icon.png differ diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsFeatureTest/src/main/resources/base/profile/test_pages.json b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsFeatureTest/src/main/resources/base/profile/test_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsFeatureTest/src/main/resources/base/profile/test_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/AppScope/app.json b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..c3e76e00eb5f0cc7c1cd5afdaec67e802bff6dba --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/AppScope/app.json @@ -0,0 +1,16 @@ +{ + "app": { + "bundleName": "com.test.lifecycle_crossplatform_xts", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name", + "minAPIVersion": 10, + "targetAPIVersion": 10, + "car": { + "apiCompatibleVersion": 10, + "singleUser": false + } + } +} diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/AppScope/resources/base/element/string.json b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..3811bc441fc0f128eb4d14c53ed463ffb8dc3811 --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "xtsDemo1" + } + ] +} diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/AppScope/resources/base/media/app_icon.png b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/AppScope/resources/base/media/app_icon.png differ diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/BUILD.gn b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..319b8f92a116dbf8cde11cedc1f53f03da7c7f3d --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/BUILD.gn @@ -0,0 +1,40 @@ +# Copyright (c) 2023 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("ActsLifeCycleEtsTest") { + hap_profile = "src/main/module.json" + deps = [ + ":windowStage_js_assets", + ":windowStage_resources", + ] + ets2abc = true + certificate_profile = "./signature/openharmony_sx.p7b" + + hap_name = "ActsLifeCycleEtsTest" + subsystem_name = "ability" + part_name = "ability_runtime" +} +ohos_app_scope("windowStage_app_profile") { + app_profile = "AppScope/app.json" + sources = [ "AppScope/resources" ] +} +ohos_js_assets("windowStage_js_assets") { + source_dir = "src/main/ets" +} +ohos_resources("windowStage_resources") { + sources = [ "src/main/resources" ] + deps = [ ":windowStage_app_profile" ] + hap_profile = "src/main/module.json" +} diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/Test.json b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..8e7a461d2cfcf86bf32df20f53d49e20144cb771 --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/Test.json @@ -0,0 +1,22 @@ +{ + "description": "Configuration for hjunit demo Tests", + "driver": { + "type": "OHJSUnitTest", + "test-timeout": "60000", + "shell-timeout": "60000", + "testcase-timeout": 15000, + "bundle-name": "com.test.lifecycle_crossplatform_xts", + "module-name": "entry_test" + }, + "kits": [ + { + "test-file-name": [ + "commonTestAbilityApp.hap", + "ActsLifeCycleEtsFeatureTest.hap", + "ActsLifeCycleEtsTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/signature/openharmony_sx.p7b b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..88ab852518707e61edaf4e1c84bbbf431333bf4f Binary files /dev/null and b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/signature/openharmony_sx.p7b differ diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/Application/AbilityStage.ts b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/Application/AbilityStage.ts new file mode 100644 index 0000000000000000000000000000000000000000..674dbf6cd01426066dec6d5d12882ff1350299fb --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/Application/AbilityStage.ts @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2022 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 AbilityStage from "@ohos.app.ability.AbilityStage"; + +export default class MyAbilityStage extends AbilityStage { + onCreate() { + console.log("[Demo] MyAbilityStage onCreate") + console.log("[Demo] MyAbilityStage stagecontext: " + JSON.stringify(this.context)); + var listKey = []; + let AbilityLifecycleCallback = { + onAbilityCreate(ability) { + console.log("[Demo] AbilityLifecycleCallback onAbilityCreate ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback onAbilityCreate abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityCreate"); + listKey.push(abilityname + " onAbilityCreate"); + console.log("[Demo] 1listKey:" + JSON.stringify(listKey)); + }, + onWindowStageCreate(ability, windowStage) { + console.log("[Demo] AbilityLifecycleCallback onWindowStageCreate ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback onWindowStageCreate abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onWindowStageCreate"); + listKey.push(abilityname + " onWindowStageCreate"); + console.log("[Demo] 2listKey:" + JSON.stringify(listKey)); + }, + onWindowStageActive(ability, windowStage) { + let abilityname = ability.context.abilityInfo.name; + console.log(abilityname + " onWindowStageActive") + }, + onWindowStageInactive(ability, windowStage) { + let abilityname = ability.context.abilityInfo.name; + console.log(abilityname + " onWindowStageInactive") + }, + onWindowStageDestroy(ability, windowStage) { + console.log("[Demo] AbilityLifecycleCallback onWindowStageDestroy ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback onWindowStageDestroy abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onWindowStageDestroy"); + listKey.push(abilityname + " onWindowStageDestroy"); + console.log("[Demo] 3listKey:" + JSON.stringify(listKey)); + }, + onAbilityDestroy(ability) { + console.log("[Demo] AbilityLifecycleCallback onAbilityDestroy ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback onAbilityDestroy abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityDestroy"); + listKey.push(abilityname + " onAbilityDestroy"); + console.log("[Demo] 4listKey:" + JSON.stringify(listKey)); + }, + onAbilityForeground(ability) { + console.log("[Demo] AbilityLifecycleCallback onAbilityForeground ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback onAbilityForeground abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityForeground"); + listKey.push(abilityname + " onAbilityForeground"); + console.log("[Demo] 5listKey:" + JSON.stringify(listKey)); + }, + onAbilityBackground(ability) { + console.log("[Demo] AbilityLifecycleCallback onAbilityBackground ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback onAbilityBackground abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityBackground"); + listKey.push(abilityname + " onAbilityBackground"); + console.log("[Demo] 6listKey:" + JSON.stringify(listKey)); + }, + onAbilityContinue(ability) { + console.log("[Demo] AbilityLifecycleCallback onAbilityContinue ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback onAbilityContinue abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityContinue"); + listKey.push(abilityname + " onAbilityContinue"); + console.log("[Demo] 7listKey:" + JSON.stringify(listKey)); + } + } + globalThis.applicationContext = this.context.getApplicationContext(); + console.log("[Demo] stage applicationContext: " + JSON.stringify(globalThis.applicationContext)); + let lifecycleid = globalThis.applicationContext.on('abilityLifecycle', AbilityLifecycleCallback); + console.log("[Demo] registerAbilityLifecycleCallback number: " + JSON.stringify(lifecycleid)); + setTimeout(function () { + console.log("[Demo] AbilityLifecycleCallback listKey : " + JSON.stringify(listKey)); + globalThis.list = listKey; + globalThis.callbackid = lifecycleid; + }, 2000); + } +} \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/Hap1MainAbility1/Hap1MainAbility1.ts b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/Hap1MainAbility1/Hap1MainAbility1.ts new file mode 100644 index 0000000000000000000000000000000000000000..9c82b95eb39dd1de16d0cc837b0967181d79756c --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/Hap1MainAbility1/Hap1MainAbility1.ts @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2022 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 Ability from '@ohos.app.ability.UIAbility' + +export default class Hap1MainAbility1 extends Ability { + onCreate(want, launchParam) { + console.log("[Demo] Hap1MainAbility1 onCreate") + globalThis.ability1Hap1Want = want; + setTimeout(() => { + this.context.terminateSelf().then((data) => { + console.log("Hap1MainAbility1 EventTest terminateSelf data: " + JSON.stringify(data)); + }).catch((error) => { + console.log("Hap1MainAbility1 EventTest terminateSelf error: " + JSON.stringify(error)); + }) + }, 2000) + } + + onDestroy() { + console.log("[Demo] Hap1MainAbility1 onDestroy") + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log("[Demo] Hap1MainAbility1 onWindowStageCreate") + + windowStage.loadContent('testability/pages/indexh1a1', (err, data) => { + if (err.code) { + console.log('Hap1MainAbility1 loadContent error'); + return; + } + console.log('Hap1MainAbility1 loadContent success'); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + console.log("[Demo] Hap1MainAbility1 onWindowStageDestroy") + } + + onForeground() { + // Ability has brought to foreground + console.log("[Demo] Hap1MainAbility1 onForeground") + } + + onBackground() { + // Ability has back to background + console.log("[Demo] Hap1MainAbility1 onBackground") + } +}; diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/Hap1MainAbility2/Hap1MainAbility2.ts b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/Hap1MainAbility2/Hap1MainAbility2.ts new file mode 100644 index 0000000000000000000000000000000000000000..49c1c33a44ec27464be1214f05a27aa626e2282c --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/Hap1MainAbility2/Hap1MainAbility2.ts @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2022 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 Ability from '@ohos.app.ability.UIAbility' + +export default class Hap1MainAbility2 extends Ability { + onCreate(want, launchParam) { + console.log("[Demo] Hap1MainAbility2 onCreate") + globalThis.ability2Hap1Want = want; + setTimeout(() => { + this.context.terminateSelf().then((data) => { + console.log("Hap1MainAbility2 EventTest terminateSelf data: " + JSON.stringify(data)); + }).catch((error) => { + console.log("Hap1MainAbility2 EventTest terminateSelf error: " + JSON.stringify(error)); + }) + }, 2000) + } + + onDestroy() { + console.log("[Demo] Hap1MainAbility2 onDestroy") + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log("[Demo] Hap1MainAbility2 onWindowStageCreate") + + windowStage.loadContent('testability/pages/indexh1a2', (err, data) => { + if (err.code) { + console.log('Hap1MainAbility2 loadContent error'); + return; + } + console.log('Hap1MainAbility2 loadContent success'); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + console.log("[Demo] Hap1MainAbility2 onWindowStageDestroy") + } + + onForeground() { + // Ability has brought to foreground + console.log("[Demo] Hap1MainAbility2 onForeground") + } + + onBackground() { + // Ability has back to background + console.log("[Demo] Hap1MainAbility2 onBackground") + } +}; \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/MainAbility1/MainAbility1.ts b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/MainAbility1/MainAbility1.ts new file mode 100644 index 0000000000000000000000000000000000000000..a05411d74e2efba8d61db1d4f0e474cf781651d5 --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/MainAbility1/MainAbility1.ts @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2022 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 Ability from '@ohos.app.ability.UIAbility' + +export default class MainAbility1 extends Ability { + onCreate(want, launchParam) { + console.log("[Demo] MainAbility1 onCreate") + globalThis.abilityWant1 = want; + console.log("[Demo] MainAbility1 context: " + JSON.stringify(this.context)); + var listKey1 = []; + let AbilityLifecycleCallback = { + onAbilityCreate(ability) { + console.log("[Demo] AbilityLifecycleCallback1 onAbilityCreate ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback1 onAbilityCreate abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityCreate"); + listKey1.push(abilityname + " onAbilityCreate"); + console.log("[Demo] 1listKey1:" + JSON.stringify(listKey1)); + }, + onWindowStageCreate(ability, windowStage) { + console.log("[Demo] AbilityLifecycleCallback1 onWindowStageCreate ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback1 onWindowStageCreate abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onWindowStageCreate"); + listKey1.push(abilityname + " onWindowStageCreate"); + console.log("[Demo] 2listKey1:" + JSON.stringify(listKey1)); + }, + onWindowStageActive(ability, windowStage) { + let abilityname = ability.context.abilityInfo.name; + console.log(abilityname + " onWindowStageActive") + }, + onWindowStageInactive(ability, windowStage) { + let abilityname = ability.context.abilityInfo.name; + console.log(abilityname + " onWindowStageInactive") + }, + onWindowStageDestroy(ability, windowStage) { + console.log("[Demo] AbilityLifecycleCallback1 onWindowStageDestroy ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + listKey1.push(abilityname + " onWindowStageDestroy"); + console.log("[Demo] 3listKey1:" + JSON.stringify(listKey1)); + }, + onAbilityDestroy(ability) { + console.log("[Demo] AbilityLifecycleCallback1 onAbilityDestroy ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback1 onAbilityDestroy abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityDestroy"); + listKey1.push(abilityname + " onAbilityDestroy"); + console.log("[Demo] 4listKey1:" + JSON.stringify(listKey1)); + }, + onAbilityForeground(ability) { + console.log("[Demo] AbilityLifecycleCallback1 onAbilityForeground ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback1 onAbilityForeground abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityForeground"); + listKey1.push(abilityname + " onAbilityForeground"); + console.log("[Demo] 5listKey1:" + JSON.stringify(listKey1)); + }, + onAbilityBackground(ability) { + console.log("[Demo] AbilityLifecycleCallback1 onAbilityBackground ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback1 onAbilityBackground abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityBackground"); + listKey1.push(abilityname + " onAbilityBackground"); + console.log("[Demo] 6listKey1:" + JSON.stringify(listKey1)); + }, + onAbilityContinue(ability) { + console.log("[Demo] AbilityLifecycleCallback1 onAbilityContinue ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback1 onAbilityContinue abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityContinue"); + listKey1.push(abilityname + " onAbilityContinue"); + console.log("[Demo] 7listKey1:" + JSON.stringify(listKey1)); + } + } + globalThis.applicationContext1 = this.context.getApplicationContext(); + let lifecycleid = globalThis.applicationContext1.on('abilityLifecycle', AbilityLifecycleCallback); + console.log("[Demo] registerAbilityLifecycleCallback1 number: " + JSON.stringify(lifecycleid)); + setTimeout(function () { + console.log("[Demo] registerAbilityLifecycleCallback1 listKey: " + JSON.stringify(listKey1)); + globalThis.list1 = listKey1; + globalThis.callbackid1 = lifecycleid; + }, 2500); + } + + onDestroy() { + console.log("[Demo] MainAbility1 onDestroy") + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log("[Demo] MainAbility1 onWindowStageCreate") + globalThis.ability1context = this.context; + + windowStage.loadContent('testability/pages/index1', (err, data) => { + if (err.code) { + console.log('MainAbility1 loadContent error'); + return; + } + console.log('MainAbility1 loadContent success'); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + console.log("[Demo] MainAbility1 onWindowStageDestroy") + } + + onForeground() { + // Ability has brought to foreground + console.log("[Demo] MainAbility1 onForeground") + } + + onBackground() { + // Ability has back to background + console.log("[Demo] MainAbility1 onBackground") + } +}; diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/MainAbility10/MainAbility10.ts b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/MainAbility10/MainAbility10.ts new file mode 100644 index 0000000000000000000000000000000000000000..b82dff3f47c461607ced69de7be85ce2ec77380c --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/MainAbility10/MainAbility10.ts @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2022 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 Ability from '@ohos.app.ability.UIAbility' + +export default class MainAbility10 extends Ability { + onCreate(want, launchParam) { + console.log("[Demo] MainAbility10 onCreate") + globalThis.abilityWant10 = want; + var listKey10 = []; + let AbilityLifecycleCallback = { + onAbilityCreate(ability) { + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback10 onAbilityCreate abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityCreate"); + listKey10.push(abilityname + " onAbilityCreate"); + console.log("[Demo] 1listKey10:" + JSON.stringify(listKey10)); + }, + onWindowStageCreate(ability, windowStage) { + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback10 onWindowStageCreate abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onWindowStageCreate"); + listKey10.push(abilityname + " onWindowStageCreate"); + console.log("[Demo] 2listKey10:" + JSON.stringify(listKey10)); + }, + onWindowStageActive(ability, windowStage) { + let abilityname = ability.context.abilityInfo.name; + console.log(abilityname + " onWindowStageActive") + }, + onWindowStageInactive(ability, windowStage) { + let abilityname = ability.context.abilityInfo.name; + console.log(abilityname + " onWindowStageInactive") + }, + onWindowStageDestroy(ability, windowStage) { + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback10 onWindowStageDestroy abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onWindowStageDestroy"); + listKey10.push(abilityname + " onWindowStageDestroy"); + console.log("[Demo] 3listKey10:" + JSON.stringify(listKey10)); + }, + onAbilityDestroy(ability) { + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback10 onAbilityDestroy abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityDestroy"); + listKey10.push(abilityname + " onAbilityDestroy"); + console.log("[Demo] 4listKey10:" + JSON.stringify(listKey10)); + }, + onAbilityForeground(ability) { + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback10 onAbilityForeground abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityForeground"); + listKey10.push(abilityname + " onAbilityForeground"); + console.log("[Demo] 5listKey10:" + JSON.stringify(listKey10)); + }, + onAbilityBackground(ability) { + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback10 onAbilityBackground abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityBackground"); + listKey10.push(abilityname + " onAbilityBackground"); + console.log("[Demo] 6listKey10:" + JSON.stringify(listKey10)); + }, + onAbilityContinue(ability) { + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback10 onAbilityContinue abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityContinue"); + listKey10.push(abilityname + " onAbilityContinue"); + console.log("[Demo] 7listKey10:" + JSON.stringify(listKey10)); + } + } + globalThis.applicationContext10 = this.context.getApplicationContext(); + let lifecycleid = globalThis.applicationContext10.on('abilityLifecycle', AbilityLifecycleCallback); + console.log("[Demo] registerAbilityLifecycleCallback10 number: " + JSON.stringify(lifecycleid)); + setTimeout(function () { + console.log("[Demo] registerAbilityLifecycleCallback10 listKey: " + JSON.stringify(listKey10)); + globalThis.list10 = listKey10; + globalThis.callbackid10 = lifecycleid; + }, 1500); + } + + onDestroy() { + console.log("[Demo] MainAbility10 onDestroy") + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log("[Demo] MainAbility10 onWindowStageCreate") + globalThis.ability10 = this.context; + + windowStage.loadContent('testability/pages/index10', (err, data) => { + if (err.code) { + console.log('MainAbility10 loadContent error'); + return; + } + console.log('MainAbility10 loadContent success'); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + console.log("[Demo] MainAbility10 onWindowStageDestroy") + } + + onForeground() { + // Ability has brought to foreground + console.log("[Demo] MainAbility10 onForeground") + } + + onBackground() { + // Ability has back to background + console.log("[Demo] MainAbility10 onBackground") + } +}; diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/MainAbility11/MainAbility11.ts b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/MainAbility11/MainAbility11.ts new file mode 100644 index 0000000000000000000000000000000000000000..a6810a24c6b2d76f166ba628e5416b1adcbef635 --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/MainAbility11/MainAbility11.ts @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2022 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 Ability from '@ohos.app.ability.UIAbility' + +export default class MainAbility11 extends Ability { + onCreate(want, launchParam) { + console.log("[Demo] MainAbility11 onCreate") + globalThis.abilityWant11 = want; + globalThis.ability11 = this.context; + var listKey11 = []; + let AbilityLifecycleCallback = { + onAbilityCreate(ability) { + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback11 onAbilityCreate abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityCreate"); + listKey11.push(abilityname + " onAbilityCreate"); + }, + onWindowStageCreate(ability, windowStage) { + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback11 onWindowStageCreate abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onWindowStageCreate"); + listKey11.push(abilityname + " onWindowStageCreate"); + }, + onWindowStageActive(ability, windowStage) { + let abilityname = ability.context.abilityInfo.name; + console.log(abilityname + " onWindowStageActive") + }, + onWindowStageInactive(ability, windowStage) { + let abilityname = ability.context.abilityInfo.name; + console.log(abilityname + " onWindowStageInactive") + }, + onWindowStageDestroy(ability, windowStage) { + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback11 onWindowStageDestroy abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onWindowStageDestroy"); + listKey11.push(abilityname + " onWindowStageDestroy"); + }, + onAbilityDestroy(ability) { + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback11 onAbilityDestroy abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityDestroy"); + listKey11.push(abilityname + " onAbilityDestroy"); + }, + onAbilityForeground(ability) { + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback11 onAbilityForeground abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityForeground"); + listKey11.push(abilityname + " onAbilityForeground"); + }, + onAbilityBackground(ability) { + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback11 onAbilityBackground abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityBackground"); + listKey11.push(abilityname + " onAbilityBackground"); + }, + onAbilityContinue(ability) { + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback11 onAbilityContinue abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityContinue"); + listKey11.push(abilityname + " onAbilityContinue"); + } + } + globalThis.applicationContext11 = globalThis.ability11.getApplicationContext(); + let lifecycleid = globalThis.applicationContext11.on('abilityLifecycle', AbilityLifecycleCallback); + console.log("[Demo] registerAbilityLifecycleCallback11 number: " + JSON.stringify(lifecycleid)); + setTimeout(function () { + console.log("[Demo] registerAbilityLifecycleCallback11 listKey: " + JSON.stringify(listKey11)); + globalThis.list11 = listKey11; + globalThis.callbackid11 = lifecycleid; + }, 2000); + } + + onDestroy() { + console.log("[Demo] MainAbility11 onDestroy") + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log("[Demo] MainAbility11 onWindowStageCreate") + + windowStage.loadContent('testability/pages/index11', (err, data) => { + if (err.code) { + console.log('MainAbility11 loadContent error'); + return; + } + console.log('MainAbility11 loadContent success'); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + console.log("[Demo] MainAbility11 onWindowStageDestroy") + } + + onForeground() { + // Ability has brought to foreground + console.log("[Demo] MainAbility11 onForeground") + } + + onBackground() { + // Ability has back to background + console.log("[Demo] MainAbility onBackground") + } +}; diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/MainAbility12/MainAbility12.ts b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/MainAbility12/MainAbility12.ts new file mode 100644 index 0000000000000000000000000000000000000000..83200a2f3209fde9891b8ed239036fb3a0b5d8ba --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/MainAbility12/MainAbility12.ts @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2022 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 Ability from '@ohos.app.ability.UIAbility' + +export default class MainAbility12 extends Ability { + onCreate(want, launchParam) { + console.log("[Demo] MainAbility12 onCreate") + globalThis.abilityWant12 = want; + var listKey12 = []; + let AbilityLifecycleCallback = { + onAbilityCreate(ability) { + console.log("[Demo] AbilityLifecycleCallback12 onAbilityCreate ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] " + abilityname + " onAbilityCreate"); + listKey12.push(abilityname + " onAbilityCreate"); + }, + onWindowStageCreate(ability, windowStage) { + console.log("[Demo] AbilityLifecycleCallback12 onWindowStageCreate ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] " + abilityname + " onWindowStageCreate"); + listKey12.push(abilityname + " onWindowStageCreate"); + }, + onWindowStageActive(ability, windowStage) { + let abilityname = ability.context.abilityInfo.name; + console.log(abilityname + " onWindowStageActive") + }, + onWindowStageInactive(ability, windowStage) { + let abilityname = ability.context.abilityInfo.name; + console.log(abilityname + " onWindowStageInactive") + }, + onWindowStageDestroy(ability, windowStage) { + console.log("[Demo] AbilityLifecycleCallback12 onWindowStageDestroy ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] " + abilityname + " onWindowStageDestroy"); + listKey12.push(abilityname + " onWindowStageDestroy"); + }, + onAbilityDestroy(ability) { + console.log("[Demo] AbilityLifecycleCallback12 onAbilityDestroy ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] " + abilityname + " onAbilityDestroy"); + listKey12.push(abilityname + " onAbilityDestroy"); + }, + onAbilityForeground(ability) { + console.log("[Demo] AbilityLifecycleCallback12 onAbilityForeground ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] " + abilityname + " onAbilityForeground"); + listKey12.push(abilityname + " onAbilityForeground"); + }, + onAbilityBackground(ability) { + console.log("[Demo] AbilityLifecycleCallback12 onAbilityBackground ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] " + abilityname + " onAbilityBackground"); + listKey12.push(abilityname + " onAbilityBackground"); + }, + onAbilityContinue(ability) { + console.log("[Demo] AbilityLifecycleCallback12 onAbilityContinue ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] " + abilityname + " onAbilityContinue"); + listKey12.push(abilityname + " onAbilityContinue"); + } + } + globalThis.applicationContext12 = this.context.getApplicationContext(); + let lifecycleid = globalThis.applicationContext12.on('abilityLifecycle', AbilityLifecycleCallback); + console.log("[Demo] registerAbilityLifecycleCallback12 number: " + JSON.stringify(lifecycleid)); + setTimeout(function () { + console.log("[Demo] registerAbilityLifecycleCallback12 listKey: " + JSON.stringify(listKey12)); + globalThis.list12 = listKey12; + globalThis.callbackid12 = lifecycleid; + }, 1700); + } + + onDestroy() { + console.log("[Demo] MainAbility12 onDestroy") + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log("[Demo] MainAbility12 onWindowStageCreate") + globalThis.ability12 = this.context; + + windowStage.loadContent('testability/pages/index12', (err, data) => { + if (err.code) { + console.log('MainAbility12 loadContent error'); + return; + } + console.log('MainAbility12 loadContent success'); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + console.log("[Demo] MainAbility12 onWindowStageDestroy") + } + + onForeground() { + // Ability has brought to foreground + console.log("[Demo] MainAbility12 onForeground") + } + + onBackground() { + // Ability has back to background + console.log("[Demo] MainAbility12 onBackground") + } +}; diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/MainAbility13/MainAbility13.ts b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/MainAbility13/MainAbility13.ts new file mode 100644 index 0000000000000000000000000000000000000000..73fc3b6f8c23c24d1f0b002c418c8f30087b9d72 --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/MainAbility13/MainAbility13.ts @@ -0,0 +1,228 @@ +/* + * Copyright (c) 2022 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 Ability from '@ohos.app.ability.UIAbility' + +export default class MainAbility13 extends Ability { + onCreate(want, launchParam) { + console.log("[Demo] MainAbility13 onCreate") + globalThis.abilityWant1 = want; + console.log("[Demo] MainAbility13 context: " + JSON.stringify(this.context)); + var listKey1 = []; + let AbilityLifecycleCallback = { + onAbilityCreate(ability) { + console.log("[Demo] AbilityLifecycleCallback1 onAbilityCreate ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback1 onAbilityCreate abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityCreate"); + listKey1.push(abilityname + " onAbilityCreate"); + console.log("[Demo] 1listKey1:" + JSON.stringify(listKey1)); + }, + onWindowStageCreate(ability, windowStage) { + console.log("[Demo] AbilityLifecycleCallback1 onWindowStageCreate ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback1 onWindowStageCreate abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onWindowStageCreate"); + listKey1.push(abilityname + " onWindowStageCreate"); + console.log("[Demo] 2listKey1:" + JSON.stringify(listKey1)); + }, + onWindowStageActive(ability, windowStage) { + let abilityname = ability.context.abilityInfo.name; + console.log(abilityname + " onWindowStageActive") + }, + onWindowStageInactive(ability, windowStage) { + let abilityname = ability.context.abilityInfo.name; + console.log(abilityname + " onWindowStageInactive") + }, + onWindowStageDestroy(ability, windowStage) { + console.log("[Demo] AbilityLifecycleCallback1 onWindowStageDestroy ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + listKey1.push(abilityname + " onWindowStageDestroy"); + console.log("[Demo] 3listKey1:" + JSON.stringify(listKey1)); + }, + onAbilityDestroy(ability) { + console.log("[Demo] AbilityLifecycleCallback1 onAbilityDestroy ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback1 onAbilityDestroy abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityDestroy"); + listKey1.push(abilityname + " onAbilityDestroy"); + console.log("[Demo] 4listKey1:" + JSON.stringify(listKey1)); + }, + onAbilityForeground(ability) { + console.log("[Demo] AbilityLifecycleCallback1 onAbilityForeground ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback1 onAbilityForeground abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityForeground"); + listKey1.push(abilityname + " onAbilityForeground"); + console.log("[Demo] 5listKey1:" + JSON.stringify(listKey1)); + }, + onAbilityBackground(ability) { + console.log("[Demo] AbilityLifecycleCallback1 onAbilityBackground ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback1 onAbilityBackground abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityBackground"); + listKey1.push(abilityname + " onAbilityBackground"); + console.log("[Demo] 6listKey1:" + JSON.stringify(listKey1)); + }, + onAbilityContinue(ability) { + console.log("[Demo] AbilityLifecycleCallback1 onAbilityContinue ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback1 onAbilityContinue abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityContinue"); + listKey1.push(abilityname + " onAbilityContinue"); + console.log("[Demo] 7listKey1:" + JSON.stringify(listKey1)); + } + } + + var listKey2 = []; + let AbilityLifecycleCallback2 = { + onAbilityCreate(ability) { + console.log("[Demo] AbilityLifecycleCallback1 onAbilityCreate ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback1 onAbilityCreate abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityCreate"); + listKey2.push(abilityname + " onAbilityCreate"); + console.log("[Demo] 1listKey2:" + JSON.stringify(listKey2)); + }, + onWindowStageCreate(ability, windowStage) { + console.log("[Demo] AbilityLifecycleCallback1 onWindowStageCreate ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback1 onWindowStageCreate abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onWindowStageCreate"); + listKey2.push(abilityname + " onWindowStageCreate"); + console.log("[Demo] 2listKey2:" + JSON.stringify(listKey2)); + }, + onWindowStageActive(ability, windowStage) { + let abilityname = ability.context.abilityInfo.name; + console.log(abilityname + " onWindowStageActive") + }, + onWindowStageInactive(ability, windowStage) { + let abilityname = ability.context.abilityInfo.name; + console.log(abilityname + " onWindowStageInactive") + }, + onWindowStageDestroy(ability, windowStage) { + console.log("[Demo] AbilityLifecycleCallback1 onWindowStageDestroy ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + listKey2.push(abilityname + " onWindowStageDestroy"); + console.log("[Demo] 3listKey2:" + JSON.stringify(listKey2)); + }, + onAbilityDestroy(ability) { + console.log("[Demo] AbilityLifecycleCallback1 onAbilityDestroy ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback1 onAbilityDestroy abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityDestroy"); + listKey2.push(abilityname + " onAbilityDestroy"); + console.log("[Demo] 4listKey2:" + JSON.stringify(listKey2)); + }, + onAbilityForeground(ability) { + console.log("[Demo] AbilityLifecycleCallback1 onAbilityForeground ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback1 onAbilityForeground abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityForeground"); + listKey2.push(abilityname + " onAbilityForeground"); + console.log("[Demo] 5listKey2:" + JSON.stringify(listKey2)); + }, + onAbilityBackground(ability) { + console.log("[Demo] AbilityLifecycleCallback1 onAbilityBackground ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback1 onAbilityBackground abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityBackground"); + listKey2.push(abilityname + " onAbilityBackground"); + console.log("[Demo] 6listKey2:" + JSON.stringify(listKey2)); + }, + onAbilityContinue(ability) { + console.log("[Demo] AbilityLifecycleCallback1 onAbilityContinue ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback1 onAbilityContinue abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityContinue"); + listKey2.push(abilityname + " onAbilityContinue"); + console.log("[Demo] 7listKey2:" + JSON.stringify(listKey2)); + } + } + + globalThis.ability13 = this.context; + globalThis.applicationContext13 = this.context.getApplicationContext(); + let lifecycleid = globalThis.applicationContext13.on('abilityLifecycle', AbilityLifecycleCallback); + let lifecycleid2 = globalThis.applicationContext13.on('abilityLifecycle', AbilityLifecycleCallback2); + console.log("[Demo] registerAbilityLifecycleCallback1 number: " + JSON.stringify(lifecycleid)); + setTimeout(function () { + console.log("[Demo] registerAbilityLifecycleCallback1 listKey: " + JSON.stringify(listKey1)); + console.log("[Demo] registerAbilityLifecycleCallback1 listKey: " + JSON.stringify(listKey2)); + globalThis.list13 = listKey1; + globalThis.callbackid13 = lifecycleid; + + globalThis.otherList13 = listKey2; + globalThis.otherCallbackid13 = lifecycleid2; + }, 1500); + } + + onDestroy() { + console.log("[Demo] MainAbility13 onDestroy") + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log("[Demo] MainAbility13 onWindowStageCreate") + globalThis.ability1context = this.context; + + windowStage.loadContent('testability/pages/index1', (err, data) => { + if (err.code) { + console.log('MainAbility13 loadContent error'); + return; + } + console.log('MainAbility13 loadContent success'); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + console.log("[Demo] MainAbility13 onWindowStageDestroy") + } + + onForeground() { + // Ability has brought to foreground + console.log("[Demo] MainAbility13 onForeground") + } + + onBackground() { + // Ability has back to background + console.log("[Demo] MainAbility13 onBackground") + } +}; diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/MainAbility14/MainAbility14.ts b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/MainAbility14/MainAbility14.ts new file mode 100644 index 0000000000000000000000000000000000000000..1e93e990e17a78863f8002d5c51a582d96bd6ae9 --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/MainAbility14/MainAbility14.ts @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2022 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 Ability from '@ohos.app.ability.UIAbility' + +export default class MainAbility14 extends Ability { + onCreate(want, launchParam) { + console.log("[Demo] MainAbility14 onCreate") + globalThis.abilityWant14 = want; + } + + onDestroy() { + console.log("[Demo] MainAbility14 onDestroy") + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log("[Demo] MainAbility14 onWindowStageCreate") + globalThis.ability14 = this.context; + windowStage.loadContent('testability/pages/index2', (err, data) => { + if (err.code) { + console.log('MainAbility14 loadContent error'); + return; + } + console.log('MainAbility14 loadContent success'); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + console.log("[Demo] MainAbility14 onWindowStageDestroy") + } + + onForeground() { + // Ability has brought to foreground + console.log("[Demo] MainAbility14 onForeground") + } + + onBackground() { + // Ability has back to background + console.log("[Demo] MainAbility14 onBackground") + } +}; diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/MainAbility2/MainAbility2.ts b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/MainAbility2/MainAbility2.ts new file mode 100644 index 0000000000000000000000000000000000000000..b295e5eac72f026f988dd7a3b34a93a77b11b49a --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/MainAbility2/MainAbility2.ts @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2022 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 Ability from '@ohos.app.ability.UIAbility' + +export default class MainAbility2 extends Ability { + onCreate(want, launchParam) { + console.log("[Demo] MainAbility2 onCreate") + globalThis.abilityWant2 = want; + } + + onDestroy() { + console.log("[Demo] MainAbility2 onDestroy") + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log("[Demo] MainAbility2 onWindowStageCreate") + globalThis.ability2 = this.context; + windowStage.loadContent('testability/pages/index2', (err, data) => { + if (err.code) { + console.log('MainAbility2 loadContent error'); + return; + } + console.log('MainAbility2 loadContent success'); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + console.log("[Demo] MainAbility2 onWindowStageDestroy") + } + + onForeground() { + // Ability has brought to foreground + console.log("[Demo] MainAbility2 onForeground") + setTimeout(function () { + globalThis.ability2.terminateSelf() + .then((data) => { + console.info('[Demo] MainAbility2 terminateself succeeded: ' + data); + }).catch((error) => { + console.error('[Demo] MainAbility2 terminateself failed. Cause: ' + error); + }) + }, 1500); + } + + onBackground() { + // Ability has back to background + console.log("[Demo] MainAbility2 onBackground") + } +}; diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/MainAbility3/MainAbility3.ts b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/MainAbility3/MainAbility3.ts new file mode 100644 index 0000000000000000000000000000000000000000..20902279d838865fd792b56e657a6a81ffc51ecf --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/MainAbility3/MainAbility3.ts @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2022 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 Ability from '@ohos.app.ability.UIAbility' + +export default class MainAbility3 extends Ability { + onCreate(want, launchParam) { + console.log("[Demo] MainAbility3 onCreate") + globalThis.abilityWant3 = want; + + console.log("[Demo] MainAbility3 context: " + JSON.stringify(this.context)); + var listKey3 = []; + let AbilityLifecycleCallback = { + onAbilityCreate(ability) { + console.log("[Demo] AbilityLifecycleCallback3 onAbilityCreate ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback3 onAbilityCreate abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityCreate"); + listKey3.push(abilityname + " onAbilityCreate"); + console.log("[Demo] 1listKey3:" + JSON.stringify(listKey3)); + }, + onWindowStageCreate(ability, windowStage) { + console.log("[Demo] AbilityLifecycleCallback3 onWindowStageCreate ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback3 onWindowStageCreate abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onWindowStageCreate"); + listKey3.push(abilityname + " onWindowStageCreate"); + console.log("[Demo] 2listKey3:" + JSON.stringify(listKey3)); + }, + onWindowStageActive(ability, windowStage) { + let abilityname = ability.context.abilityInfo.name; + console.log(abilityname + " onWindowStageActive") + }, + onWindowStageInactive(ability, windowStage) { + let abilityname = ability.context.abilityInfo.name; + console.log(abilityname + " onWindowStageInactive") + }, + onWindowStageDestroy(ability, windowStage) { + console.log("[Demo] AbilityLifecycleCallback3 onWindowStageDestroy ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback3 onWindowStageDestroy abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onWindowStageDestroy"); + listKey3.push(abilityname + " onWindowStageDestroy"); + console.log("[Demo] 3listKey3:" + JSON.stringify(listKey3)); + }, + onAbilityDestroy(ability) { + console.log("[Demo] AbilityLifecycleCallback3 onAbilityDestroy ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback3 onAbilityDestroy abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityDestroy"); + listKey3.push(abilityname + " onAbilityDestroy"); + console.log("[Demo] 4listKey3:" + JSON.stringify(listKey3)); + }, + onAbilityForeground(ability) { + console.log("[Demo] AbilityLifecycleCallback3 onAbilityForeground ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback3 onAbilityForeground abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityForeground"); + listKey3.push(abilityname + " onAbilityForeground"); + console.log("[Demo] 5listKey3:" + JSON.stringify(listKey3)); + }, + onAbilityBackground(ability) { + console.log("[Demo] AbilityLifecycleCallback3 onAbilityBackground ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback3 onAbilityBackground abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityBackground"); + listKey3.push(abilityname + " onAbilityBackground"); + console.log("[Demo] 6listKey3:" + JSON.stringify(listKey3)); + }, + onAbilityContinue(ability) { + console.log("[Demo] AbilityLifecycleCallback3 onAbilityContinue ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback3 onAbilityContinue abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityContinue"); + listKey3.push(abilityname + " onAbilityContinue"); + console.log("[Demo] 7listKey3:" + JSON.stringify(listKey3)); + } + } + globalThis.applicationContext3 = this.context.getApplicationContext(); + let lifecycleid = globalThis.applicationContext3.on('abilityLifecycle', AbilityLifecycleCallback); + console.log("[Demo] registerAbilityLifecycleCallback3 number: " + JSON.stringify(lifecycleid)); + setTimeout(function () { + console.log("[Demo] registerAbilityLifecycleCallback3 listKey : " + JSON.stringify(listKey3)); + globalThis.list3 = listKey3; + globalThis.callbackid3 = lifecycleid; + }, 2000); + } + + onDestroy() { + console.log("[Demo] MainAbility3 onDestroy") + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log("[Demo] MainAbility3 onWindowStageCreate") + globalThis.ability3 = this.context + + windowStage.loadContent('testability/pages/index3', (err, data) => { + if (err.code) { + console.log('MainAbility3 loadContent error'); + return; + } + console.log('MainAbility3 loadContent success'); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + console.log("[Demo] MainAbility3 onWindowStageDestroy") + } + + onForeground() { + // Ability has brought to foreground + console.log("[Demo] MainAbility onForeground") + } + + onBackground() { + // Ability has back to background + console.log("[Demo] MainAbility onBackground") + } +}; diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/MainAbility4/MainAbility4.ts b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/MainAbility4/MainAbility4.ts new file mode 100644 index 0000000000000000000000000000000000000000..124636a7f8d61a43dec228d1fe82989665fa65e7 --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/MainAbility4/MainAbility4.ts @@ -0,0 +1,154 @@ +/* + * Copyright (c) 2022 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 Ability from '@ohos.app.ability.UIAbility' + +export default class MainAbility4 extends Ability { + onCreate(want, launchParam) { + console.log("[Demo] MainAbility4 onCreate") + globalThis.abilityWant4 = want; + + console.log("[Demo] MainAbility4 context: " + JSON.stringify(this.context)); + var listKey4 = []; + let AbilityLifecycleCallback = { + onAbilityCreate(ability) { + console.log("[Demo] AbilityLifecycleCallback4 onAbilityCreate ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback4 onAbilityCreate abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityCreate"); + listKey4.push(abilityname + " onAbilityCreate"); + console.log("[Demo] 1listKey4:" + JSON.stringify(listKey4)); + }, + onWindowStageCreate(ability, windowStage) { + console.log("[Demo] AbilityLifecycleCallback4 onWindowStageCreate ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback4 onWindowStageCreate abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onWindowStageCreate"); + listKey4.push(abilityname + " onWindowStageCreate"); + console.log("[Demo] 2listKey4:" + JSON.stringify(listKey4)); + }, + onWindowStageActive(ability, windowStage) { + let abilityname = ability.context.abilityInfo.name; + console.log(abilityname + " onWindowStageActive") + }, + onWindowStageInactive(ability, windowStage) { + let abilityname = ability.context.abilityInfo.name; + console.log(abilityname + " onWindowStageInactive") + }, + onWindowStageDestroy(ability, windowStage) { + console.log("[Demo] AbilityLifecycleCallback4 onWindowStageDestroy ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback4 onWindowStageDestroy abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onWindowStageDestroy"); + listKey4.push(abilityname + " onWindowStageDestroy"); + console.log("[Demo] 3listKey4:" + JSON.stringify(listKey4)); + }, + onAbilityDestroy(ability) { + console.log("[Demo] AbilityLifecycleCallback4 onAbilityDestroy ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback4 onAbilityDestroy abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityDestroy"); + listKey4.push(abilityname + " onAbilityDestroy"); + console.log("[Demo] 4listKey4:" + JSON.stringify(listKey4)); + }, + onAbilityForeground(ability) { + console.log("[Demo] AbilityLifecycleCallback4 onAbilityForeground ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback4 onAbilityForeground abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityForeground"); + listKey4.push(abilityname + " onAbilityForeground"); + console.log("[Demo] 5listKey4:" + JSON.stringify(listKey4)); + }, + onAbilityBackground(ability) { + console.log("[Demo] AbilityLifecycleCallback4 onAbilityBackground ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback4 onAbilityBackground abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityBackground"); + listKey4.push(abilityname + " onAbilityBackground"); + console.log("[Demo] 6listKey4:" + JSON.stringify(listKey4)); + }, + onAbilityContinue(ability) { + console.log("[Demo] AbilityLifecycleCallback4 onAbilityContinue ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback4 onAbilityContinue abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityContinue"); + listKey4.push(abilityname + " onAbilityContinue"); + console.log("[Demo] 7listKey4:" + JSON.stringify(listKey4)); + } + } + globalThis.applicationContext4 = this.context.getApplicationContext(); + let lifecycleid = globalThis.applicationContext4.on('abilityLifecycle', AbilityLifecycleCallback); + console.log("[Demo] registerAbilityLifecycleCallback4 number: " + JSON.stringify(lifecycleid)); + globalThis.callbackid4 = lifecycleid; + setTimeout(function () { + console.log("[Demo] registerAbilityLifecycleCallback4 listKey : " + JSON.stringify(listKey4)); + globalThis.list4 = listKey4; + }, 1500); + } + + onDestroy() { + console.log("[Demo] MainAbility4 onDestroy") + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log("[Demo] MainAbility4 onWindowStageCreate") + globalThis.ability4 = this.context; + + windowStage.loadContent('testability/pages/index4', (err, data) => { + if (err.code) { + console.log('MainAbility4 loadContent error'); + return; + } + console.log('MainAbility4 loadContent success'); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + console.log("[Demo] MainAbility4 onWindowStageDestroy") + } + + onForeground() { + // Ability has brought to foreground + console.log("[Demo] MainAbility4 onForeground") + setTimeout(function () { + globalThis.ability4.terminateSelf() + .then((data) => { + console.info('[Demo] MainAbility4 terminateself succeeded: ' + data); + }).catch((error) => { + console.error('[Demo] MainAbility4 terminateself failed. Cause: ' + error); + }) + }, 5000); + } + + onBackground() { + // Ability has back to background + console.log("[Demo] MainAbility4 onBackground") + } +}; diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/MainAbility5/MainAbility5.ts b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/MainAbility5/MainAbility5.ts new file mode 100644 index 0000000000000000000000000000000000000000..d541f633afa369a16f1eadf98970a060e5afb68f --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/MainAbility5/MainAbility5.ts @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2022 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 Ability from '@ohos.app.ability.UIAbility' + +export default class MainAbility5 extends Ability { + onCreate(want, launchParam) { + console.log("[Demo] MainAbility5 onCreate") + globalThis.abilityWant5 = want; + } + + onDestroy() { + console.log("[Demo] MainAbility5 onDestroy") + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log("[Demo] MainAbility5 onWindowStageCreate") + globalThis.ability5 = this.context; + + windowStage.loadContent('testability/pages/index5', (err, data) => { + if (err.code) { + console.log('MainAbility5 loadContent error'); + return; + } + console.log('MainAbility5 loadContent success'); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + console.log("[Demo] MainAbility5 onWindowStageDestroy") + } + + onForeground() { + // Ability has brought to foreground + console.log("[Demo] MainAbility5 onForeground") + setTimeout(function () { + globalThis.ability5.terminateSelf() + .then((data) => { + console.info('[Demo] MainAbility5 terminateself succeeded: ' + data); + }).catch((error) => { + console.error('[Demo] MainAbility5 terminateself failed. Cause: ' + error); + }) + }, 500); + } + + onBackground() { + // Ability has back to background + console.log("[Demo] MainAbility5 onBackground") + } +}; diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/MainAbility6/MainAbility6.ts b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/MainAbility6/MainAbility6.ts new file mode 100644 index 0000000000000000000000000000000000000000..8cc601d59de65c32f366e22f62bd6923e4ccd627 --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/MainAbility6/MainAbility6.ts @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2022 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 Ability from '@ohos.app.ability.UIAbility' + +export default class MainAbility6 extends Ability { + onCreate(want, launchParam) { + console.log("[Demo] MainAbility6 onCreate") + globalThis.abilityWant6 = want; + } + + onDestroy() { + console.log("[Demo] MainAbility6 onDestroy") + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log("[Demo] MainAbility6 onWindowStageCreate") + globalThis.ability6 = this.context; + + windowStage.loadContent('testability/pages/index6', (err, data) => { + if (err.code) { + console.log('MainAbility6 loadContent error'); + return; + } + console.log('MainAbility6 loadContent success'); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + console.log("[Demo] MainAbility6 onWindowStageDestroy") + } + + onForeground() { + // Ability has brought to foreground + console.log("[Demo] MainAbility6 onForeground") + + var listKey6 = []; + let AbilityLifecycleCallback = { + onAbilityCreate(ability) { + console.log("[Demo] AbilityLifecycleCallback6 onAbilityCreate ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback6 onAbilityCreate abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityCreate"); + listKey6.push(abilityname + " onAbilityCreate"); + console.log("[Demo] 1listKey6:" + JSON.stringify(listKey6)); + }, + onWindowStageCreate(ability, windowStage) { + console.log("[Demo] AbilityLifecycleCallback6 onWindowStageCreate ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback6 onWindowStageCreate abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onWindowStageCreate"); + listKey6.push(abilityname + " onWindowStageCreate"); + console.log("[Demo] 2listKey6:" + JSON.stringify(listKey6)); + }, + onWindowStageActive(ability, windowStage) { + let abilityname = ability.context.abilityInfo.name; + console.log(abilityname + " onWindowStageActive") + }, + onWindowStageInactive(ability, windowStage) { + let abilityname = ability.context.abilityInfo.name; + console.log(abilityname + " onWindowStageInactive") + }, + onWindowStageDestroy(ability, windowStage) { + console.log("[Demo] AbilityLifecycleCallback6 onWindowStageDestroy ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback6 onWindowStageDestroy abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onWindowStageDestroy"); + listKey6.push(abilityname + " onWindowStageDestroy"); + console.log("[Demo] 3listKey6:" + JSON.stringify(listKey6)); + }, + onAbilityDestroy(ability) { + console.log("[Demo] AbilityLifecycleCallback6 onAbilityDestroy ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback6 onAbilityDestroy abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityDestroy"); + listKey6.push(abilityname + " onAbilityDestroy"); + console.log("[Demo] 4listKey6:" + JSON.stringify(listKey6)); + }, + onAbilityForeground(ability) { + console.log("[Demo] AbilityLifecycleCallback6 onAbilityForeground ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback6 onAbilityForeground abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityForeground"); + listKey6.push(abilityname + " onAbilityForeground"); + console.log("[Demo] 5listKey6:" + JSON.stringify(listKey6)); + }, + onAbilityBackground(ability) { + console.log("[Demo] AbilityLifecycleCallback6 onAbilityBackground ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback6 onAbilityBackground abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityBackground"); + listKey6.push(abilityname + " onAbilityBackground"); + console.log("[Demo] 6listKey6:" + JSON.stringify(listKey6)); + }, + onAbilityContinue(ability) { + console.log("[Demo] AbilityLifecycleCallback6 onAbilityContinue ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback6 onAbilityContinue abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityContinue"); + listKey6.push(abilityname + " onAbilityContinue"); + console.log("[Demo] 7listKey6:" + JSON.stringify(listKey6)); + } + } + globalThis.applicationContext6 = globalThis.ability6.getApplicationContext(); + let lifecycleid = globalThis.applicationContext6.on('abilityLifecycle', AbilityLifecycleCallback); + console.log("[Demo] registerAbilityLifecycleCallback6 number: " + JSON.stringify(lifecycleid)); + setTimeout(function () { + console.log("[Demo] registerAbilityLifecycleCallback6 listKey: " + JSON.stringify(listKey6)); + globalThis.list6 = listKey6; + globalThis.callbackid6 = lifecycleid; + }, 1500); + } + + onBackground() { + // Ability has back to background + console.log("[Demo] MainAbility6 onBackground") + } +}; diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/MainAbility7/MainAbility7.ts b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/MainAbility7/MainAbility7.ts new file mode 100644 index 0000000000000000000000000000000000000000..b52f5df41d40d18752a809c22cc336d25e71c96c --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/MainAbility7/MainAbility7.ts @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2022 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 Ability from '@ohos.app.ability.UIAbility' + +export default class MainAbility7 extends Ability { + onCreate(want, launchParam) { + console.log("[Demo] MainAbility7 onCreate") + globalThis.abilityWant7 = want; + } + + onDestroy() { + console.log("[Demo] MainAbility7 onDestroy") + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log("[Demo] MainAbility7 onWindowStageCreate") + globalThis.ability7 = this.context; + + windowStage.loadContent('testability/pages/index7', (err, data) => { + if (err.code) { + console.log('MainAbility7 loadContent error'); + return; + } + console.log('MainAbility7 loadContent success'); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + console.log("[Demo] MainAbility7 onWindowStageDestroy") + } + + onForeground() { + // Ability has brought to foreground + console.log("[Demo] MainAbility7 onForeground") + + var listKey7 = []; + let AbilityLifecycleCallback = { + onAbilityCreate(ability) { + console.log("[Demo] AbilityLifecycleCallback7 onAbilityCreate ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback7 onAbilityCreate abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityCreate"); + listKey7.push(abilityname + " onAbilityCreate"); + console.log("[Demo] 1listKey7:" + JSON.stringify(listKey7)); + }, + onWindowStageCreate(ability, windowStage) { + console.log("[Demo] AbilityLifecycleCallback7 onWindowStageCreate ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback7 onWindowStageCreate abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onWindowStageCreate"); + listKey7.push(abilityname + " onWindowStageCreate"); + console.log("[Demo] 2listKey7:" + JSON.stringify(listKey7)); + }, + onWindowStageActive(ability, windowStage) { + let abilityname = ability.context.abilityInfo.name; + console.log(abilityname + " onWindowStageActive") + }, + onWindowStageInactive(ability, windowStage) { + let abilityname = ability.context.abilityInfo.name; + console.log(abilityname + " onWindowStageInactive") + }, + onWindowStageDestroy(ability, windowStage) { + console.log("[Demo] AbilityLifecycleCallback7 onWindowStageDestroy ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback7 onWindowStageDestroy abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onWindowStageDestroy"); + listKey7.push(abilityname + " onWindowStageDestroy"); + console.log("[Demo] 3listKey7:" + JSON.stringify(listKey7)); + }, + onAbilityDestroy(ability) { + console.log("[Demo] AbilityLifecycleCallback7 onAbilityDestroy ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback7 onAbilityDestroy abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityDestroy"); + listKey7.push(abilityname + " onAbilityDestroy"); + console.log("[Demo] 4listKey7:" + JSON.stringify(listKey7)); + }, + onAbilityForeground(ability) { + console.log("[Demo] AbilityLifecycleCallback7 onAbilityForeground ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback7 onAbilityForeground abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityForeground"); + listKey7.push(abilityname + " onAbilityForeground"); + console.log("[Demo] 5listKey7:" + JSON.stringify(listKey7)); + }, + onAbilityBackground(ability) { + console.log("[Demo] AbilityLifecycleCallback7 onAbilityBackground ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback7 onAbilityBackground abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityBackground"); + listKey7.push(abilityname + " onAbilityBackground"); + console.log("[Demo] 6listKey7:" + JSON.stringify(listKey7)); + }, + onAbilityContinue(ability) { + console.log("[Demo] AbilityLifecycleCallback7 onAbilityContinue ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback7 onAbilityContinue abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityContinue"); + listKey7.push(abilityname + " onAbilityContinue"); + console.log("[Demo] 7listKey7:" + JSON.stringify(listKey7)); + } + } + globalThis.applicationContext7 = this.context.getApplicationContext(); + let lifecycleid = globalThis.applicationContext7.on('abilityLifecycle', AbilityLifecycleCallback); + console.log("[Demo] AbilityLifecycleCallback7 number: " + JSON.stringify(lifecycleid)); + setTimeout(function () { + console.log("[Demo] AbilityLifecycleCallback7 listKey: " + JSON.stringify(listKey7)); + globalThis.list7 = listKey7; + globalThis.callbackid7 = lifecycleid; + }, 1500); + } + + onBackground() { + // Ability has back to background + console.log("[Demo] MainAbility7 onBackground") + } +}; diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/MainAbility8/MainAbility8.ts b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/MainAbility8/MainAbility8.ts new file mode 100644 index 0000000000000000000000000000000000000000..99ca094ad71c0a915d99f18252d29c3a1f96357b --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/MainAbility8/MainAbility8.ts @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2022 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 Ability from '@ohos.app.ability.UIAbility' + +export default class MainAbility8 extends Ability { + onCreate(want, launchParam) { + console.log("[Demo] MainAbility8 onCreate") + globalThis.abilityWant8 = want; + } + + onDestroy() { + console.log("[Demo] MainAbility8 onDestroy") + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log("[Demo] MainAbility8 onWindowStageCreate") + globalThis.ability8 = this.context; + + windowStage.loadContent('testability/pages/index8', (err, data) => { + if (err.code) { + console.log('MainAbility8 loadContent error'); + return; + } + console.log('MainAbility8 loadContent success'); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + console.log("[Demo] MainAbility8 onWindowStageDestroy") + } + + onForeground() { + // Ability has brought to foreground + console.log("[Demo] MainAbility8 onForeground") + var listKey8 = []; + let AbilityLifecycleCallback = { + onAbilityCreate(ability) { + console.log("[Demo] AbilityLifecycleCallback8 onAbilityCreate ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback8 onAbilityCreate abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityCreate"); + listKey8.push(abilityname + " onAbilityCreate"); + console.log("[Demo] 1listKey8:" + JSON.stringify(listKey8)); + }, + onWindowStageCreate(ability, windowStage) { + console.log("[Demo] AbilityLifecycleCallback8 onWindowStageCreate ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback8 onWindowStageCreate abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onWindowStageCreate"); + listKey8.push(abilityname + " onWindowStageCreate"); + console.log("[Demo] 2listKey8:" + JSON.stringify(listKey8)); + }, + onWindowStageActive(ability, windowStage) { + let abilityname = ability.context.abilityInfo.name; + console.log(abilityname + " onWindowStageActive") + }, + onWindowStageInactive(ability, windowStage) { + let abilityname = ability.context.abilityInfo.name; + console.log(abilityname + " onWindowStageInactive") + }, + onWindowStageDestroy(ability, windowStage) { + console.log("[Demo] AbilityLifecycleCallback8 onWindowStageDestroy ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback8 onWindowStageDestroy abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onWindowStageDestroy"); + listKey8.push(abilityname + " onWindowStageDestroy"); + console.log("[Demo] 3listKey8:" + JSON.stringify(listKey8)); + }, + onAbilityDestroy(ability) { + console.log("[Demo] AbilityLifecycleCallback8 onAbilityDestroy ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback8 onAbilityDestroy abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityDestroy"); + listKey8.push(abilityname + " onAbilityDestroy"); + console.log("[Demo] 4listKey8:" + JSON.stringify(listKey8)); + }, + onAbilityForeground(ability) { + console.log("[Demo] AbilityLifecycleCallback8 onAbilityForeground ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback8 onAbilityForeground abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityForeground"); + listKey8.push(abilityname + " onAbilityForeground"); + console.log("[Demo] 5listKey8:" + JSON.stringify(listKey8)); + }, + onAbilityBackground(ability) { + console.log("[Demo] AbilityLifecycleCallback8 onAbilityBackground ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback8 onAbilityBackground abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityBackground"); + listKey8.push(abilityname + " onAbilityBackground"); + console.log("[Demo] 6listKey8:" + JSON.stringify(listKey8)); + }, + onAbilityContinue(ability) { + console.log("[Demo] AbilityLifecycleCallback8 onAbilityContinue ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback8 onAbilityContinue abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityContinue"); + listKey8.push(abilityname + " onAbilityContinue"); + console.log("[Demo] 7listKey8:" + JSON.stringify(listKey8)); + } + } + globalThis.applicationContext8 = this.context.getApplicationContext(); + let lifecycleid = globalThis.applicationContext8.on('abilityLifecycle', AbilityLifecycleCallback); + console.log("[Demo] AbilityLifecycleCallback8 number: " + JSON.stringify(lifecycleid)); + setTimeout(function () { + console.log("[Demo] AbilityLifecycleCallback8 listKey: " + JSON.stringify(listKey8)); + globalThis.list8 = listKey8; + globalThis.callbackid8 = lifecycleid; + }, 1500); + + } + + onBackground() { + // Ability has back to background + console.log("[Demo] MainAbility8 onBackground") + } +}; diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/MainAbility9/MainAbility9.ts b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/MainAbility9/MainAbility9.ts new file mode 100644 index 0000000000000000000000000000000000000000..ad26e7c885f2811ee9cdae0ea44c194772417511 --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/MainAbility9/MainAbility9.ts @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2022 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 Ability from '@ohos.app.ability.UIAbility' + +export default class MainAbility9 extends Ability { + onCreate(want, launchParam) { + console.log("[Demo] MainAbility9 onCreate") + globalThis.abilityWant9 = want; + } + + onDestroy() { + console.log("[Demo] MainAbility9 onDestroy") + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log("[Demo] MainAbility9 onWindowStageCreate") + + windowStage.loadContent('testability/pages/index9', (err, data) => { + if (err.code) { + console.log('MainAbility9 loadContent error'); + return; + } + console.log('MainAbility9 loadContent success'); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + console.log("[Demo] MainAbility9 onWindowStageDestroy") + } + + onForeground() { + // Ability has brought to foreground + console.log("[Demo] MainAbility9 onForeground") + + var listKey9 = []; + var abilityName = ""; + let AbilityLifecycleCallback = { + onAbilityCreate(ability) { + abilityName = ability.context.abilityInfo.name; + console.log(abilityName + " onAbilityCreate") + listKey9.push(abilityName + " onAbilityCreate"); + }, + onWindowStageCreate(ability, windowStage) { + abilityName = ability.context.abilityInfo.name; + console.log(abilityName + " onWindowStageCreate") + listKey9.push(abilityName + " onWindowStageCreate"); + }, + onWindowStageActive(ability, windowStage) { + abilityName = ability.context.abilityInfo.name; + console.log(abilityName + " onWindowStageActive") + }, + onWindowStageInactive(ability, windowStage) { + abilityName = ability.context.abilityInfo.name; + console.log(abilityName + " onWindowStageInactive") + }, + onAbilityForeground(ability) { + abilityName = ability.context.abilityInfo.name; + console.log(abilityName + " onAbilityForeground") + listKey9.push(abilityName + " onAbilityForeground"); + }, + onAbilityBackground(ability) { + abilityName = ability.context.abilityInfo.name; + console.log(abilityName + " onAbilityBackground") + listKey9.push(abilityName + " onAbilityBackground"); + }, + onWindowStageDestroy(ability, windowStage) { + abilityName = ability.context.abilityInfo.name; + console.log(abilityName + " onWindowStageDestroy") + listKey9.push(abilityName + " onWindowStageDestroy"); + }, + onAbilityDestroy(ability) { + abilityName = ability.context.abilityInfo.name; + console.log(abilityName + " onAbilityDestroy") + listKey9.push(abilityName + " onAbilityDestroy"); + }, + onAbilityContinue(ability) { + abilityName = ability.context.abilityInfo.name; + console.log(abilityName + " onAbilityContinue") + listKey9.push(abilityName + " onAbilityContinue"); + } + } + globalThis.applicationContext9 = this.context.getApplicationContext(); + var callBackId = globalThis.applicationContext9.on('abilityLifecycle', AbilityLifecycleCallback); + + console.log("callBackId is aaa :" + callBackId); + setTimeout(() => { + globalThis.mainAbility9ListKey = listKey9 + globalThis.mainAbility9CallBackId = callBackId + console.log("listKey is :" + listKey9); + console.log("callBackId is :" + callBackId); + }, 3000) + } + + onBackground() { + // Ability has back to background + console.log("[Demo] MainAbility9 onBackground") + } +}; diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/MultiMainability1/MultiMainability1.ts b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/MultiMainability1/MultiMainability1.ts new file mode 100644 index 0000000000000000000000000000000000000000..e0f32aca3ec3b080cab5bcfeeb662e9fca7ed71b --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/MultiMainability1/MultiMainability1.ts @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2022 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 Ability from '@ohos.app.ability.UIAbility' + +var listKey1 = []; + +export default class MultiMainability1 extends Ability { + onCreate(want, launchParam) { + console.log("[Demo] MultiMainability1 onCreate") + globalThis.abilityWant1 = want; + console.log("[Demo] MultiMainability1 context: " + JSON.stringify(this.context)); + let AbilityLifecycleCallback = { + onAbilityCreate(ability) { + console.log("[Demo] AbilityLifecycleCallback1 onAbilityCreate ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback1 onAbilityCreate abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityCreate"); + listKey1.push(abilityname + " onAbilityCreate"); + console.log("[Demo] 1listKey1:" + JSON.stringify(listKey1)); + }, + onWindowStageCreate(ability, windowStage) { + console.log("[Demo] AbilityLifecycleCallback1 onWindowStageCreate ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback1 onWindowStageCreate abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onWindowStageCreate"); + listKey1.push(abilityname + " onWindowStageCreate"); + console.log("[Demo] 2listKey1:" + JSON.stringify(listKey1)); + }, + onWindowStageActive(ability, windowStage) { + let abilityname = ability.context.abilityInfo.name; + console.log(abilityname + " onWindowStageActive") + }, + onWindowStageInactive(ability, windowStage) { + let abilityname = ability.context.abilityInfo.name; + console.log(abilityname + " onWindowStageInactive") + }, + onWindowStageDestroy(ability, windowStage) { + console.log("[Demo] AbilityLifecycleCallback1 onWindowStageDestroy ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + listKey1.push(abilityname + " onWindowStageDestroy"); + console.log("[Demo] 3listKey1:" + JSON.stringify(listKey1)); + }, + onAbilityDestroy(ability) { + console.log("[Demo] AbilityLifecycleCallback1 onAbilityDestroy ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback1 onAbilityDestroy abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityDestroy"); + listKey1.push(abilityname + " onAbilityDestroy"); + console.log("[Demo] 4listKey1:" + JSON.stringify(listKey1)); + }, + onAbilityForeground(ability) { + console.log("[Demo] AbilityLifecycleCallback1 onAbilityForeground ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback1 onAbilityForeground abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityForeground"); + listKey1.push(abilityname + " onAbilityForeground"); + console.log("[Demo] 5listKey1:" + JSON.stringify(listKey1)); + }, + onAbilityBackground(ability) { + console.log("[Demo] AbilityLifecycleCallback1 onAbilityBackground ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback1 onAbilityBackground abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityBackground"); + listKey1.push(abilityname + " onAbilityBackground"); + console.log("[Demo] 6listKey1:" + JSON.stringify(listKey1)); + }, + onAbilityContinue(ability) { + console.log("[Demo] AbilityLifecycleCallback1 onAbilityContinue ability:" + + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log("[Demo] AbilityLifecycleCallback1 onAbilityContinue abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityContinue"); + listKey1.push(abilityname + " onAbilityContinue"); + console.log("[Demo] 7listKey1:" + JSON.stringify(listKey1)); + } + } + globalThis.applicationContext1 = this.context.getApplicationContext(); + let lifecycleid = globalThis.applicationContext1.on('abilityLifecycle', AbilityLifecycleCallback); + console.log("[Demo] registerAbilityLifecycleCallback1 number: " + JSON.stringify(lifecycleid)); + setTimeout(function () { + console.log("[Demo] registerAbilityLifecycleCallback1 listKey: " + JSON.stringify(listKey1)); + globalThis.mlist1 = listKey1; + globalThis.mCallbackid1 = lifecycleid; + }, 1000); + } + + onDestroy() { + console.log("[Demo] MultiMainability1 onDestroy") + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log("[Demo] MultiMainability1 onWindowStageCreate") + globalThis.ability1context = this.context; + + windowStage.loadContent('testability/pages/index1', (err, data) => { + if (err.code) { + console.log('MultiMainability1 loadContent error'); + return; + } + console.log('MultiMainability1 loadContent success'); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + console.log("[Demo] MultiMainability1 onWindowStageDestroy") + } + + onForeground() { + // Ability has brought to foreground + console.log("[Demo] MultiMainability1 onForeground") + } + + onBackground() { + // Ability has back to background + console.log("[Demo] MultiMainability1 onBackground") + } +}; diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestAbility/TestAbility.ets b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestAbility/TestAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..f8167330877684501b58fc6acab4931a9ef25ea5 --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestAbility/TestAbility.ets @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2023 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 UIAbility from '@ohos.app.ability.UIAbility'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; +import hilog from '@ohos.hilog'; +import { Hypium } from '@ohos/hypium'; +import testsuite from '../test/List.test'; +import window from '@ohos.window'; + +export default class TestAbility extends UIAbility { + onCreate(want, launchParam) { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onCreate'); + hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? ''); + hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:'+ JSON.stringify(launchParam) ?? ''); + var abilityDelegator: any + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var abilityDelegatorArguments: any + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!'); + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + } + + onDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageCreate'); + globalThis.abilityContext = this.context; + windowStage.loadContent('TestAbility/pages/Index', (err, data) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', + JSON.stringify(data) ?? ''); + }); + } + + onWindowStageDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageDestroy'); + } + + onForeground() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onForeground'); + } + + onBackground() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onBackground'); + } +} \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestAbility/pages/Index.ets b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestAbility/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..3e31143061bdaa9e2bda41f3b106efa1fe416f09 --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestAbility/pages/Index.ets @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2023 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 hilog from '@ohos.hilog'; + +@Entry +@Component +struct Index { + aboutToAppear() { + hilog.info(0x0000, 'testTag', '%{public}s', 'testability index aboutToAppear'); + } + @State message: string = 'Hello World' + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .width('35%') + .height('5%') + .onClick(()=>{ + }) + } + .width('100%') + } + .height('100%') + } + } \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestAbility/pages/index1.ets b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestAbility/pages/index1.ets new file mode 100644 index 0000000000000000000000000000000000000000..5f0560de7982c21e63ea0117b07f0e915168fdb8 --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestAbility/pages/index1.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2022 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. + */ +@Entry +@Component +struct Index1 { + build() { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text('Hello World Mainability1') + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestAbility/pages/index10.ets b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestAbility/pages/index10.ets new file mode 100644 index 0000000000000000000000000000000000000000..faf118b3234d5c0dc95f67e7d2da3dc53f0972d5 --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestAbility/pages/index10.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2022 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. + */ +@Entry +@Component +struct Index10 { + build() { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text('Hello World Mainability10') + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestAbility/pages/index11.ets b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestAbility/pages/index11.ets new file mode 100644 index 0000000000000000000000000000000000000000..fbcf1d266d4b9485bca7e71dce1f43ea4eb7f143 --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestAbility/pages/index11.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2022 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. + */ +@Entry +@Component +struct Index11 { + build() { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text('Hello World Mainability11') + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestAbility/pages/index12.ets b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestAbility/pages/index12.ets new file mode 100644 index 0000000000000000000000000000000000000000..054b13b6ea6352c0917b2c7f1ad1c709c8211c97 --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestAbility/pages/index12.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2022 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. + */ +@Entry +@Component +struct Index12 { + build() { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text('Hello World Mainability12') + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestAbility/pages/index2.ets b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestAbility/pages/index2.ets new file mode 100644 index 0000000000000000000000000000000000000000..3454fec431af36ac22d7c90ab7f91888c0a7e7d5 --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestAbility/pages/index2.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2022 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. + */ +@Entry +@Component +struct Index2 { + build() { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text('Hello World Mainability2') + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestAbility/pages/index3.ets b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestAbility/pages/index3.ets new file mode 100644 index 0000000000000000000000000000000000000000..1da36da3dc0a111d17e1fe35b97eac8c487dc094 --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestAbility/pages/index3.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2022 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. + */ +@Entry +@Component +struct Index3 { + build() { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text('Hello World Mainability3') + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestAbility/pages/index4.ets b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestAbility/pages/index4.ets new file mode 100644 index 0000000000000000000000000000000000000000..93ff08b658732de020985aebc5e477b267a36b24 --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestAbility/pages/index4.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2022 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. + */ +@Entry +@Component +struct Index4 { + build() { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text('Hello World Mainability4') + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestAbility/pages/index5.ets b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestAbility/pages/index5.ets new file mode 100644 index 0000000000000000000000000000000000000000..3c3c2904435e5f6b0077226395c7367184f3253b --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestAbility/pages/index5.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2022 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. + */ +@Entry +@Component +struct Index5 { + build() { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text('Hello World Mainability5') + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestAbility/pages/index6.ets b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestAbility/pages/index6.ets new file mode 100644 index 0000000000000000000000000000000000000000..a8c2b4e158f8a43dbbe50e0c2523a76d4c50526b --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestAbility/pages/index6.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2022 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. + */ +@Entry +@Component +struct Index6 { + build() { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text('Hello World Mainability6') + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestAbility/pages/index7.ets b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestAbility/pages/index7.ets new file mode 100644 index 0000000000000000000000000000000000000000..2acfc9b169578217a606b1f359a5ba21c74c433c --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestAbility/pages/index7.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2022 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. + */ +@Entry +@Component +struct Index7 { + build() { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text('Hello World Mainability7') + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestAbility/pages/index8.ets b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestAbility/pages/index8.ets new file mode 100644 index 0000000000000000000000000000000000000000..40ebaa205b49da94ae0c463d02e7505fca6aef30 --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestAbility/pages/index8.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2022 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. + */ +@Entry +@Component +struct Index8 { + build() { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text('Hello World Mainability8') + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestAbility/pages/index9.ets b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestAbility/pages/index9.ets new file mode 100644 index 0000000000000000000000000000000000000000..7aeb889946121ecfbf7f07c89532c7eb7e10cd30 --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestAbility/pages/index9.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2022 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. + */ +@Entry +@Component +struct Index9 { + build() { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text('Hello World Mainability9') + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestAbility/pages/indexh1a1.ets b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestAbility/pages/indexh1a1.ets new file mode 100644 index 0000000000000000000000000000000000000000..4a5bc62f94379a3215966330b85c580968adc9c6 --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestAbility/pages/indexh1a1.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2022 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. + */ +@Entry +@Component +struct indexh1a1 { + build() { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text('Hello World Hap1MainAbility1') + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestAbility/pages/indexh1a2.ets b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestAbility/pages/indexh1a2.ets new file mode 100644 index 0000000000000000000000000000000000000000..8e82f9dfd5a86bfb61d4412c9374120bc5d09769 --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestAbility/pages/indexh1a2.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2022 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. + */ +@Entry +@Component +struct indexh1a2 { + build() { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text('Hello World Hap1MainAbility2') + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..92a16d84e8870da219c51d9f1342c79203c1f42d --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,49 @@ +import hilog from '@ohos.hilog'; +import TestRunner from '@ohos.application.testRunner'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +var abilityDelegator = undefined +var abilityDelegatorArguments = undefined + +async function onAbilityCreateCallback() { + hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback'); +} + +async function addAbilityMonitorCallback(err: any) { + hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? ''); +} + +export default class OpenHarmonyTestRunner implements TestRunner { + constructor() { + } + + onPrepare() { + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare '); + } + + async onRun() { + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run'); + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility' + let lMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + }; + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) + var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName + var debug = abilityDelegatorArguments.parameters['-D'] + if (debug == 'true') + { + cmd += ' -D' + } + hilog.info(0x0000, 'testTag', 'cmd : %{public}s', cmd); + abilityDelegator.executeShellCommand(cmd, + (err: any, d: any) => { + hilog.info(0x0000, 'testTag', 'executeShellCommand : err : %{public}s', JSON.stringify(err) ?? ''); + hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.stdResult ?? ''); + hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.exitCode ?? ''); + }) + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun end'); + } +} \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/test/LifeCycleTest.test.ets b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/test/LifeCycleTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1c2c276b16556d7c072785138d5896c012c4e82 --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/test/LifeCycleTest.test.ets @@ -0,0 +1,1604 @@ +/* + * Copyright (c) 2023 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 { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "@ohos/hypium"; + +const moduleName = "entry_test"; +const otherBundle = "com.example.commontestabilityapp"; +const otherModuleName = "feature"; + +export default function lifecycleTest() { + describe("LifeCycleTest", function () { + beforeEach(async function (done) { + console.info("LifeCycleTest before each called"); + await sleep(1000); + done(); + }); + + afterEach(async function (done) { + console.info("LifeCycleTest after each called"); + if ("Crossplatform_Singlehap_LifeCycleTest_0200" === TAG || "Crossplatform_Singlehap_LifeCycleTest_0300" === TAG + || "Crossplatform_Singlehap_LifeCycleTest_0500" === TAG || "Crossplatform_Singlehap_LifeCycleTest_0600" === TAG + || "Crossplatform_Singlehap_LifeCycleTest_0800" === TAG || "Crossplatform_Singlehap_LifeCycleTest_0900" === TAG) { + var para = { + resultCode: 2, + want: { + abilityName: "MainAbility1", + bundleName: "com.test.lifecycle_crossplatform_xts", + moduleName: moduleName, + }, + }; + console.log("LifeCycleTest terminateSelfwithresult para: " + JSON.stringify(para)); + + await globalThis.ability1context + .terminateSelf() + .then((data) => { + console.log("LifeCycleTest terminateSelfwithresult successful data: " + JSON.stringify(data)); + }) + .catch((error) => { + console.log("LifeCycleTest terminateSelfwithresult error: " + JSON.stringify(error)); + }); + } else if ("Singlehap_LifeCycleTest_2000" === TAG) { + var para1 = { + resultCode: 2, + want: { + abilityName: "MainAbility12", + bundleName: "com.test.lifecycle_crossplatform_xts", + moduleName: moduleName, + }, + }; + console.log("LifeCycleTest terminateSelfwithresult para: " + JSON.stringify(para1)); + await globalThis.ability12 + .terminateSelf() + .then((data) => { + console.log("LifeCycleTest terminateSelfwithresult successful data: " + JSON.stringify(data)); + }) + .catch((error) => { + console.log("LifeCycleTest terminateSelfwithresult error: " + JSON.stringify(error)); + }); + } + done(); + }); + + var TAG = ""; + var listKeyTemp; + var tempCallbackId; + + function sleep(time) { + return new Promise((resolve) => setTimeout(resolve, time)); + } + + /* + * @tc.number Crossplatform_Singlehap_LifeCycleTest_0100 + * @tc.name Register in abilitystage,listen to the lifecycle of abilityA,deregister after listening + * @tc.desc Function test + * @tc.level 0 + */ + it("Crossplatform_Singlehap_LifeCycleTest_0100", 0, async function (done) { + console.log("------------Crossplatform_Singlehap_LifeCycleTest_0100 START-------------"); + TAG = "Crossplatform_Singlehap_LifeCycleTest_0100"; + var code; + var str = { + bundleName: "com.test.lifecycle_crossplatform_xts", + abilityName: "MainAbility2", + moduleName: moduleName, + }; + globalThis.abilityContext + .startAbility(str) + .then((data) => { + console.info(TAG + " start successful. Data: " + data); + }) + .catch((error) => { + console.error(TAG + " start failed. Cause: " + JSON.stringify(error)); + }); + setTimeout(function () { + console.log(TAG + " registerAbilityLifecycleCallback listKey : " + JSON.stringify(globalThis.list)); + console.log(TAG + " registerAbilityLifecycleCallback callbackid : " + JSON.stringify(globalThis.callbackid)); + tempCallbackId = globalThis.callbackid; + console.log(TAG + " registerAbilityLifecycleCallback tempCallbackId : " + JSON.stringify(tempCallbackId)); + var strtemp = ""; + var listtemp = []; + for (var i = 0; i < globalThis.list.length; i++) { + strtemp = globalThis.list[i].substring(0, 12); + if (strtemp === "MainAbility2") { + listtemp.push(globalThis.list[i]); + } + } + console.log(TAG + " listtemp is :" + JSON.stringify(listtemp)); + let exlist = listtemp; + + globalThis.applicationContext.off("abilityLifecycle", tempCallbackId, (error) => { + console.log(TAG + ": unregisterAbilityLifecycleCallback success, err: " + error); + code = error ? error.code : 0; + }); + setTimeout(function () { + console.log("start expect"); + console.log(JSON.stringify(exlist)); + expect(exlist[0]).assertEqual("MainAbility2 onAbilityCreate"); + expect(exlist[1]).assertEqual("MainAbility2 onWindowStageCreate"); + expect(exlist[2]).assertEqual("MainAbility2 onAbilityForeground"); + expect(exlist[3]).assertEqual("MainAbility2 onAbilityBackground"); + expect(exlist[4]).assertEqual("MainAbility2 onWindowStageDestroy"); + expect(exlist[5]).assertEqual("MainAbility2 onAbilityDestroy"); + expect(code).assertEqual(0); + console.log("------------Crossplatform_Singlehap_LifeCycleTest_0100 END-------------"); + done(); + }, 1000); + }, 3000); + }); + + /* + * @tc.number Crossplatform_Singlehap_LifeCycleTest_0200 + * @tc.name Register in abilityA,listen to the lifecycle of abilityB,deregister after listening + * @tc.desc Function test + * @tc.level 0 + */ + it("Crossplatform_Singlehap_LifeCycleTest_0200", 0, async function (done) { + console.log("------------Crossplatform_Singlehap_LifeCycleTest_0200 START-------------"); + TAG = "Crossplatform_Singlehap_LifeCycleTest_0200"; + var code; + var str = { + bundleName: "com.test.lifecycle_crossplatform_xts", + abilityName: "MainAbility1", + moduleName: moduleName, + }; + globalThis.abilityContext + .startAbility(str) + .then((data) => { + console.info(TAG + " start successful. Data: " + data); + }) + .catch((error) => { + console.error(TAG + " start failed. Cause: " + JSON.stringify(error)); + }); + setTimeout(function () { + var str1 = { + bundleName: "com.test.lifecycle_crossplatform_xts", + abilityName: "MainAbility2", + moduleName: moduleName, + }; + globalThis.abilityContext + .startAbility(str1) + .then((data) => { + console.info(TAG + " start successful. Data: " + data); + }) + .catch((error) => { + console.error(TAG + " start failed. Cause: " + JSON.stringify(error)); + }); + }, 500); + setTimeout(function () { + console.log(TAG + " registerAbilityLifecycleCallback listKey : " + JSON.stringify(globalThis.list1)); + console.log(TAG + " registerAbilityLifecycleCallback callbackid : " + JSON.stringify(globalThis.callbackid1)); + var strtemp = ""; + var listtemp = []; + var listtemp1 = []; + for (var i = 0; i < globalThis.list1.length; i++) { + strtemp = globalThis.list1[i].substring(0, 12); + if (strtemp === "MainAbility1") { + listtemp.push(globalThis.list1[i]); + } else if (strtemp === "MainAbility2") { + listtemp1.push(globalThis.list1[i]); + } + } + console.log(TAG + " listtemp is :" + JSON.stringify(listtemp)); + console.log(TAG + " listtemp1 is :" + JSON.stringify(listtemp1)); + let exlist = listtemp; + let exlist1 = listtemp1; + + globalThis.applicationContext1.off("abilityLifecycle", globalThis.callbackid1, (error) => { + console.log(TAG + ": unregisterAbilityLifecycleCallback success, err: " + error); + code = error ? error.code : 0; + }); + setTimeout(function () { + expect(exlist[0]).assertEqual("MainAbility1 onWindowStageCreate"); + expect(exlist[1]).assertEqual("MainAbility1 onAbilityForeground"); + expect(exlist[2]).assertEqual("MainAbility1 onAbilityBackground"); + expect(exlist[3]).assertEqual("MainAbility1 onAbilityForeground"); + expect(exlist1[0]).assertEqual("MainAbility2 onAbilityCreate"); + expect(exlist1[1]).assertEqual("MainAbility2 onWindowStageCreate"); + expect(exlist1[2]).assertEqual("MainAbility2 onAbilityForeground"); + expect(exlist1[3]).assertEqual("MainAbility2 onAbilityBackground"); + expect(exlist1[4]).assertEqual("MainAbility2 onWindowStageDestroy"); + expect(exlist1[5]).assertEqual("MainAbility2 onAbilityDestroy"); + expect(code).assertEqual(0); + console.log("------------Crossplatform_Singlehap_LifeCycleTest_0200 END-------------"); + done(); + }, 1000); + }, 4000); + }); + + /* + * @tc.number Crossplatform_Singlehap_LifeCycleTest_0300 + * @tc.name Register in abilityA,listening the lifecycle of abilityB,deregister,repeat the unregister + * @tc.desc Function test + * @tc.level 0 + */ + it("Crossplatform_Singlehap_LifeCycleTest_0300", 0, async function (done) { + console.log("------------Crossplatform_Singlehap_LifeCycleTest_0300 START-------------"); + TAG = "Crossplatform_Singlehap_LifeCycleTest_0300"; + var code; + var str = { + bundleName: "com.test.lifecycle_crossplatform_xts", + abilityName: "MainAbility1", + moduleName: moduleName, + }; + globalThis.abilityContext + .startAbility(str) + .then((data) => { + console.info(TAG + " start successful. Data: " + data); + }) + .catch((error) => { + console.error(TAG + " start failed. Cause: " + JSON.stringify(error)); + }); + setTimeout(function () { + var str1 = { + bundleName: "com.test.lifecycle_crossplatform_xts", + abilityName: "MainAbility2", + moduleName: moduleName, + }; + globalThis.abilityContext + .startAbility(str1) + .then((data) => { + console.info(TAG + " start successful. Data: " + data); + }) + .catch((error) => { + console.error(TAG + " start failed. Cause: " + JSON.stringify(error)); + }); + }, 500); + setTimeout(function () { + console.log(TAG + " registerAbilityLifecycleCallback listKey : " + JSON.stringify(globalThis.list1)); + console.log(TAG + " registerAbilityLifecycleCallback callbackid : " + JSON.stringify(globalThis.callbackid1)); + var strtemp = ""; + var listtemp = []; + var listtemp1 = []; + for (var i = 0; i < globalThis.list1.length; i++) { + strtemp = globalThis.list1[i].substring(0, 12); + if (strtemp === "MainAbility1") { + listtemp.push(globalThis.list1[i]); + } else if (strtemp === "MainAbility2") { + listtemp1.push(globalThis.list1[i]); + } + } + console.log(TAG + " listtemp is :" + JSON.stringify(listtemp)); + console.log(TAG + " listtemp1 is :" + JSON.stringify(listtemp1)); + let exlist = listtemp; + let exlist1 = listtemp1; + + globalThis.applicationContext1.off("abilityLifecycle", globalThis.callbackid1, (error) => { + console.log(TAG + ": unregisterAbilityLifecycleCallback success, err: "); + }); + setTimeout(function () { + console.log(TAG + " secondunregister callbackid : " + JSON.stringify(globalThis.callbackid1)); + + globalThis.applicationContext1.off("abilityLifecycle", globalThis.callbackid1, (error) => { + console.log(TAG + ": unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error)); + code = error ? error.code : 0; + }); + }, 500); + setTimeout(function () { + expect(exlist[0]).assertEqual("MainAbility1 onWindowStageCreate"); + expect(exlist[1]).assertEqual("MainAbility1 onAbilityForeground"); + expect(exlist[2]).assertEqual("MainAbility1 onAbilityBackground"); + expect(exlist[3]).assertEqual("MainAbility1 onAbilityForeground"); + expect(exlist1[0]).assertEqual("MainAbility2 onAbilityCreate"); + expect(exlist1[1]).assertEqual("MainAbility2 onWindowStageCreate"); + expect(exlist1[2]).assertEqual("MainAbility2 onAbilityForeground"); + expect(exlist1[3]).assertEqual("MainAbility2 onAbilityBackground"); + expect(exlist1[4]).assertEqual("MainAbility2 onWindowStageDestroy"); + expect(exlist1[5]).assertEqual("MainAbility2 onAbilityDestroy"); + expect(code).assertEqual(401); + console.log("------------Crossplatform_Singlehap_LifeCycleTest_0300 END-------------"); + done(); + }, 2000); + }, 4000); + }); + + /* + * @tc.number Crossplatform_Singlehap_LifeCycleTest_0400 + * @tc.name Register in abilityA,listening the lifecycle of abilityB,terminate abilityA,unregister + * @tc.desc Function test + * @tc.level 0 + */ + it("Crossplatform_Singlehap_LifeCycleTest_0400", 0, async function (done) { + console.log("------------Crossplatform_Singlehap_LifeCycleTest_0400 START-------------"); + TAG = "Crossplatform_Singlehap_LifeCycleTest_0400"; + var code; + var str = { + bundleName: "com.test.lifecycle_crossplatform_xts", + abilityName: "MainAbility3", + moduleName: moduleName, + }; + globalThis.abilityContext + .startAbility(str) + .then((data) => { + console.info(TAG + " start3 successful. Data: " + data); + }) + .catch((error) => { + console.error(TAG + " start3 failed. Cause: " + JSON.stringify(error)); + }); + setTimeout(function () { + var str1 = { + bundleName: "com.test.lifecycle_crossplatform_xts", + abilityName: "MainAbility2", + moduleName: moduleName, + }; + globalThis.abilityContext + .startAbility(str1) + .then((data) => { + console.info(TAG + " start2 successful. Data: " + data); + }) + .catch((error) => { + console.error(TAG + " start2 failed. Cause: " + JSON.stringify(error)); + }); + }, 500); + setTimeout(function () { + console.log(TAG + " registerAbilityLifecycleCallback listKey : " + JSON.stringify(globalThis.list3)); + console.log(TAG + " registerAbilityLifecycleCallback callbackid : " + JSON.stringify(globalThis.callbackid3)); + var strtemp = ""; + var listtemp = []; + var listtemp1 = []; + for (var i = 0; i < globalThis.list3.length; i++) { + strtemp = globalThis.list3[i].substring(0, 12); + if (strtemp === "MainAbility3") { + listtemp.push(globalThis.list3[i]); + } else if (strtemp === "MainAbility2") { + listtemp1.push(globalThis.list3[i]); + } + } + console.log(TAG + " listtemp is :" + JSON.stringify(listtemp)); + console.log(TAG + " listtemp1 is :" + JSON.stringify(listtemp1)); + let exlist = listtemp; + let exlist1 = listtemp1; + var para = { + resultCode: 1, + want: { + abilityName: "MainAbility3", + bundleName: "com.test.lifecycle_crossplatform_xts", + moduleName: moduleName, + }, + }; + console.log(TAG + " terminateSelfwithresult para: " + JSON.stringify(para)); + + globalThis.ability3 + .terminateSelf() + .then((data) => { + console.log(TAG + " terminateSelfwithresult successful data: " + JSON.stringify(data)); + }) + .catch((error) => { + console.log(TAG + " terminateSelfwithresult error: " + JSON.stringify(error)); + }); + setTimeout(function () { + globalThis.applicationContext3.off("abilityLifecycle", globalThis.callbackid3, (error) => { + console.log(TAG + ": unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error)); + code = error ? error.code : 0; + }); + }, 500); + setTimeout(function () { + expect(exlist[0]).assertEqual("MainAbility3 onWindowStageCreate"); + expect(exlist[1]).assertEqual("MainAbility3 onAbilityForeground"); + expect(exlist[2]).assertEqual("MainAbility3 onAbilityBackground"); + expect(exlist[3]).assertEqual("MainAbility3 onAbilityForeground"); + expect(exlist1[0]).assertEqual("MainAbility2 onAbilityCreate"); + expect(exlist1[1]).assertEqual("MainAbility2 onWindowStageCreate"); + expect(exlist1[2]).assertEqual("MainAbility2 onAbilityForeground"); + expect(exlist1[3]).assertEqual("MainAbility2 onAbilityBackground"); + expect(exlist1[4]).assertEqual("MainAbility2 onWindowStageDestroy"); + expect(exlist1[5]).assertEqual("MainAbility2 onAbilityDestroy"); + expect(code).assertEqual(0); + console.log("------------Crossplatform_Singlehap_LifeCycleTest_0400 END-------------"); + done(); + }, 1000); + }, 4000); + }); + + /* + * @tc.number Crossplatform_Singlehap_LifeCycleTest_0500 + * @tc.name Register in abilityA and abilityB,unregister MainabilityB,then Register in ManinabilityC + * @tc.desc Function test + * @tc.level 0 + */ + it("Crossplatform_Singlehap_LifeCycleTest_0500", 0, async function (done) { + console.log("------------Crossplatform_Singlehap_LifeCycleTest_0500 START-------------"); + TAG = "Crossplatform_Singlehap_LifeCycleTest_0500"; + var str = { + bundleName: "com.test.lifecycle_crossplatform_xts", + abilityName: "MainAbility1", + moduleName: moduleName, + }; + globalThis.abilityContext + .startAbility(str) + .then((data) => { + console.info(TAG + " start1 successful. Data: " + data); + }) + .catch((error) => { + console.error(TAG + " start1 failed. Cause: " + JSON.stringify(error)); + }); + setTimeout(function () { + var str1 = { + bundleName: "com.test.lifecycle_crossplatform_xts", + abilityName: "MainAbility3", + moduleName: moduleName, + }; + globalThis.abilityContext + .startAbility(str1) + .then((data) => { + console.info(TAG + " start3 successful. Data: " + data); + }) + .catch((error) => { + console.error(TAG + " start3 failed. Cause: " + JSON.stringify(error)); + }); + }, 500); + setTimeout(function () { + console.log(TAG + " start after callbackid3 : " + JSON.stringify(globalThis.callbackid3)); + globalThis.applicationContext3.off("abilityLifecycle", globalThis.callbackid3, (error) => { + console.log(TAG + ": unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error)); + }); + var str2 = { + bundleName: "com.test.lifecycle_crossplatform_xts", + abilityName: "MainAbility4", + moduleName: moduleName, + }; + globalThis.abilityContext + .startAbility(str2) + .then((data) => { + console.info(TAG + " start4 successful. Data: " + data); + }) + .catch((error) => { + console.error(TAG + " start4 failed. Cause: " + JSON.stringify(error)); + }); + }, 2800); + setTimeout(function () { + console.log(TAG + " listKey1 : " + JSON.stringify(globalThis.list1)); + console.log(TAG + " callbackid1 : " + JSON.stringify(globalThis.callbackid1)); + console.log(TAG + " listKey3 : " + JSON.stringify(globalThis.list3)); + console.log(TAG + " callbackid3 : " + JSON.stringify(globalThis.callbackid3)); + let id3 = globalThis.callbackid3; + console.log(TAG + " listKey4 : " + JSON.stringify(globalThis.list4)); + console.log(TAG + " callbackid4 : " + JSON.stringify(globalThis.callbackid4)); + let id4 = globalThis.callbackid4; + expect(id3 + 1).assertEqual(id4); + + globalThis.applicationContext4.off("abilityLifecycle", globalThis.callbackid4, (error) => { + console.log(TAG + ": unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error)); + }); + + globalThis.applicationContext1.off("abilityLifecycle", globalThis.callbackid1, (error) => { + console.log(TAG + ": unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error)); + done(); + }); + }, 5000); + }); + + /* + * @tc.number Crossplatform_Singlehap_LifeCycleTest_0600 + * @tc.name Register in abilityA,start abilityB、abilityC,terminate abilityB 、abilityC + * @tc.desc Function test + * @tc.level 0 + */ + it("Crossplatform_Singlehap_LifeCycleTest_0600", 0, async function (done) { + console.log("------------Crossplatform_Singlehap_LifeCycleTest_0600 START-------------"); + TAG = "Crossplatform_Singlehap_LifeCycleTest_0600"; + var str = { + bundleName: "com.test.lifecycle_crossplatform_xts", + abilityName: "MainAbility1", + moduleName: moduleName, + }; + globalThis.abilityContext + .startAbility(str) + .then((data) => { + console.info(TAG + " start1 successful. Data: " + data); + }) + .catch((error) => { + console.error(TAG + " start1 failed. Cause: " + JSON.stringify(error)); + }); + setTimeout(function () { + var str1 = { + bundleName: "com.test.lifecycle_crossplatform_xts", + abilityName: "MainAbility5", + moduleName: moduleName, + }; + globalThis.abilityContext + .startAbility(str1) + .then((data) => { + console.info(TAG + " start5 successful. Data: " + data); + }) + .catch((error) => { + console.error(TAG + " start5 failed. Cause: " + JSON.stringify(error)); + }); + }, 500); + setTimeout(function () { + var str2 = { + bundleName: "com.test.lifecycle_crossplatform_xts", + abilityName: "MainAbility2", + moduleName: moduleName, + }; + globalThis.abilityContext + .startAbility(str2) + .then((data) => { + console.info(TAG + " start2 successful. Data: " + data); + }) + .catch((error) => { + console.error(TAG + " start2 failed. Cause: " + JSON.stringify(error)); + }); + }, 1100); + setTimeout(function () { + console.log(TAG + " listKey1 : " + JSON.stringify(globalThis.list1)); + console.log(TAG + " callbackid1 : " + JSON.stringify(globalThis.callbackid1)); + var strtemp = ""; + var listtemp = []; + var listtemp2 = []; + for (var i = 0; i < globalThis.list1.length; i++) { + strtemp = globalThis.list1[i].substring(0, 12); + if (strtemp == "MainAbility2") { + listtemp.push(globalThis.list1[i]); + } else if (strtemp == "MainAbility5") { + listtemp2.push(globalThis.list1[i]); + } + } + console.log(TAG + " listtemp is :" + JSON.stringify(listtemp)); + console.log(TAG + " listtemp2 is :" + JSON.stringify(listtemp2)); + let exlist = listtemp; + let exlist2 = listtemp2; + expect(exlist[0]).assertEqual("MainAbility2 onAbilityCreate"); + expect(exlist[1]).assertEqual("MainAbility2 onWindowStageCreate"); + expect(exlist[2]).assertEqual("MainAbility2 onAbilityForeground"); + expect(exlist[3]).assertEqual("MainAbility2 onAbilityBackground"); + expect(exlist[4]).assertEqual("MainAbility2 onWindowStageDestroy"); + expect(exlist[5]).assertEqual("MainAbility2 onAbilityDestroy"); + expect(exlist2[0]).assertEqual("MainAbility5 onAbilityCreate"); + expect(exlist2[1]).assertEqual("MainAbility5 onWindowStageCreate"); + expect(exlist2[2]).assertEqual("MainAbility5 onAbilityForeground"); + expect(exlist2[3]).assertEqual("MainAbility5 onAbilityBackground"); + expect(exlist2[4]).assertEqual("MainAbility5 onWindowStageDestroy"); + expect(exlist2[5]).assertEqual("MainAbility5 onAbilityDestroy"); + + globalThis.applicationContext1.off("abilityLifecycle", globalThis.callbackid1, (error) => { + console.log(TAG + ": unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error)); + done(); + }); + }, 5200); + }); + + /* + * @tc.number Crossplatform_Singlehap_LifeCycleTest_0700 + * @tc.name Multiple registration/unregistration + * @tc.desc Function test + * @tc.level 0 + */ + it("Crossplatform_Singlehap_LifeCycleTest_0700", 0, async function (done) { + console.log("------------Crossplatform_Singlehap_LifeCycleTest_0700 START-------------"); + TAG = "Crossplatform_Singlehap_LifeCycleTest_0700"; + var code1; + var code2; + var code3; + var id1; + var id2; + var id3; + var listKey8 = []; + let AbilityLifecycleCallback = { + onAbilityCreate(ability) { + console.log(TAG + " onAbilityCreate ability:" + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log(TAG + " onAbilityCreate abilityname:" + JSON.stringify(abilityname)); + console.log(TAG + " " + abilityname + " onAbilityCreate"); + listKey8.push(abilityname + " onAbilityCreate"); + }, + onWindowStageCreate(ability, windowStage) { + console.log(TAG + " onWindowStageCreate ability:" + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log(TAG + " onWindowStageCreate abilityname:" + JSON.stringify(abilityname)); + console.log(TAG + " " + abilityname + " onWindowStageCreate"); + listKey8.push(abilityname + " onWindowStageCreate"); + }, + onWindowStageActive(ability, windowStage) { + let abilityname = ability.context.abilityInfo.name; + console.log(abilityname + " onWindowStageActive"); + }, + onWindowStageInactive(ability, windowStage) { + let abilityname = ability.context.abilityInfo.name; + console.log(abilityname + " onWindowStageInactive"); + }, + onWindowStageDestroy(ability, windowStage) { + console.log(TAG + " AbilityLifecycleCallback1 onWindowStageDestroy ability:" + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log(TAG + " AbilityLifecycleCallback1 onWindowStageDestroy abilityname:" + JSON.stringify(abilityname)); + console.log(TAG + " " + abilityname + " onWindowStageDestroy"); + listKey8.push(abilityname + " onWindowStageDestroy"); + }, + onAbilityDestroy(ability) { + console.log(TAG + " AbilityLifecycleCallback1 onAbilityDestroy ability:" + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log(TAG + " AbilityLifecycleCallback1 onAbilityDestroy abilityname:" + JSON.stringify(abilityname)); + console.log(TAG + " " + abilityname + " onAbilityDestroy"); + listKey8.push(abilityname + " onAbilityDestroy"); + }, + onAbilityForeground(ability) { + console.log(TAG + " AbilityLifecycleCallback1 onAbilityForeground ability:" + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log(TAG + " AbilityLifecycleCallback1 onAbilityForeground abilityname:" + JSON.stringify(abilityname)); + console.log(TAG + " " + abilityname + " onAbilityForeground"); + listKey8.push(abilityname + " onAbilityForeground"); + }, + onAbilityBackground(ability) { + console.log(TAG + " AbilityLifecycleCallback1 onAbilityBackground ability:" + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log(TAG + " AbilityLifecycleCallback1 onAbilityBackground abilityname:" + JSON.stringify(abilityname)); + console.log(TAG + " " + abilityname + " onAbilityBackground"); + listKey8.push(abilityname + " onAbilityBackground"); + }, + onAbilityContinue(ability) { + console.log(TAG + " AbilityLifecycleCallback1 onAbilityContinue ability:" + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log(TAG + " AbilityLifecycleCallback1 onAbilityContinue abilityname:" + JSON.stringify(abilityname)); + console.log(TAG + " " + abilityname + " onAbilityContinue"); + listKey8.push(abilityname + " onAbilityContinue"); + }, + }; + let applicationContext = globalThis.abilityContext.getApplicationContext(); + id1 = applicationContext.on("abilityLifecycle", AbilityLifecycleCallback); + console.log(TAG + " registerAbilityLifecycleCallback1 number: " + JSON.stringify(id1)); + + applicationContext.off("abilityLifecycle", id1, (error) => { + console.log(TAG + ": unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error)); + code1 = error ? error.code : 0; + }); + setTimeout(function () { + id2 = applicationContext.on("abilityLifecycle", AbilityLifecycleCallback); + console.log(TAG + " registerAbilityLifecycleCallback2 number: " + JSON.stringify(id2)); + applicationContext.off("abilityLifecycle", id2, (error) => { + console.log(TAG + ": unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error)); + code2 = error ? error.code : 0; + }); + }, 1000); + setTimeout(function () { + id3 = applicationContext.on("abilityLifecycle", AbilityLifecycleCallback); + console.log(TAG + " registerAbilityLifecycleCallback3 number: " + JSON.stringify(id3)); + + applicationContext.off("abilityLifecycle", id3, (error) => { + console.log(TAG + ": unregisterAbilityLifecycleCallback3 success, err: " + JSON.stringify(error)); + code3 = error ? error.code : 0; + expect(id1 > 0).assertTrue(); + expect(id2).assertEqual(id1 + 1); + expect(id3).assertEqual(id2 + 1); + expect(code1).assertEqual(0); + expect(code2).assertEqual(0); + expect(code3).assertEqual(0); + console.log("------------Crossplatform_Singlehap_LifeCycleTest_0700 END-------------"); + done(); + }); + }, 3000); + }); + + /* + * @tc.number Crossplatform_Singlehap_LifeCycleTest_0800 + * @tc.name Maninability1 Register listening, Repeat starting and termination Ability2 + * @tc.desc Function test + * @tc.level 0 + */ + it("Crossplatform_Singlehap_LifeCycleTest_0800", 0, async function (done) { + console.log("------------Crossplatform_Singlehap_LifeCycleTest_0800 START-------------"); + TAG = "Crossplatform_Singlehap_LifeCycleTest_0800"; + var str = { + bundleName: "com.test.lifecycle_crossplatform_xts", + abilityName: "MainAbility1", + moduleName: moduleName, + }; + globalThis.abilityContext + .startAbility(str) + .then((data) => { + console.info(TAG + " start successful. Data: " + data); + }) + .catch((error) => { + console.error(TAG + " start failed. Cause: " + JSON.stringify(error)); + }); + setTimeout(function () { + var str1 = { + bundleName: "com.test.lifecycle_crossplatform_xts", + abilityName: "MainAbility2", + moduleName: moduleName, + }; + globalThis.abilityContext + .startAbility(str1) + .then((data) => { + console.info(TAG + " start successful. Data: " + data); + }) + .catch((error) => { + console.error(TAG + " start failed. Cause: " + JSON.stringify(error)); + }); + }, 1500); + setTimeout(function () { + var str1 = { + bundleName: "com.test.lifecycle_crossplatform_xts", + abilityName: "MainAbility2", + moduleName: moduleName, + }; + globalThis.abilityContext + .startAbility(str1) + .then((data) => { + console.info(TAG + " start successful. Data: " + data); + }) + .catch((error) => { + console.error(TAG + " start failed. Cause: " + JSON.stringify(error)); + }); + }, 4500); + + setTimeout(function () { + var str1 = { + bundleName: "com.test.lifecycle_crossplatform_xts", + abilityName: "MainAbility2", + moduleName: moduleName, + }; + globalThis.abilityContext + .startAbility(str1) + .then((data) => { + console.info(TAG + " start successful. Data: " + data); + }) + .catch((error) => { + console.error(TAG + " start failed. Cause: " + JSON.stringify(error)); + }); + }, 7500); + + setTimeout(function () { + console.log(TAG + " registerAbilityLifecycleCallback listKey : " + JSON.stringify(globalThis.list1)); + console.log(TAG + " registerAbilityLifecycleCallback callbackid : " + JSON.stringify(globalThis.callbackid1)); + var strtemp = ""; + var listtemp = []; + var listtemp1 = []; + for (var i = 0; i < globalThis.list1.length; i++) { + strtemp = globalThis.list1[i].substring(0, 12); + if (strtemp === "MainAbility1") { + listtemp.push(globalThis.list1[i]); + } else if (strtemp === "MainAbility2") { + listtemp1.push(globalThis.list1[i]); + } + } + console.log(TAG + " listtemp is :" + listtemp); + console.log(TAG + " listtemp1 is :" + listtemp1); + let exlist = listtemp; + let exlist1 = listtemp1; + try { + expect(exlist[0]).assertEqual("MainAbility1 onWindowStageCreate"); + expect(exlist[1]).assertEqual("MainAbility1 onAbilityForeground"); + expect(exlist[2]).assertEqual("MainAbility1 onAbilityBackground"); + expect(exlist[3]).assertEqual("MainAbility1 onAbilityForeground"); + expect(exlist[4]).assertEqual("MainAbility1 onAbilityBackground"); + expect(exlist[5]).assertEqual("MainAbility1 onAbilityForeground"); + expect(exlist[6]).assertEqual("MainAbility1 onAbilityBackground"); + expect(exlist1[0]).assertEqual("MainAbility2 onAbilityCreate"); + expect(exlist1[1]).assertEqual("MainAbility2 onWindowStageCreate"); + expect(exlist1[2]).assertEqual("MainAbility2 onAbilityForeground"); + expect(exlist1[3]).assertEqual("MainAbility2 onAbilityBackground"); + expect(exlist1[4]).assertEqual("MainAbility2 onWindowStageDestroy"); + expect(exlist1[5]).assertEqual("MainAbility2 onAbilityDestroy"); + expect(exlist1[6]).assertEqual("MainAbility2 onAbilityCreate"); + expect(exlist1[7]).assertEqual("MainAbility2 onWindowStageCreate"); + expect(exlist1[8]).assertEqual("MainAbility2 onAbilityForeground"); + expect(exlist1[9]).assertEqual("MainAbility2 onAbilityBackground"); + expect(exlist1[10]).assertEqual("MainAbility2 onWindowStageDestroy"); + expect(exlist1[11]).assertEqual("MainAbility2 onAbilityDestroy"); + expect(exlist1[12]).assertEqual("MainAbility2 onAbilityCreate"); + expect(exlist1[13]).assertEqual("MainAbility2 onWindowStageCreate"); + expect(exlist1[14]).assertEqual("MainAbility2 onAbilityForeground"); + } catch (error) { + console.error(`${TAG} startRunning failed: ${JSON.stringify(error)}`); + done(); + } + + globalThis.applicationContext1.off("abilityLifecycle", globalThis.callbackid1, (error) => { + console.log(TAG + ": unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error)); + done(); + }); + }, 9000); + }); + + /* + * @tc.number Crossplatform_Singlehap_LifeCycleTest_0900 + * @tc.name Repeat switching Ability1 between front and back + * @tc.desc Function test + * @tc.level 0 + */ + it("Crossplatform_Singlehap_LifeCycleTest_0900", 0, async function (done) { + console.log("------------Crossplatform_Singlehap_LifeCycleTest_0900 START-------------"); + TAG = "Crossplatform_Singlehap_LifeCycleTest_0900"; + var str = { + bundleName: "com.test.lifecycle_crossplatform_xts", + abilityName: "MainAbility1", + moduleName: moduleName, + }; + globalThis.abilityContext + .startAbility(str) + .then((data) => { + console.info(TAG + " start successful. Data: " + data); + }) + .catch((error) => { + console.error(TAG + " start failed. Cause: " + JSON.stringify(error)); + }); + setTimeout(function () { + var str1 = { + bundleName: "com.test.lifecycle_crossplatform_xts", + abilityName: "MainAbility2", + moduleName: moduleName, + }; + globalThis.abilityContext + .startAbility(str1) + .then((data) => { + console.info(TAG + " start successful. Data: " + data); + }) + .catch((error) => { + console.error(TAG + " start failed. Cause: " + JSON.stringify(error)); + }); + }, 500); + setTimeout(function () { + var str1 = { + bundleName: "com.test.lifecycle_crossplatform_xts", + abilityName: "MainAbility2", + moduleName: moduleName, + }; + globalThis.abilityContext + .startAbility(str1) + .then((data) => { + console.info(TAG + " start successful. Data: " + data); + }) + .catch((error) => { + console.error(TAG + " start failed. Cause: " + JSON.stringify(error)); + }); + }, 3000); + setTimeout(function () { + console.log(TAG + " registerAbilityLifecycleCallback listKey : " + JSON.stringify(globalThis.list1)); + console.log(TAG + " registerAbilityLifecycleCallback callbackid : " + JSON.stringify(globalThis.callbackid1)); + var strtemp = ""; + var listtemp = []; + var listtemp1 = []; + for (var i = 0; i < globalThis.list1.length; i++) { + strtemp = globalThis.list1[i].substring(0, 12); + if (strtemp === "MainAbility1") { + listtemp.push(globalThis.list1[i]); + } else if (strtemp === "MainAbility2") { + listtemp1.push(globalThis.list1[i]); + } + } + console.log(TAG + " listtemp is :" + listtemp); + console.log(TAG + " listtemp1 is :" + listtemp1); + let exlist = listtemp; + let exlist1 = listtemp1; + expect(exlist[0]).assertEqual("MainAbility1 onWindowStageCreate"); + expect(exlist[1]).assertEqual("MainAbility1 onAbilityForeground"); + expect(exlist[2]).assertEqual("MainAbility1 onAbilityBackground"); + expect(exlist[3]).assertEqual("MainAbility1 onAbilityForeground"); + expect(exlist[4]).assertEqual("MainAbility1 onAbilityBackground"); + expect(exlist[5]).assertEqual("MainAbility1 onAbilityForeground"); + expect(exlist1[0]).assertEqual("MainAbility2 onAbilityCreate"); + expect(exlist1[1]).assertEqual("MainAbility2 onWindowStageCreate"); + expect(exlist1[2]).assertEqual("MainAbility2 onAbilityForeground"); + expect(exlist1[3]).assertEqual("MainAbility2 onAbilityBackground"); + expect(exlist1[4]).assertEqual("MainAbility2 onWindowStageDestroy"); + expect(exlist1[5]).assertEqual("MainAbility2 onAbilityDestroy"); + expect(exlist1[6]).assertEqual("MainAbility2 onAbilityCreate"); + expect(exlist1[7]).assertEqual("MainAbility2 onWindowStageCreate"); + expect(exlist1[8]).assertEqual("MainAbility2 onAbilityForeground"); + expect(exlist1[9]).assertEqual("MainAbility2 onAbilityBackground"); + expect(exlist1[10]).assertEqual("MainAbility2 onWindowStageDestroy"); + expect(exlist1[11]).assertEqual("MainAbility2 onAbilityDestroy"); + + globalThis.applicationContext1.off("abilityLifecycle", globalThis.callbackid1, (error) => { + console.log(TAG + ": unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error)); + done(); + }); + }, 5500); + }); + + /* + * @tc.number Crossplatform_Singlehap_LifeCycleTest_1000 + * @tc.name Register listening in abilityA foreground,repeat the registration (standard) + * @tc.desc Function test + * @tc.level 0 + */ + it("Crossplatform_Singlehap_LifeCycleTest_1000", 0, async function (done) { + console.log("------------Singlehap_LifeCycleTest_1200 START-------------"); + TAG = "Singlehap_LifeCycleTest_1200"; + var id1; + var id2; + var str = { + bundleName: "com.test.lifecycle_crossplatform_xts", + abilityName: "MainAbility8", + moduleName: moduleName, + }; + globalThis.abilityContext + .startAbility(str) + .then((data) => { + console.info(TAG + " start successful. Data: " + data); + }) + .catch((error) => { + console.error(TAG + " start failed. Cause: " + JSON.stringify(error)); + }); + setTimeout(function () { + console.log(TAG + " firstCallback listKey : " + JSON.stringify(globalThis.list8)); + console.log(TAG + " firstCallback callbackid : " + JSON.stringify(globalThis.callbackid8)); + id1 = globalThis.callbackid8; + console.log(TAG + " firstCallback id : " + JSON.stringify(id1)); + var str = { + bundleName: "com.test.lifecycle_crossplatform_xts", + abilityName: "MainAbility8", + moduleName: moduleName, + }; + globalThis.abilityContext + .startAbility(str) + .then((data) => { + console.info(TAG + " start successful. Data: " + data); + }) + .catch((error) => { + console.error(TAG + " start failed. Cause: " + JSON.stringify(error)); + }); + }, 2000); + setTimeout(function () { + console.log(TAG + " secondCallback listKey : " + JSON.stringify(globalThis.list8)); + console.log(TAG + " secondCallback callbackid : " + JSON.stringify(globalThis.callbackid8)); + id2 = globalThis.callbackid8; + console.log(TAG + " secondCallback id : " + JSON.stringify(id2)); + expect(id1 + 1).assertEqual(id2); + + globalThis.applicationContext8.off("abilityLifecycle", globalThis.callbackid8, (error) => { + console.log(TAG + ": unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error)); + }); + var para = { + resultCode: 1, + want: { + abilityName: "MainAbility8", + bundleName: "com.test.lifecycle_crossplatform_xts", + moduleName: moduleName, + }, + }; + console.log(TAG + " terminateSelfwithresult para: " + JSON.stringify(para)); + + globalThis.ability8.terminateSelf((error, data) => { + console.log(TAG + " terminateSelfwithresult success, err: " + JSON.stringify(error) + ",data: " + JSON.stringify(data)); + console.log("------------Singlehap_LifeCycleTest_1200 END-------------"); + done(); + }); + }, 4000); + }); + + /* + * @tc.number Crossplatform_Singlehap_LifeCycleTest_1100 + * @tc.name The ability of HAP A listens to the ability lifecycle callback of HAP B (standard) + * @tc.desc Function test + * @tc.level 0 + */ + it("Crossplatform_Singlehap_LifeCycleTest_1100", 0, async function (done) { + console.log("------------Singlehap_LifeCycleTest_1400 start-------------"); + TAG = "Singlehap_LifeCycleTest_1400"; + listKeyTemp = []; + globalThis.abilityContext.startAbility( + { + bundleName: "com.test.lifecycle_crossplatform_xts", + abilityName: "MainAbility9", + moduleName: moduleName, + }, + (error, data) => { + console.log(TAG + ": MainAbility9 startAbility success, err: " + JSON.stringify(error) + ",data: " + JSON.stringify(data)); + } + ); + await sleep(500); + globalThis.abilityContext.startAbility( + { + bundleName: "com.test.lifecycle_crossplatform_xts", + abilityName: "Hap1MainAbility2", + moduleName: moduleName, + }, + (error, data) => { + console.log(TAG + ":first Hap1MainAbility2 startAbility success, err: " + JSON.stringify(error) + ",data: " + JSON.stringify(data)); + } + ); + await sleep(500); + globalThis.abilityContext.startAbility( + { + bundleName: "com.test.lifecycle_crossplatform_xts", + abilityName: "Hap1MainAbility2", + moduleName: moduleName, + }, + (error, data) => { + setTimeout(() => { + console.log(TAG + ": second Hap1MainAbility2 startAbility success, err: " + JSON.stringify(error) + ",data: " + JSON.stringify(data)); + for (var i = 0; i < globalThis.mainAbility9ListKey.length; i++) { + if (globalThis.mainAbility9ListKey[i].substring(0, 16) == "Hap1MainAbility2") { + listKeyTemp.push(globalThis.mainAbility9ListKey[i]); + } + } + console.log(TAG + "listKeyTemp is :" + listKeyTemp); + console.log(TAG + "globalThis.mainAbility9CallBackId is :" + globalThis.mainAbility9CallBackId); + expect(listKeyTemp[0]).assertEqual("Hap1MainAbility2 onAbilityCreate"); + expect(listKeyTemp[1]).assertEqual("Hap1MainAbility2 onWindowStageCreate"); + expect(listKeyTemp[2]).assertEqual("Hap1MainAbility2 onAbilityForeground"); + expect(listKeyTemp[3]).assertEqual("Hap1MainAbility2 onAbilityCreate"); + expect(listKeyTemp[4]).assertEqual("Hap1MainAbility2 onWindowStageCreate"); + expect(listKeyTemp[5]).assertEqual("Hap1MainAbility2 onAbilityForeground"); + expect(listKeyTemp[6]).assertEqual("Hap1MainAbility2 onAbilityBackground"); + expect(listKeyTemp[7]).assertEqual("Hap1MainAbility2 onWindowStageDestroy"); + expect(listKeyTemp[8]).assertEqual("Hap1MainAbility2 onAbilityDestroy"); + expect(listKeyTemp[9]).assertEqual("Hap1MainAbility2 onAbilityBackground"); + expect(listKeyTemp[10]).assertEqual("Hap1MainAbility2 onWindowStageDestroy"); + expect(listKeyTemp[11]).assertEqual("Hap1MainAbility2 onAbilityDestroy"); + + globalThis.applicationContext9.off("abilityLifecycle", globalThis.mainAbility9CallBackId, (error) => { + console.log(TAG + ": unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error)); + done(); + }); + }, 3000); + } + ); + console.log("------------Singlehap_LifeCycleTest_1400 end-------------"); + }); + + var callbackid_NA = 100; + var callbackid_errorNum = -1; + + /* + * @tc.number Crossplatform_Singlehap_LifeCycleTest_1200 + * @tc.name input Nonexistent callbackid for unregisterAbilityLifecycleCallback parameter + * @tc.desc Function test + * @tc.level 1 + */ + it("Crossplatform_Singlehap_LifeCycleTest_1200", 0, async function (done) { + console.log("------------Singlehap_LifeCycleTest_1600 START-------------"); + TAG = "Singlehap_LifeCycleTest_1600"; + let code; + + globalThis.abilityContext.getApplicationContext().off("abilityLifecycle", callbackid_NA, (error) => { + console.log(TAG + ": unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error)); + code = error.code; + sleep(1000); + expect(code).assertEqual(401); + done(); + }); + }); + + /* + * @tc.number Crossplatform_Singlehap_LifeCycleTest_1300 + * @tc.name input error callbackid for unregisterAbilityLifecycleCallback parameter + * @tc.desc Function test + * @tc.level 1 + */ + it("Crossplatform_Singlehap_LifeCycleTest_1300", 0, async function (done) { + console.log("------------Singlehap_LifeCycleTest_1700 START-------------"); + TAG = "Singlehap_LifeCycleTest_1700"; + let code; + + globalThis.abilityContext.getApplicationContext().off("abilityLifecycle", callbackid_errorNum, (error) => { + console.log(TAG + ": unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error)); + code = error.code; + sleep(1000); + expect(code).assertEqual(401); + done(); + }); + }); + + /* + * @tc.number Crossplatform_Singlehap_LifeCycleTest_1400 + * @tc.name Register in abilityA,register in abilityB, starting and termination abilityC, + termination abilityB、abilityA, Re-register in abilityA、abilityB + * @tc.desc Function test + * @tc.level 0 + */ + it("Crossplatform_Singlehap_LifeCycleTest_1400", 0, async function (done) { + console.log("------------Crossplatform_Singlehap_LifeCycleTest_1400 START-------------"); + TAG = "Crossplatform_Singlehap_LifeCycleTest_1400"; + let id1; + let str = { + bundleName: "com.test.lifecycle_crossplatform_xts", + abilityName: "MainAbility1", + moduleName: moduleName, + }; + globalThis.abilityContext + .startAbility(str) + .then((data) => { + console.info(TAG + " start successful. Data: " + data); + }) + .catch((error) => { + console.error(TAG + " start failed. Cause: " + JSON.stringify(error)); + }); + setTimeout(function () { + var str2 = { + bundleName: "com.test.lifecycle_crossplatform_xts", + abilityName: "MainAbility2", + moduleName: moduleName, + }; + globalThis.abilityContext + .startAbility(str2) + .then((data) => { + console.info(TAG + " start successful. Data: " + data); + }) + .catch((error) => { + console.error(TAG + " start failed. Cause: " + JSON.stringify(error)); + }); + }, 1000); + setTimeout(function () { + console.log(TAG + " firstCallback listKey1 : " + JSON.stringify(globalThis.list1)); + console.log(TAG + " firstCallback callbackid1 : " + JSON.stringify(globalThis.callbackid1)); + id1 = globalThis.callbackid1; + console.log(TAG + " firstCallback id1 : " + JSON.stringify(id1)); + var para = { + resultCode: 2100, + want: { + abilityName: "MainAbility1", + bundleName: "com.test.lifecycle_crossplatform_xts", + moduleName: moduleName, + }, + }; + console.log(TAG + " terminateSelfwithresult para: " + JSON.stringify(para)); + + globalThis.ability1context + .terminateSelf() + .then((data) => { + console.log(TAG + " terminateSelfwithresult successful data: " + JSON.stringify(data)); + }) + .catch((error) => { + console.log(TAG + " terminateSelfwithresult error: " + JSON.stringify(error)); + }); + }, 4500); + setTimeout(function () { + console.log(TAG + " secondCallback listKey1 : " + JSON.stringify(globalThis.list1)); + let templist1 = globalThis.list1; + console.log(TAG + " secondCallback callbackid1 : " + JSON.stringify(globalThis.callbackid1)); + var strtemp = ""; + var listtemp = []; + for (var i = 0; i < templist1.length; i++) { + strtemp = templist1[i].substring(0, 13); + if (strtemp === "MainAbility2 ") { + listtemp.push(templist1[i]); + } + } + console.log(TAG + " listtemp is :" + JSON.stringify(listtemp)); + let exlist = listtemp; + expect(exlist[0]).assertEqual("MainAbility2 onAbilityCreate"); + expect(exlist[1]).assertEqual("MainAbility2 onWindowStageCreate"); + expect(exlist[2]).assertEqual("MainAbility2 onAbilityForeground"); + expect(exlist[3]).assertEqual("MainAbility2 onAbilityBackground"); + expect(exlist[4]).assertEqual("MainAbility2 onWindowStageDestroy"); + expect(exlist[5]).assertEqual("MainAbility2 onAbilityDestroy"); + + globalThis.applicationContext1.off("abilityLifecycle", globalThis.callbackid1, (error) => { + console.log(TAG + ": unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error)); + done(); + }); + }, 7000); + }); + + /* + * @tc.number Crossplatform_Multi_LifeCycleTest_0100 + * @tc.name Register in abilitystage,listen to the lifecycle of abilityA, then start other bundle's ablilty + * @tc.desc Function test + * @tc.level 0 + */ + it("Crossplatform_Multi_LifeCycleTest_0100", 0, async function (done) { + console.log("------------Crossplatform_Multi_LifeCycleTest_0100 START-------------"); + TAG = "Crossplatform_Multi_LifeCycleTest_0100"; + var str = { + bundleName: "com.test.lifecycle_crossplatform_xts", + abilityName: "MainAbility1", + moduleName: moduleName, + }; + globalThis.abilityContext + .startAbility(str) + .then((data) => { + console.info(TAG + " start successful. Data: " + data); + }) + .catch((error) => { + console.error(TAG + " start failed. Cause: " + JSON.stringify(error)); + }); + + await sleep(1000); + + var str = { + bundleName: otherBundle, + abilityName: "MainAbility", + moduleName: "entry_test", + }; + + let otherAppResult = 0; + globalThis.abilityContext + .startAbility(str) + .then((data) => { + console.info(TAG + " start successful. Data: " + data); + otherAppResult = 1; + }) + .catch((error) => { + console.error(TAG + " start failed. Cause: " + JSON.stringify(error)); + }); + await sleep(1000); + expect(otherAppResult == 1).assertTrue(); + let list1 = globalThis.list1; + console.info(TAG + "list: " + list1); + done(); + }); + + /* + * @tc.number Crossplatform_AbilityStage_onCreate_Test_0100 + * @tc.name Crossplatform_AbilityStage_onCreate_Test_0100 + * @tc.desc Start mainability2, test stage ability onCreate + * @tc.level 0 + */ + it("Crossplatform_AbilityStage_onCreate_Test_0100", 0, async function (done) { + console.log("------------Crossplatform_AbilityStage_onCreate_Test_0100 START-------------"); + TAG = "Crossplatform_AbilityStage_onCreate_Test_0100"; + var str = { + bundleName: "com.test.lifecycle_crossplatform_xts", + abilityName: "MainAbility2", + moduleName: moduleName, + }; + globalThis.abilityContext + .startAbility(str) + .then((data) => { + console.info(TAG + " start successful. Data: " + data); + }) + .catch((error) => { + console.error(TAG + " start failed. Cause: " + JSON.stringify(error)); + }); + setTimeout(function () { + // abilitystage的onCreatre里注册了globalThis.applicationContext,globalThis.applicationContext不为null + // 则oncreate触发成功。 + expect(globalThis.applicationContext != null).assertTrue(); + done(); + }, 3000); + }); + + /* + * @tc.number Crossplatform_AbilityStage_Context_Test_0100 + * @tc.name Crossplatform_AbilityStage_Context_Test_0100 + * @tc.desc Start mainability2, test stage ability context + * @tc.level 0 + */ + it("Crossplatform_AbilityStage_Context_Test_0100", 0, async function (done) { + console.log("------------Crossplatform_AbilityStage_Context_Test_0100 START-------------"); + TAG = "Crossplatform_AbilityStage_Context_Test_0100"; + var str = { + bundleName: "com.test.lifecycle_crossplatform_xts", + abilityName: "MainAbility2", + moduleName: moduleName, + }; + globalThis.abilityContext + .startAbility(str) + .then((data) => { + console.info(TAG + " start successful. Data: " + data); + }) + .catch((error) => { + console.error(TAG + " start failed. Cause: " + JSON.stringify(error)); + }); + setTimeout(function () { + // abilitystage的onCreatre里注册了globalThis.applicationContext,globalThis.applicationContext不为null + // 则oncreate触发成功,且context能够获取。 + console.log("AbilityStage_Context_Test_0100 1000"); + expect(globalThis.ability2 != null).assertTrue(); + console.log("AbilityStage_Context_Test_0100 1001"); + expect(globalThis.ability2.currentHapModuleInfo != null).assertTrue(); + console.log("AbilityStage_Context_Test_0100 1002"); + expect(globalThis.ability2.config != null).assertTrue(); + done(); + }, 1000); + }); + + /* + * @tc.number Crossplatform_Multi_LifeCycleTest_0200 + * @tc.name Crossplatform_Multi_LifeCycleTest_0200 + * @tc.desc start multi ability1, then start multi ability1, check life cycle + * @tc.level 0 + */ + it("Crossplatform_Multi_LifeCycleTest_0200", 0, async function (done) { + console.log("------------Crossplatform_Multi_LifeCycleTest_0200 START-------------"); + TAG = "Crossplatform_Multi_LifeCycleTest_0200"; + var str = { + bundleName: "com.test.lifecycle_crossplatform_xts", + abilityName: "MultiMainability1", + moduleName: moduleName, + }; + + // 第一次起MultiMainability1 + globalThis.abilityContext + .startAbility(str) + .then((data) => { + console.info(TAG + " start successful. Data: " + data); + }) + .catch((error) => { + console.error(TAG + " start failed. Cause: " + JSON.stringify(error)); + }); + await sleep(1500); + + var listtemp = []; + for (var i = 0; i < globalThis.mlist1.length; i++) { + const item = globalThis.mlist1[i]; + if (item.indexOf("MultiMainability1") != -1) { + listtemp.push(item); + } + } + console.info(TAG + "list:" + listtemp); + + expect(listtemp[0]).assertEqual("MultiMainability1 onWindowStageCreate"); + expect(listtemp[1]).assertEqual("MultiMainability1 onAbilityForeground"); + + // 第二次起MultiMainability1 + globalThis.abilityContext + .startAbility(str) + .then((data) => { + console.info(TAG + " start successful. Data: " + data); + }) + .catch((error) => { + console.error(TAG + " start failed. Cause: " + JSON.stringify(error)); + }); + await sleep(1500); + + var listtemp = []; + for (var i = 0; i < globalThis.mlist1.length; i++) { + const item = globalThis.mlist1[i]; + if (item.indexOf("MultiMainability1") != -1) { + listtemp.push(item); + } + } + console.info(TAG + "list:" + listtemp); + + expect(listtemp[2]).assertEqual("MultiMainability1 onAbilityCreate"); + expect(listtemp[3]).assertEqual("MultiMainability1 onWindowStageCreate"); + done(); + }); + + /* + * @tc.number Crossplatform_LifeCycleTest_on_0100 + * @tc.name Crossplatform_LifeCycleTest_on_0100 + * @tc.desc on abilityLifecycle twice in mainability13 + * @tc.level 0 + */ + it("Crossplatform_LifeCycleTest_on_0100", 0, async function (done) { + console.log("------------Crossplatform_LifeCycleTest_on_0100 START-------------"); + TAG = "Crossplatform_LifeCycleTest_on_0100"; + var str = { + bundleName: "com.test.lifecycle_crossplatform_xts", + abilityName: "MainAbility13", + moduleName: moduleName, + }; + + // 第一次起MultiMainability1 + globalThis.abilityContext + .startAbility(str) + .then((data) => { + console.info(TAG + " start successful. Data: " + data); + }) + .catch((error) => { + console.error(TAG + " start failed. Cause: " + JSON.stringify(error)); + }); + + await sleep(2500); + console.log(TAG + "list1:" + globalThis.list13); + const list1 = globalThis.list13; + console.log(TAG + "list2:" + globalThis.otherList13); + const list2 = globalThis.otherList13; + + expect(list1[0]).assertEqual(list2[0]); + expect(list1[1]).assertEqual(list2[1]); + expect(list1[2]).assertEqual(list2[2]); + globalThis.ability13.terminateSelf(); + done(); + }); + + /* + * @tc.number Crossplatform_LifeCycleTest_on_0200 + * @tc.name Crossplatform_LifeCycleTest_on_0200 + * @tc.desc Function test + * @tc.level 0 + */ + it("Crossplatform_LifeCycleTest_on_0200", 0, async function (done) { + console.log("------------Crossplatform_LifeCycleTest_on_0200 START-------------"); + TAG = "Crossplatform_LifeCycleTest_on_0200"; + var listKey14 = []; + let AbilityLifecycleCallback = { + onAbilityCreate(ability) { + console.log(TAG + " onAbilityCreate ability:" + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log(TAG + " onAbilityCreate abilityname:" + JSON.stringify(abilityname)); + console.log(TAG + " " + abilityname + " onAbilityCreate"); + listKey14.push(abilityname + " onAbilityCreate"); + }, + onWindowStageCreate(ability, windowStage) { + console.log(TAG + " onWindowStageCreate ability:" + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log(TAG + " onWindowStageCreate abilityname:" + JSON.stringify(abilityname)); + console.log(TAG + " " + abilityname + " onWindowStageCreate"); + listKey14.push(abilityname + " onWindowStageCreate"); + }, + onWindowStageActive(ability, windowStage) { + let abilityname = ability.context.abilityInfo.name; + console.log(abilityname + " onWindowStageActive"); + }, + onWindowStageInactive(ability, windowStage) { + let abilityname = ability.context.abilityInfo.name; + console.log(abilityname + " onWindowStageInactive"); + }, + onWindowStageDestroy(ability, windowStage) { + console.log(TAG + " AbilityLifecycleCallback1 onWindowStageDestroy ability:" + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log(TAG + " AbilityLifecycleCallback1 onWindowStageDestroy abilityname:" + JSON.stringify(abilityname)); + console.log(TAG + " " + abilityname + " onWindowStageDestroy"); + listKey14.push(abilityname + " onWindowStageDestroy"); + }, + onAbilityDestroy(ability) { + console.log(TAG + " AbilityLifecycleCallback1 onAbilityDestroy ability:" + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log(TAG + " AbilityLifecycleCallback1 onAbilityDestroy abilityname:" + JSON.stringify(abilityname)); + console.log(TAG + " " + abilityname + " onAbilityDestroy"); + listKey14.push(abilityname + " onAbilityDestroy"); + }, + onAbilityForeground(ability) { + console.log(TAG + " AbilityLifecycleCallback1 onAbilityForeground ability:" + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log(TAG + " AbilityLifecycleCallback1 onAbilityForeground abilityname:" + JSON.stringify(abilityname)); + console.log(TAG + " " + abilityname + " onAbilityForeground"); + listKey14.push(abilityname + " onAbilityForeground"); + }, + onAbilityBackground(ability) { + console.log(TAG + " AbilityLifecycleCallback1 onAbilityBackground ability:" + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log(TAG + " AbilityLifecycleCallback1 onAbilityBackground abilityname:" + JSON.stringify(abilityname)); + console.log(TAG + " " + abilityname + " onAbilityBackground"); + listKey14.push(abilityname + " onAbilityBackground"); + }, + onAbilityContinue(ability) { + console.log(TAG + " AbilityLifecycleCallback1 onAbilityContinue ability:" + JSON.stringify(ability)); + let abilityname = ability.context.abilityInfo.name; + console.log(TAG + " AbilityLifecycleCallback1 onAbilityContinue abilityname:" + JSON.stringify(abilityname)); + console.log(TAG + " " + abilityname + " onAbilityContinue"); + listKey14.push(abilityname + " onAbilityContinue"); + }, + }; + + var str = { + bundleName: "com.test.lifecycle_crossplatform_xts", + abilityName: "MainAbility14", + moduleName: moduleName, + }; + + // 第一次起MultiMainability1 + globalThis.abilityContext + .startAbility(str) + .then((data) => { + console.info(TAG + " start successful. Data: " + data); + }) + .catch((error) => { + console.error(TAG + " start failed. Cause: " + JSON.stringify(error)); + }); + + await sleep(1000); + let applicationContext = globalThis.ability14.getApplicationContext(); + + for (let i = 0; i < 10; i++) { + const tempId = applicationContext.on("abilityLifecycle", AbilityLifecycleCallback); + console.log(TAG + " registerAbilityLifecycleCallback1 number: " + JSON.stringify(tempId)); + + applicationContext.off("abilityLifecycle", tempId, (error) => { + console.log(TAG + ": unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error)); + }); + } + + applicationContext.on("abilityLifecycle", AbilityLifecycleCallback); + await sleep(1000); + globalThis.ability14.terminateSelf(); + await sleep(1000); + console.info(TAG + "list:" + listKey14); + + var listtemp = []; + for (var i = 0; i < listKey14.length; i++) { + const item = listKey14[i]; + if (item.indexOf("MainAbility14") != -1) { + listtemp.push(item); + } + } + expect(listtemp[0]).assertEqual("MainAbility14 onAbilityBackground"); + expect(listtemp[1]).assertEqual("MainAbility14 onWindowStageDestroy"); + expect(listtemp[2]).assertEqual("MainAbility14 onAbilityDestroy"); + done(); + }); + + /* + * @tc.number Crossplatform_LifeCycleTest_on_0300 + * @tc.name Crossplatform_LifeCycleTest_on_0300 + * @tc.desc unregister callback id which is not exists. + * @tc.level 0 + */ + it("Crossplatform_LifeCycleTest_on_0300", 0, async function (done) { + console.log("------------Crossplatform_LifeCycleTest_on_0300 START-------------"); + TAG = "Crossplatform_LifeCycleTest_on_0300"; + + let applicationContext = globalThis.abilityContext.getApplicationContext(); + applicationContext.off("abilityLifecycle", 100, (error) => { + expect(error.code).assertEqual(401); + console.log(TAG + ": unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error)); + done(); + }); + }); + + /* + * @tc.number Crossplatform_LifeCycleTest_on_0400 + * @tc.name Crossplatform_LifeCycleTest_on_0400 + * @tc.desc unregister callback twice. + * @tc.level 0 + */ + it("Crossplatform_LifeCycleTest_on_0400", 0, async function (done) { + console.log("------------LifeCycleTest_on_0400 START-------------"); + TAG = "Crossplatform_LifeCycleTest_on_0400"; + + var str = { + bundleName: "com.test.lifecycle_crossplatform_xts", + abilityName: "MainAbility1", + moduleName: moduleName, + }; + + // 第一次起MultiMainability1 + globalThis.abilityContext + .startAbility(str) + .then((data) => { + console.info(TAG + " start successful. Data: " + data); + }) + .catch((error) => { + console.error(TAG + " start failed. Cause: " + JSON.stringify(error)); + }); + + await sleep(3000); + console.info(TAG + "list:" + globalThis.list1); + + globalThis.applicationContext1.off("abilityLifecycle", globalThis.callbackid1, (error) => { + console.log(TAG + ": unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error)); + }); + + await sleep(500); + + globalThis.applicationContext1.off("abilityLifecycle", globalThis.callbackid1, (error) => { + console.log(TAG + ": unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error)); + expect(error.code).assertEqual(401); + done(); + }); + }); + + /* + * @tc.number Crossplatform_LifeCycleTest_on_0500 + * @tc.name Crossplatform_LifeCycleTest_on_0500 + * @tc.desc start other hap's ability in the same app, and register this lifecycle. + * @tc.level 0 + */ + it("Crossplatform_LifeCycleTest_on_0500", 0, async function (done) { + console.log("------------LifeCycleTest_on_0500 START-------------"); + TAG = "LifeCycleTest_on_0500"; + + var str = { + bundleName: "com.test.lifecycle_crossplatform_xts", + abilityName: "MainAbility", + moduleName: otherModuleName, + }; + + // 第一次起MultiMainability1 + globalThis.abilityContext + .startAbility(str) + .then((data) => { + console.info(TAG + " start successful. Data: " + data); + }) + .catch((error) => { + console.error(TAG + " start failed. Cause: " + JSON.stringify(error)); + }); + + await sleep(2000); + console.info(TAG + "list:" + globalThis.featureList1); + expect(globalThis.featureList1[0]).assertEqual("FeatureMainAbility onWindowStageCreate"); + expect(globalThis.featureList1[1]).assertEqual("FeatureMainAbility onAbilityForeground"); + + globalThis.featureAbilityContext.terminateSelf(); + await sleep(1000); + done(); + }); + }); +} diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/test/List.test.ets b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..9b63d932ae5bbed6f352a4ec9dc4006eefe9ba52 --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/ets/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 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 LifeCycleTest from './LifeCycleTest.test' + +export default function testsuite() { + LifeCycleTest() +} \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/module.json b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..298d61f64e85a108705faf628cdb2ee528e29f58 --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/module.json @@ -0,0 +1,196 @@ +{ + "module": { + "name": "entry_test", + "type": "feature", + "srcEntry": "./ets/Application/AbilityStage.ts", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntry": "./ets/TestAbility/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "exported": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + }, + { + "name": "MainAbility1", + "srcEntry": "./ets/MainAbility1/MainAbility1.ts", + "description": "$string:MainAbility1_desc", + "icon": "$media:icon", + "label": "$string:MainAbility1_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background" + }, + { + "name": "MainAbility2", + "srcEntry": "./ets/MainAbility2/MainAbility2.ts", + "description": "$string:MainAbility2_desc", + "icon": "$media:icon", + "label": "$string:MainAbility2_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background" + }, + { + "name": "MainAbility3", + "srcEntry": "./ets/MainAbility3/MainAbility3.ts", + "description": "$string:MainAbility3_desc", + "icon": "$media:icon", + "label": "$string:MainAbility3_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background" + }, + { + "name": "MainAbility4", + "srcEntry": "./ets/MainAbility4/MainAbility4.ts", + "description": "$string:MainAbility4_desc", + "icon": "$media:icon", + "label": "$string:MainAbility4_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background" + }, + { + "name": "MainAbility5", + "srcEntry": "./ets/MainAbility5/MainAbility5.ts", + "description": "$string:MainAbility5_desc", + "icon": "$media:icon", + "label": "$string:MainAbility5_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background" + }, + { + "name": "MainAbility6", + "srcEntry": "./ets/MainAbility6/MainAbility6.ts", + "description": "$string:MainAbility6_desc", + "icon": "$media:icon", + "label": "$string:MainAbility6_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background" + }, + { + "name": "MainAbility7", + "srcEntry": "./ets/MainAbility7/MainAbility7.ts", + "description": "$string:MainAbility7_desc", + "launchType": "singleton", + "icon": "$media:icon", + "label": "$string:MainAbility7_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background" + }, + { + "name": "MainAbility8", + "srcEntry": "./ets/MainAbility8/MainAbility8.ts", + "description": "$string:MainAbility8_desc", + "launchType": "standard", + "icon": "$media:icon", + "label": "$string:MainAbility8_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background" + }, + { + "name": "MainAbility9", + "srcEntry": "./ets/MainAbility9/MainAbility9.ts", + "description": "$string:MainAbility9_desc", + "icon": "$media:icon", + "label": "$string:MainAbility9_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background" + }, + { + "name": "Hap1MainAbility1", + "srcEntry": "./ets/Hap1MainAbility1/Hap1MainAbility1.ts", + "description": "$string:Hap1MainAbility1_desc", + "icon": "$media:icon", + "label": "$string:Hap1MainAbility1_label", + "launchType": "singleton", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background" + }, + { + "name": "Hap1MainAbility2", + "srcEntry": "./ets/Hap1MainAbility2/Hap1MainAbility2.ts", + "description": "$string:Hap1MainAbility2_desc", + "icon": "$media:icon", + "label": "$string:Hap1MainAbility2_label", + "launchType": "standard", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background" + }, + { + "name": "MainAbility10", + "srcEntry": "./ets/MainAbility10/MainAbility10.ts", + "description": "$string:MainAbility10_desc", + "icon": "$media:icon", + "label": "$string:MainAbility10_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background" + }, + { + "name": "MainAbility11", + "srcEntry": "./ets/MainAbility11/MainAbility11.ts", + "description": "$string:MainAbility11_desc", + "icon": "$media:icon", + "label": "$string:MainAbility11_label", + "launchType": "standard", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background" + }, + { + "name": "MainAbility12", + "srcEntry": "./ets/MainAbility12/MainAbility12.ts", + "description": "$string:MainAbility12_desc", + "icon": "$media:icon", + "label": "$string:MainAbility12_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background" + }, + { + "name": "MainAbility13", + "srcEntry": "./ets/MainAbility13/MainAbility13.ts", + "description": "$string:MainAbility12_desc", + "icon": "$media:icon", + "label": "$string:MainAbility12_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background" + }, + { + "name": "MainAbility14", + "srcEntry": "./ets/MainAbility14/MainAbility14.ts", + "description": "$string:MainAbility12_desc", + "icon": "$media:icon", + "label": "$string:MainAbility12_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background" + }, + { + "name": "MultiMainability1", + "srcEntry": "./ets/MultiMainability1/MultiMainability1.ts", + "description": "$string:MultiMainability1_desc", + "icon": "$media:icon", + "launchType": "standard", + "label": "$string:MultiMainability1_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background" + } + ] + } +} diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/resources/base/element/color.json b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/resources/base/element/string.json b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..31c7a5da55f72991fcf4b92cadec155f728bf07e --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/resources/base/element/string.json @@ -0,0 +1,180 @@ +{ + "string": [ + { + "name": "module_test_desc", + "value": "test ability description" + }, + { + "name": "TestAbility_desc", + "value": "the test ability" + }, + { + "name": "TestAbility_label", + "value": "test label" + }, + { + "name": "phone_entry_dsc", + "value": "i am an entry for phone" + }, + { + "name": "phone_entry_main", + "value": "the phone entry ability" + }, + { + "name": "entry_label", + "value": "ActsContextTest" + }, + { + "name": "form_description", + "value": "my form" + }, + { + "name": "serviceability_description", + "value": "my whether" + }, + { + "name": "description_application", + "value": "demo for test" + }, + { + "name": "entry_desc", + "value": "description" + }, + { + "name": "MainAbility_desc", + "value": "description" + }, + { + "name": "MainAbility_label", + "value": "label" + }, + { + "name": "MainAbility1_desc", + "value": "description" + }, + { + "name": "MainAbility1_label", + "value": "label" + }, + { + "name": "MainAbility2_desc", + "value": "description" + }, + { + "name": "MainAbility2_label", + "value": "label" + }, + { + "name": "MainAbility3_desc", + "value": "description" + }, + { + "name": "MainAbility3_label", + "value": "label" + }, + { + "name": "MainAbility4_desc", + "value": "description" + }, + { + "name": "MainAbility4_label", + "value": "label" + }, + { + "name": "MainAbility5_desc", + "value": "description" + }, + { + "name": "MainAbility5_label", + "value": "label" + }, + { + "name": "MainAbility6_desc", + "value": "description" + }, + { + "name": "MainAbility6_label", + "value": "label" + }, + { + "name": "MainAbility7_desc", + "value": "description" + }, + { + "name": "MainAbility7_label", + "value": "label" + }, + { + "name": "MainAbility8_desc", + "value": "description" + }, + { + "name": "MainAbility8_label", + "value": "label" + }, + { + "name": "MainAbility9_desc", + "value": "description" + }, + { + "name": "MainAbility9_label", + "value": "label" + }, + { + "name": "Hap1MainAbility1_desc", + "value": "description" + }, + { + "name": "Hap1MainAbility1_label", + "value": "label" + }, + { + "name": "Hap1MainAbility2_desc", + "value": "description" + }, + { + "name": "Hap1MainAbility2_label", + "value": "label" + }, + { + "name": "MainAbility10_desc", + "value": "description" + }, + { + "name": "MainAbility10_label", + "value": "label" + }, + { + "name": "MainAbility11_desc", + "value": "description" + }, + { + "name": "MainAbility11_label", + "value": "label" + }, + { + "name": "MainAbility12_desc", + "value": "description" + }, + { + "name": "MainAbility12_label", + "value": "label" + }, + { + "name": "MainAbility13_desc", + "value": "description" + }, + { + "name": "MainAbility13_label", + "value": "label" + }, + { + "name": "MultiMainability1_desc", + "value": "description" + }, + { + "name": "MultiMainability1_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/resources/base/media/icon.png b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/resources/base/media/icon.png differ diff --git a/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/resources/base/profile/test_pages.json b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/resources/base/profile/test_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..d9a501abc4fa3eadcfad92f80f348bc9735cb307 --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsLifeCycleEtsTest/src/main/resources/base/profile/test_pages.json @@ -0,0 +1,19 @@ +{ + "src": [ + "TestAbility/pages/Index", + "TestAbility/pages/index1", + "TestAbility/pages/index2", + "TestAbility/pages/index3", + "TestAbility/pages/index4", + "TestAbility/pages/index5", + "TestAbility/pages/index6", + "TestAbility/pages/index7", + "TestAbility/pages/index8", + "TestAbility/pages/index9", + "TestAbility/pages/index10", + "TestAbility/pages/index11", + "TestAbility/pages/index12", + "TestAbility/pages/indexh1a1", + "TestAbility/pages/indexh1a2" + ] +} diff --git a/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/AppScope/app.json b/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..5b01b9bbba4d839d8b028323e74015c45ec315be --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/AppScope/app.json @@ -0,0 +1,16 @@ +{ + "app": { + "bundleName": "com.example.uiabilitylifecycle", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name", + "minAPIVersion": 9, + "targetAPIVersion": 9, + "car": { + "apiCompatibleVersion": 9, + "singleUser": false + } + } +} diff --git a/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/AppScope/resources/base/element/string.json b/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..3811bc441fc0f128eb4d14c53ed463ffb8dc3811 --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "xtsDemo1" + } + ] +} diff --git a/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/AppScope/resources/base/media/app_icon.png b/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/AppScope/resources/base/media/app_icon.png differ diff --git a/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/BUILD.gn b/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..dbf21402de9b225740144d89acc6dcb8e12ad2d7 --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/BUILD.gn @@ -0,0 +1,40 @@ +# Copyright (c) 2023 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("ActsUiAbilityEtsTest") { + hap_profile = "src/main/module.json" + deps = [ + ":windowStage_js_assets", + ":windowStage_resources", + ] + ets2abc = true + certificate_profile = "./signature/openharmony_sx.p7b" + + hap_name = "ActsUiAbilityEtsTest" + subsystem_name = "ability" + part_name = "ability_runtime" +} +ohos_app_scope("windowStage_app_profile") { + app_profile = "AppScope/app.json" + sources = [ "AppScope/resources" ] +} +ohos_js_assets("windowStage_js_assets") { + source_dir = "src/main/ets" +} +ohos_resources("windowStage_resources") { + sources = [ "src/main/resources" ] + deps = [ ":windowStage_app_profile" ] + hap_profile = "src/main/module.json" +} diff --git a/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/Test.json b/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..9bab4c8ef20dc48f2c6373a2b207cd0fd9cf6546 --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/Test.json @@ -0,0 +1,21 @@ +{ + "description": "Configuration for hjunit demo Tests", + "driver": { + "type": "OHJSUnitTest", + "test-timeout": "60000", + "shell-timeout": "60000", + "testcase-timeout": 15000, + "bundle-name": "com.example.uiabilitylifecycle", + "module-name": "entry_test" + }, + "kits": [ + { + "test-file-name": [ + "ActsUiAbilityEtsTest.hap", + "commonTestAbilityApp.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/signature/openharmony_sx.p7b b/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..46d860f19d74687a7910fe08ac498138ed26a73e Binary files /dev/null and b/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/signature/openharmony_sx.p7b differ diff --git a/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/src/main/ets/Application/AbilityStage.ts b/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/src/main/ets/Application/AbilityStage.ts new file mode 100644 index 0000000000000000000000000000000000000000..5f781eef66760e9268ec99f02a6d758a49983cfc --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/src/main/ets/Application/AbilityStage.ts @@ -0,0 +1,7 @@ +import AbilityStage from '@ohos.app.ability.AbilityStage'; + +export default class MyAbilityStage extends AbilityStage { + onCreate() { + console.log("[Demo] MyAbilityStage onCreate") + } +} \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/src/main/ets/MainAbility1/MainAbility1.ts b/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/src/main/ets/MainAbility1/MainAbility1.ts new file mode 100644 index 0000000000000000000000000000000000000000..d5e3a7b9e9078ef6ad2181a48ff1b6df7db35fde --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/src/main/ets/MainAbility1/MainAbility1.ts @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2022 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 Ability from '@ohos.app.ability.UIAbility' + +let abilityName = null; +function recordLife(ownList, abilityName, lifeName) { + ownList.push(abilityName + ' ' + lifeName); +} + +export default class MainAbility1 extends Ability { + + onNewWant(want, launchParam) { + console.log("[Demo] MainAbility1 onNewWant") + globalThis.onNewWantStr = abilityName + ' ' + 'onNewWant'; + } + + onCreate(want, launchParam) { + console.log("[Demo] MainAbility1 onCreate") + globalThis.launchParam1 = launchParam; + abilityName = want.abilityName + globalThis.list1 = []; + recordLife(globalThis.list1, abilityName, 'onCreate'); + } + + onDestroy() { + console.log("[Demo] MainAbility1 onDestroy") + recordLife(globalThis.list1, abilityName, 'onDestroy'); + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log("[Demo] MainAbility1 onWindowStageCreate") + globalThis.ability1context = this.context; + recordLife(globalThis.list1, abilityName, 'onWindowStageCreate'); + + windowStage.loadContent('TestAbility/pages/Index1', (err, data) => { + if (err.code) { + console.log('MainAbility1 loadContent error'); + return; + } + console.log('MainAbility1 loadContent success'); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + console.log("[Demo] MainAbility1 onWindowStageDestroy") + recordLife(globalThis.list1, abilityName, 'onWindowStageDestroy'); + } + + onForeground() { + console.log("[Demo] MainAbility1 onForeground") + recordLife(globalThis.list1, abilityName, 'onForeground'); + } + + onBackground() { + // Ability has back to background + console.log("[Demo] MainAbility1 onBackground") + recordLife(globalThis.list1, abilityName, 'onBackground'); + } +}; diff --git a/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/src/main/ets/MainAbility2/MainAbility2.ts b/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/src/main/ets/MainAbility2/MainAbility2.ts new file mode 100644 index 0000000000000000000000000000000000000000..18ae39583c2ca2331a463e6ebf3210194c82358e --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/src/main/ets/MainAbility2/MainAbility2.ts @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2022 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 Ability from '@ohos.app.ability.UIAbility' + +let abilityName = null; +function recordLife(ownList, abilityName, lifeName) { + ownList.push(abilityName + ' ' + lifeName); +} + +export default class MainAbility2 extends Ability { + onCreate(want, launchParam) { + console.log("[Demo] MainAbility2 onCreate") + abilityName = want.abilityName + globalThis.list2 = []; + recordLife(globalThis.list2, abilityName, 'onCreate'); + } + + onDestroy() { + console.log("[Demo] MainAbility2 onDestroy") + recordLife(globalThis.list2, abilityName, 'onDestroy'); + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log("[Demo] MainAbility2 onWindowStageCreate") + globalThis.ability2context = this.context; + recordLife(globalThis.list2, abilityName, 'onWindowStageCreate'); + + windowStage.loadContent('TestAbility/pages/Index2', (err, data) => { + if (err.code) { + console.log('MainAbility2 loadContent error'); + return; + } + console.log('MainAbility2 loadContent success'); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + console.log("[Demo] MainAbility2 onWindowStageDestroy") + recordLife(globalThis.list2, abilityName, 'onWindowStageDestroy'); + } + + onForeground() { + console.log("[Demo] MainAbility2 onForeground") + recordLife(globalThis.list2, abilityName, 'onForeground'); + setTimeout(function () { + console.log("[Demo] MainAbility2 onForeground after 1500ms") + globalThis.ability2context.terminateSelf() + .then((data) => { + console.info('[Demo] MainAbility2 terminateself succeeded: ' + data); + }).catch((error) => { + console.error('[Demo] MainAbility2 terminateself failed. Cause: ' + error); + }) + }, 1500); + } + + onBackground() { + // Ability has back to background + console.log("[Demo] MainAbility2 onBackground") + recordLife(globalThis.list2, abilityName, 'onBackground'); + } +}; diff --git a/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/src/main/ets/MainAbility3/MainAbility3.ts b/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/src/main/ets/MainAbility3/MainAbility3.ts new file mode 100644 index 0000000000000000000000000000000000000000..1268d0db1cbb477cb055ba7ada670f531b3dc752 --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/src/main/ets/MainAbility3/MainAbility3.ts @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2022 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 Ability from '@ohos.app.ability.UIAbility' + +let abilityName = null; +function recordLife(ownList, abilityName, lifeName) { + ownList.push(abilityName + ' ' + lifeName); +} + +export default class MainAbility3 extends Ability { + onCreate(want, launchParam) { + console.log("[Demo] MainAbility3 onCreate") + abilityName = want.abilityName + globalThis.list3 = []; + recordLife(globalThis.list3, abilityName, 'onCreate'); + } + + onDestroy() { + console.log("[Demo] MainAbility3 onDestroy") + recordLife(globalThis.list3, abilityName, 'onDestroy'); + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log("[Demo] MainAbility3 onWindowStageCreate") + globalThis.ability3context = this.context; + recordLife(globalThis.list3, abilityName, 'onWindowStageCreate'); + + windowStage.loadContent('TestAbility/pages/Index2', (err, data) => { + if (err.code) { + console.log('MainAbility3 loadContent error'); + return; + } + console.log('MainAbility3 loadContent success'); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + console.log("[Demo] MainAbility3 onWindowStageDestroy") + recordLife(globalThis.list3, abilityName, 'onWindowStageDestroy'); + } + + onForeground() { + console.log("[Demo] MainAbility3 onForeground") + recordLife(globalThis.list3, abilityName, 'onForeground'); + } + + onBackground() { + // Ability has back to background + console.log("[Demo] MainAbility3 onBackground") + recordLife(globalThis.list3, abilityName, 'onBackground'); + } +}; diff --git a/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/src/main/ets/TestAbility/TestAbility.ets b/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/src/main/ets/TestAbility/TestAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..613f239dfe11e4fb11a7b9f726e06eaaef5309d0 --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/src/main/ets/TestAbility/TestAbility.ets @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2023 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 UIAbility from '@ohos.app.ability.UIAbility'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; +import hilog from '@ohos.hilog'; +import { Hypium } from '@ohos/hypium'; +import testsuite from '../test/List.test'; +import window from '@ohos.window'; + +export default class TestAbility extends UIAbility { + onCreate(want, launchParam) { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onCreate'); + hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? ''); + hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:'+ JSON.stringify(launchParam) ?? ''); + var abilityDelegator: any + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var abilityDelegatorArguments: any + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!'); + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + } + + onDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageCreate'); + windowStage.loadContent('TestAbility/pages/Index', (err, data) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', + JSON.stringify(data) ?? ''); + }); + globalThis.abilityContext = this.context; + } + + onWindowStageDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageDestroy'); + } + + onForeground() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onForeground'); + } + + onBackground() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onBackground'); + } +} \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/src/main/ets/TestAbility/pages/Index.ets b/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/src/main/ets/TestAbility/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..40f0a77aebde46e8c079bd9975134e37d373c1f7 --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/src/main/ets/TestAbility/pages/Index.ets @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2023 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 hilog from '@ohos.hilog'; + +@Entry +@Component +struct Index { + aboutToAppear() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility index aboutToAppear'); + } + @State message: string = 'Hello World' + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .width('35%') + .height('5%') + .onClick(()=>{ + }) + } + .width('100%') + } + .height('100%') + } + } \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/src/main/ets/TestAbility/pages/Index1.ets b/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/src/main/ets/TestAbility/pages/Index1.ets new file mode 100644 index 0000000000000000000000000000000000000000..5f0560de7982c21e63ea0117b07f0e915168fdb8 --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/src/main/ets/TestAbility/pages/Index1.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2022 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. + */ +@Entry +@Component +struct Index1 { + build() { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text('Hello World Mainability1') + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/src/main/ets/TestAbility/pages/Index2.ets b/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/src/main/ets/TestAbility/pages/Index2.ets new file mode 100644 index 0000000000000000000000000000000000000000..3454fec431af36ac22d7c90ab7f91888c0a7e7d5 --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/src/main/ets/TestAbility/pages/Index2.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2022 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. + */ +@Entry +@Component +struct Index2 { + build() { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text('Hello World Mainability2') + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..92a16d84e8870da219c51d9f1342c79203c1f42d --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,49 @@ +import hilog from '@ohos.hilog'; +import TestRunner from '@ohos.application.testRunner'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +var abilityDelegator = undefined +var abilityDelegatorArguments = undefined + +async function onAbilityCreateCallback() { + hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback'); +} + +async function addAbilityMonitorCallback(err: any) { + hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? ''); +} + +export default class OpenHarmonyTestRunner implements TestRunner { + constructor() { + } + + onPrepare() { + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare '); + } + + async onRun() { + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run'); + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility' + let lMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + }; + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) + var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName + var debug = abilityDelegatorArguments.parameters['-D'] + if (debug == 'true') + { + cmd += ' -D' + } + hilog.info(0x0000, 'testTag', 'cmd : %{public}s', cmd); + abilityDelegator.executeShellCommand(cmd, + (err: any, d: any) => { + hilog.info(0x0000, 'testTag', 'executeShellCommand : err : %{public}s', JSON.stringify(err) ?? ''); + hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.stdResult ?? ''); + hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.exitCode ?? ''); + }) + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun end'); + } +} \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/src/main/ets/test/List.test.ets b/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/src/main/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..6499302bbf6c4e1a85f11def00a16ad3c9302459 --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/src/main/ets/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 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 abilityLifeCycleTest from './abilityLifeCycle.test' + +export default function testsuite() { + abilityLifeCycleTest() +} \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/src/main/ets/test/abilityLifeCycle.test.ets b/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/src/main/ets/test/abilityLifeCycle.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..604b986238477a639723aab1d2b02e4f95c90a42 --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/src/main/ets/test/abilityLifeCycle.test.ets @@ -0,0 +1,478 @@ +/* + * Copyright (c) 2023 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 { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "@ohos/hypium"; +import aConstant from '@ohos.app.ability.AbilityConstant' + +function sleep(time) { + return new Promise((resolve) => setTimeout(resolve, time)); +} + +const moduleName = "entry_test"; +export default function abilityTest() { + describe("ActsAbilityLifeCycleTest", function () { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(function () { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(function () { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(function () { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(function () { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + + let TAG = ""; + const otherBundle = "com.example.commontestabilityapp"; + + /** + *@tc.number : UI_ABILITY_CONTEXT_TEST_0001 + *@tc.name : UI_Ability_Context_Test_0001 + *@tc.desc : Test context. + *@tc.size : MediumTest + *@tc.type : Function + *@tc.level : Level 1 + */ + it("UI_Ability_Context_Test_0001", 0, async (done) => { + console.log("------------UI_ABILITY_CONTEXT_TEST_0001 START-------------"); + TAG = "UI_ABILITY_CONTEXT_TEST_0001"; + expect(globalThis.abilityContext != null).assertTrue(); + done(); + }); + + /** + *@tc.number : UI_ABILITY_CONTEXT_TEST_0002 + *@tc.name : UI_Ability_Context_Test_0002 + *@tc.desc : Test context. + *@tc.size : MediumTest + *@tc.type : Function + *@tc.level : Level 1 + */ + it("UI_Ability_Context_Test_0002", 0, async (done) => { + console.log("------------UI_ABILITY_CONTEXT_TEST_0002 START-------------"); + TAG = "UI_ABILITY_CONTEXT_TEST_0002"; + expect(globalThis.abilityContext != null).assertTrue(); + expect(globalThis.abilityContext.startAbility != null).assertTrue(); + done(); + }); + + /** + *@tc.number : UI_ABILITY_CONTEXT_TEST_0003 + *@tc.name : UIAbilityContextTest_0003 + *@tc.desc : Test context. + *@tc.size : MediumTest + *@tc.type : Function + *@tc.level : Level 1 + */ + it("UIAbilityContextTest_0003", 0, async (done) => { + console.log("------------UI_ABILITY_CONTEXT_TEST_0003 START-------------"); + TAG = "UI_ABILITY_CONTEXT_TEST_0003"; + expect(globalThis.abilityContext != null).assertTrue(); + expect(globalThis.abilityContext.terminateSelf != null).assertTrue(); + done(); + }); + + /** + *@tc.number : UI_ABILITY_LIFE_CYCLE_TEST_0001 + *@tc.name : UI_Ability_Life_Cycle_Test_0001 + *@tc.desc : Only start 'MainAbility2', MainAbility2 will terminate self after 1.5 seconds. + *@tc.size : MediumTest + *@tc.type : Function + *@tc.level : Level 1 + */ + it("UI_Ability_Life_Cycle_Test_0001", 0, async (done) => { + console.log("------------UI_ABILITY_LIFE_CYCLE_TEST_0001 START-------------"); + TAG = "UI_ABILITY_LIFE_CYCLE_TEST_0001"; + + var want = { + bundleName: "com.example.uiabilitylifecycle", + abilityName: "MainAbility2", + moduleName: moduleName, + }; + globalThis.abilityContext + .startAbility(want) + .then((data) => { + console.info(TAG + " start successful. Data: " + data); + }) + .catch((error) => { + console.error(TAG + " start failed. Cause: " + JSON.stringify(error)); + }); + + // MainAbility2在1.5秒后,会终结自己,等待2.5s, 确保MainAbility2终结完自己 + await sleep(2500); + + const result2 = globalThis.list2; + console.info("result2: " + JSON.stringify(result2)); + + expect(result2[0]).assertEqual("MainAbility2 onCreate"); + expect(result2[1]).assertEqual("MainAbility2 onWindowStageCreate"); + expect(result2[2]).assertEqual("MainAbility2 onForeground"); + expect(result2[3]).assertEqual("MainAbility2 onBackground"); + expect(result2[4]).assertEqual("MainAbility2 onWindowStageDestroy"); + expect(result2[5]).assertEqual("MainAbility2 onDestroy"); + done(); + }); + + /** + *@tc.number : UI_ABILITY_LIFE_CYCLE_TEST_0002 + *@tc.name : UI_Ability_Life_Cycle_Test_0002 + *@tc.desc : Only start 'MainAbility1' + *@tc.size : MediumTest + *@tc.type : Function + *@tc.level : Level 1 + */ + it("UI_Ability_Life_Cycle_Test_0002", 0, async (done) => { + console.log("------------UI_ABILITY_LIFE_CYCLE_TEST_0002 START-------------"); + TAG = "UI_ABILITY_LIFE_CYCLE_TEST_0002"; + + var want = { + bundleName: "com.example.uiabilitylifecycle", + abilityName: "MainAbility1", + moduleName: moduleName, + }; + globalThis.abilityContext + .startAbility(want) + .then((data) => { + console.info(TAG + " start successful. Data: " + data); + }) + .catch((error) => { + console.error(TAG + " start failed. Cause: " + JSON.stringify(error)); + }); + + await sleep(2500); + + const result1 = globalThis.list1; + console.info("result1: " + JSON.stringify(result1)); + + expect(result1[0]).assertEqual("MainAbility1 onCreate"); + expect(result1[1]).assertEqual("MainAbility1 onWindowStageCreate"); + expect(result1[2]).assertEqual("MainAbility1 onForeground"); + + globalThis.ability1context.terminateSelf(); + await sleep(1000); + expect(result1[3]).assertEqual("MainAbility1 onBackground"); + expect(result1[4]).assertEqual("MainAbility1 onWindowStageDestroy"); + expect(result1[5]).assertEqual("MainAbility1 onDestroy"); + done(); + }); + + /** + *@tc.number : UI_ABILITY_LIFE_CYCLE_TEST_0003 + *@tc.name : UI_Ability_Life_Cycle_Test_0003 + *@tc.desc : start 'MainAbility2', after MainAbility2 terminated, start MainAbility1, after 2 seconds, terminate MainAbility1. + *@tc.size : MediumTest + *@tc.type : Function + *@tc.level : Level 1 + */ + it("UI_Ability_Life_Cycle_Test_0003", 0, async (done) => { + console.log("------------UI_ABILITY_LIFE_CYCLE_TEST_0003 START-------------"); + TAG = "UI_ABILITY_LIFE_CYCLE_TEST_0003"; + + var want = { + bundleName: "com.example.uiabilitylifecycle", + abilityName: "MainAbility2", + moduleName: moduleName, + }; + globalThis.abilityContext + .startAbility(want) + .then((data) => { + console.info(TAG + " start successful. Data: " + data); + }) + .catch((error) => { + console.error(TAG + " start failed. Cause: " + JSON.stringify(error)); + }); + + // MainAbility2在1.5秒后,会终结自己,等待2.5s, 确保MainAbility2终结完自己 + await sleep(2500); + + var want = { + bundleName: "com.example.uiabilitylifecycle", + abilityName: "MainAbility1", + moduleName: moduleName, + }; + globalThis.abilityContext + .startAbility(want) + .then((data) => { + console.info(TAG + " start MainAbility1 successful. Data: " + data); + }) + .catch((error) => { + console.error(TAG + " start MainAbility1 failed. Cause: " + JSON.stringify(error)); + }); + await sleep(2000); + globalThis.ability1context.terminateSelf(); + await sleep(1000); + + const result1 = globalThis.list1; + const result2 = globalThis.list2; + console.info("result1: " + JSON.stringify(result1)); + console.info("result2: " + JSON.stringify(result2)); + + expect(result2[0]).assertEqual("MainAbility2 onCreate"); + expect(result2[1]).assertEqual("MainAbility2 onWindowStageCreate"); + expect(result2[2]).assertEqual("MainAbility2 onForeground"); + expect(result2[3]).assertEqual("MainAbility2 onBackground"); + expect(result2[4]).assertEqual("MainAbility2 onWindowStageDestroy"); + expect(result2[5]).assertEqual("MainAbility2 onDestroy"); + + expect(result1[0]).assertEqual("MainAbility1 onCreate"); + expect(result1[1]).assertEqual("MainAbility1 onWindowStageCreate"); + expect(result1[2]).assertEqual("MainAbility1 onForeground"); + expect(result1[3]).assertEqual("MainAbility1 onBackground"); + expect(result1[4]).assertEqual("MainAbility1 onWindowStageDestroy"); + expect(result1[5]).assertEqual("MainAbility1 onDestroy"); + done(); + }); + + /** + *@tc.number : UI_ABILITY_LIFE_CYCLE_TEST_0004 + *@tc.name : UI_Ability_Life_Cycle_Test_0004 + *@tc.desc : start mainability1, after 1.5 seconds, start mainability2, after 1.5 seconds, mainability2 terminated. + after 1 seconds, terminate mainability1. + *@tc.size : MediumTest + *@tc.type : Function + *@tc.level : Level 1 + */ + it("UI_Ability_Life_Cycle_Test_0004", 0, async (done) => { + console.log("------------UI_ABILITY_LIFE_CYCLE_TEST_0004 START-------------"); + TAG = "UI_ABILITY_LIFE_CYCLE_TEST_0004"; + + var want = { + bundleName: "com.example.uiabilitylifecycle", + abilityName: "MainAbility1", + moduleName: moduleName, + }; + globalThis.abilityContext + .startAbility(want) + .then((data) => { + console.info(TAG + " start successful. Data: " + data); + }) + .catch((error) => { + console.error(TAG + " start failed. Cause: " + JSON.stringify(error)); + }); + + // 1.5秒后打开MainAbility2 + await sleep(1500); + + var want = { + bundleName: "com.example.uiabilitylifecycle", + abilityName: "MainAbility2", + moduleName: moduleName, + }; + globalThis.abilityContext + .startAbility(want) + .then((data) => { + console.info(TAG + " start successful. Data: " + data); + }) + .catch((error) => { + console.error(TAG + " start failed. Cause: " + JSON.stringify(error)); + }); + + await sleep(1000); + + const result1 = globalThis.list1; + console.info(TAG + "result1: " + JSON.stringify(result1)); + + // 启动mainability2后,mainability1将会切到后台 + expect(result1[0]).assertEqual("MainAbility1 onCreate"); + expect(result1[1]).assertEqual("MainAbility1 onWindowStageCreate"); + expect(result1[2]).assertEqual("MainAbility1 onForeground"); + expect(result1[3]).assertEqual("MainAbility1 onBackground"); + + // mainability2将会在1.5秒后,终结自己 + await sleep(2000); + const result2 = globalThis.list2; + console.info(TAG + "result2: " + JSON.stringify(result2)); + + expect(result2[0]).assertEqual("MainAbility2 onCreate"); + expect(result2[1]).assertEqual("MainAbility2 onWindowStageCreate"); + expect(result2[2]).assertEqual("MainAbility2 onForeground"); + expect(result2[3]).assertEqual("MainAbility2 onBackground"); + expect(result2[4]).assertEqual("MainAbility2 onWindowStageDestroy"); + expect(result2[5]).assertEqual("MainAbility2 onDestroy"); + + // mainability1将会重新唤起 + await sleep(1000); + console.info(TAG + "result1: " + JSON.stringify(result1)); + expect(result1[2]).assertEqual("MainAbility1 onForeground"); + + await sleep(1000); + globalThis.ability1context.terminateSelf(); + await sleep(1500); + console.info(TAG + "result1: " + JSON.stringify(result1)); + expect(result1[5]).assertEqual("MainAbility1 onBackground"); + expect(result1[6]).assertEqual("MainAbility1 onWindowStageDestroy"); + expect(result1[7]).assertEqual("MainAbility1 onDestroy"); + done(); + }); + + /** + *@tc.number : UI_ABILITY_LIFE_CYCLE_TEST_0005 + *@tc.name : UI_Ability_Life_Cycle_Test_0005 + *@tc.desc : start mainability1, after 1seconds, start other app mainability. + *@tc.size : MediumTest + *@tc.type : Function + *@tc.level : Level 1 + */ + it("UI_Ability_Life_Cycle_Test_0005", 0, async (done) => { + console.log("------------UI_ABILITY_LIFE_CYCLE_TEST_0005 START-------------"); + TAG = "UI_ABILITY_LIFE_CYCLE_TEST_0005"; + + var want = { + bundleName: "com.example.uiabilitylifecycle", + abilityName: "MainAbility1", + moduleName: moduleName, + }; + globalThis.abilityContext + .startAbility(want) + .then((data) => { + console.info(TAG + " start successful. Data: " + data); + }) + .catch((error) => { + console.error(TAG + " start failed. Cause: " + JSON.stringify(error)); + }); + + await sleep(1000); + + const result1 = globalThis.list1; + console.info(TAG + "result1: " + JSON.stringify(result1)); + + expect(result1[0]).assertEqual("MainAbility1 onCreate"); + expect(result1[1]).assertEqual("MainAbility1 onWindowStageCreate"); + expect(result1[2]).assertEqual("MainAbility1 onForeground"); + + var want = { + bundleName: otherBundle, + abilityName: "MainAbility", + moduleName: "entry_test", + }; + let otherAppResult = 0; + globalThis.abilityContext + .startAbility(want) + .then((data) => { + console.info(TAG + " start successful. Data: " + data); + otherAppResult = 1; + }) + .catch((error) => { + console.error(TAG + " start failed. Cause: " + JSON.stringify(error)); + }); + + await sleep(2000); + expect(otherAppResult == 1).assertTrue(); + done(); + }); + + /** + *@tc.number : UI_ABILITY_LIFE_CYCLE_TEST_0006 + *@tc.name : UI_Ability_Life_Cycle_Test_0006 + *@tc.desc : start mainability3, after start mainability3 twice, mainability3 is a standard ability. + *@tc.size : MediumTest + *@tc.type : Function + *@tc.level : Level 1 + */ + it("UI_Ability_Life_Cycle_Test_0006", 0, async (done) => { + console.log("------------UI_ABILITY_LIFE_CYCLE_TEST_0006 START-------------"); + TAG = "UI_ABILITY_LIFE_CYCLE_TEST_0006"; + + var want = { + bundleName: "com.example.uiabilitylifecycle", + abilityName: "MainAbility3", + moduleName: moduleName, + }; + globalThis.abilityContext + .startAbility(want) + .then((data) => { + console.info(TAG + " start successful. Data: " + data); + }) + .catch((error) => { + console.error(TAG + " start failed. Cause: " + JSON.stringify(error)); + }); + + await sleep(1000); + + const result1 = globalThis.list3; + console.info(TAG + "result1: " + JSON.stringify(result1)); + + expect(result1[0]).assertEqual("MainAbility3 onCreate"); + expect(result1[1]).assertEqual("MainAbility3 onWindowStageCreate"); + expect(result1[2]).assertEqual("MainAbility3 onForeground"); + + globalThis.abilityContext + .startAbility(want) + .then((data) => { + console.info(TAG + " start successful. Data: " + data); + }) + .catch((error) => { + console.error(TAG + " start failed. Cause: " + JSON.stringify(error)); + }); + + await sleep(1000); + const result2 = globalThis.list3; + console.info(TAG + "result2: " + JSON.stringify(result2)); + expect(result2[0]).assertEqual("MainAbility3 onCreate"); + expect(result2[1]).assertEqual("MainAbility3 onWindowStageCreate"); + expect(result2[2]).assertEqual("MainAbility3 onForeground"); + + globalThis.ability3context.terminateSelf(); + await sleep(500); + done(); + }); + + /** + *@tc.number : UI_Ability_Constant_Test_0100 + *@tc.name : UI_Ability_Constant_Test_0100 + *@tc.desc : start mainability1, check ability constant. + *@tc.size : MediumTest + *@tc.type : Function + *@tc.level : Level 1 + */ + it("UI_Ability_Constant_Test_0100", 0, async (done) => { + console.log("------------UI_Ability_Constant_Test_0100 START-------------"); + TAG = "UI_Ability_Constant_Test_0100"; + + var want = { + bundleName: "com.example.uiabilitylifecycle", + abilityName: "MainAbility1", + moduleName: moduleName, + }; + globalThis.abilityContext + .startAbility(want) + .then((data) => { + console.info(TAG + " start successful. Data: " + data); + }) + .catch((error) => { + console.error(TAG + " start failed. Cause: " + JSON.stringify(error)); + }); + + await sleep(1000); + + console.log('UI_Ability_Constant_Test_0100:' + globalThis.launchParam1.lastExitReason) + expect(globalThis.launchParam1.launchReason == 1).assertTrue(); + expect(globalThis.launchParam1.lastExitReason == 2).assertTrue(); + expect(aConstant.LaunchReason.UNKNOWN == 0).assertTrue(); + expect(aConstant.LastExitReason.UNKNOWN == 0).assertTrue(); + done(); + }); + + }); +} diff --git a/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/src/main/module.json b/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..8ddfae21046ffc8e84f4976c525d58f6060d9bc4 --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/src/main/module.json @@ -0,0 +1,65 @@ +{ + "module": { + "name": "entry_test", + "type": "feature", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntry": "./ets/TestAbility/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "exported": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + }, + { + "name": "MainAbility1", + "srcEntry": "./ets/MainAbility1/MainAbility1.ts", + "description": "$string:MainAbility1_desc", + "icon": "$media:icon", + "launchType": "singleton", + "label": "$string:MainAbility1_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background" + }, + { + "name": "MainAbility2", + "srcEntry": "./ets/MainAbility2/MainAbility2.ts", + "description": "$string:MainAbility2_desc", + "icon": "$media:icon", + "label": "$string:MainAbility2_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background" + }, + { + "name": "MainAbility3", + "srcEntry": "./ets/MainAbility3/MainAbility3.ts", + "description": "$string:MainAbility2_desc", + "launchType": "standard", + "icon": "$media:icon", + "label": "$string:MainAbility2_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background" + } + ] + } +} diff --git a/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/src/main/resources/base/element/color.json b/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/src/main/resources/base/element/string.json b/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..03f1687c37c70755bf277a1d20642ed1ee9919eb --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/src/main/resources/base/element/string.json @@ -0,0 +1,172 @@ +{ + "string": [ + { + "name": "module_test_desc", + "value": "test ability description" + }, + { + "name": "TestAbility_desc", + "value": "the test ability" + }, + { + "name": "TestAbility_label", + "value": "test label" + }, + { + "name": "phone_entry_dsc", + "value": "i am an entry for phone" + }, + { + "name": "phone_entry_main", + "value": "the phone entry ability" + }, + { + "name": "entry_label", + "value": "ActsContextTest" + }, + { + "name": "form_description", + "value": "my form" + }, + { + "name": "serviceability_description", + "value": "my whether" + }, + { + "name": "description_application", + "value": "demo for test" + }, + { + "name": "entry_desc", + "value": "description" + }, + { + "name": "MainAbility_desc", + "value": "description" + }, + { + "name": "MainAbility_label", + "value": "label" + }, + { + "name": "MainAbility1_desc", + "value": "description" + }, + { + "name": "MainAbility1_label", + "value": "label" + }, + { + "name": "MainAbility2_desc", + "value": "description" + }, + { + "name": "MainAbility2_label", + "value": "label" + }, + { + "name": "MainAbility3_desc", + "value": "description" + }, + { + "name": "MainAbility3_label", + "value": "label" + }, + { + "name": "MainAbility4_desc", + "value": "description" + }, + { + "name": "MainAbility4_label", + "value": "label" + }, + { + "name": "MainAbility5_desc", + "value": "description" + }, + { + "name": "MainAbility5_label", + "value": "label" + }, + { + "name": "MainAbility6_desc", + "value": "description" + }, + { + "name": "MainAbility6_label", + "value": "label" + }, + { + "name": "MainAbility7_desc", + "value": "description" + }, + { + "name": "MainAbility7_label", + "value": "label" + }, + { + "name": "MainAbility8_desc", + "value": "description" + }, + { + "name": "MainAbility8_label", + "value": "label" + }, + { + "name": "MainAbility9_desc", + "value": "description" + }, + { + "name": "MainAbility9_label", + "value": "label" + }, + { + "name": "Hap1MainAbility1_desc", + "value": "description" + }, + { + "name": "Hap1MainAbility1_label", + "value": "label" + }, + { + "name": "Hap1MainAbility2_desc", + "value": "description" + }, + { + "name": "Hap1MainAbility2_label", + "value": "label" + }, + { + "name": "MainAbility10_desc", + "value": "description" + }, + { + "name": "MainAbility10_label", + "value": "label" + }, + { + "name": "MainAbility11_desc", + "value": "description" + }, + { + "name": "MainAbility11_label", + "value": "label" + }, + { + "name": "MainAbility12_desc", + "value": "description" + }, + { + "name": "MainAbility12_label", + "value": "label" + }, + { + "name": "MainAbility13_desc", + "value": "description" + }, + { + "name": "MainAbility13_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/src/main/resources/base/media/icon.png b/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/src/main/resources/base/media/icon.png differ diff --git a/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/src/main/resources/base/profile/test_pages.json b/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/src/main/resources/base/profile/test_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..54bc73eafa0ff4bae2a4963bd0dadb352bb9b806 --- /dev/null +++ b/ability/crossplatform/ability_runtime/ActsUiAbilityEtsTest/src/main/resources/base/profile/test_pages.json @@ -0,0 +1,7 @@ +{ + "src": [ + "TestAbility/pages/Index", + "TestAbility/pages/Index1", + "TestAbility/pages/Index2" + ] +} diff --git a/ability/crossplatform/ability_runtime/BUILD.gn b/ability/crossplatform/ability_runtime/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..483e8d4dc7c3f9b72474de662f6c63ce6fb67b1d --- /dev/null +++ b/ability/crossplatform/ability_runtime/BUILD.gn @@ -0,0 +1,26 @@ +# Copyright (c) 2023 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("//build/ohos_var.gni") + +group("ability_crossplatform_runtime") { + testonly = true + if (is_standard_system) { + deps = [ + "ActsLifeCycleEtsFeatureTest:ActsLifeCycleEtsFeatureTest", + "ActsLifeCycleEtsTest:ActsLifeCycleEtsTest", + "ActsUiAbilityEtsTest:ActsUiAbilityEtsTest", + "commonTestAbilityApp:commonTestAbilityApp", + ] + } +} diff --git a/ability/crossplatform/ability_runtime/commonTestAbilityApp/AppScope/app.json b/ability/crossplatform/ability_runtime/commonTestAbilityApp/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..bb186ea2e07f665dccd598bcd37a814626b5a2bb --- /dev/null +++ b/ability/crossplatform/ability_runtime/commonTestAbilityApp/AppScope/app.json @@ -0,0 +1,16 @@ +{ + "app": { + "bundleName": "com.example.commontestabilityapp", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name", + "minAPIVersion": 9, + "targetAPIVersion": 9, + "car": { + "apiCompatibleVersion": 9, + "singleUser": false + } + } +} diff --git a/ability/crossplatform/ability_runtime/commonTestAbilityApp/AppScope/resources/base/element/string.json b/ability/crossplatform/ability_runtime/commonTestAbilityApp/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..3811bc441fc0f128eb4d14c53ed463ffb8dc3811 --- /dev/null +++ b/ability/crossplatform/ability_runtime/commonTestAbilityApp/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "xtsDemo1" + } + ] +} diff --git a/ability/crossplatform/ability_runtime/commonTestAbilityApp/AppScope/resources/base/media/app_icon.png b/ability/crossplatform/ability_runtime/commonTestAbilityApp/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ability/crossplatform/ability_runtime/commonTestAbilityApp/AppScope/resources/base/media/app_icon.png differ diff --git a/ability/crossplatform/ability_runtime/commonTestAbilityApp/BUILD.gn b/ability/crossplatform/ability_runtime/commonTestAbilityApp/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..1c54e6efaaffea9d9c0e64ec9bfb836866cbaf56 --- /dev/null +++ b/ability/crossplatform/ability_runtime/commonTestAbilityApp/BUILD.gn @@ -0,0 +1,40 @@ +# Copyright (c) 2023 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_hap_assist_suite("commonTestAbilityApp") { + hap_profile = "src/main/module.json" + deps = [ + ":windowStage_js_assets", + ":windowStage_resources", + ] + ets2abc = true + certificate_profile = "./signature/openharmony_sx.p7b" + + hap_name = "commonTestAbilityApp" + subsystem_name = "ability" + part_name = "ability_runtime" +} +ohos_app_scope("windowStage_app_profile") { + app_profile = "AppScope/app.json" + sources = [ "AppScope/resources" ] +} +ohos_js_assets("windowStage_js_assets") { + source_dir = "src/main/ets" +} +ohos_resources("windowStage_resources") { + sources = [ "src/main/resources" ] + deps = [ ":windowStage_app_profile" ] + hap_profile = "src/main/module.json" +} diff --git a/ability/crossplatform/ability_runtime/commonTestAbilityApp/Test.json b/ability/crossplatform/ability_runtime/commonTestAbilityApp/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..257a1d29839ec6095be58300b0b91ef98d513ef3 --- /dev/null +++ b/ability/crossplatform/ability_runtime/commonTestAbilityApp/Test.json @@ -0,0 +1,19 @@ +{ + "description": "Configuration for hjunit demo Tests", + "driver": { + "type": "OHJSUnitTest", + "test-timeout": "60000", + "shell-timeout": "60000", + "bundle-name": "com.example.commontestabilityapp", + "module-name": "entry_test" + }, + "kits": [ + { + "test-file-name": [ + "commonTestAbilityApp.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/commonTestAbilityApp/signature/openharmony_sx.p7b b/ability/crossplatform/ability_runtime/commonTestAbilityApp/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..ee3d9b2b21230b31570aa1e706f1677f7dfcb368 Binary files /dev/null and b/ability/crossplatform/ability_runtime/commonTestAbilityApp/signature/openharmony_sx.p7b differ diff --git a/ability/crossplatform/ability_runtime/commonTestAbilityApp/src/main/ets/Application/AbilityStage.ts b/ability/crossplatform/ability_runtime/commonTestAbilityApp/src/main/ets/Application/AbilityStage.ts new file mode 100644 index 0000000000000000000000000000000000000000..5f781eef66760e9268ec99f02a6d758a49983cfc --- /dev/null +++ b/ability/crossplatform/ability_runtime/commonTestAbilityApp/src/main/ets/Application/AbilityStage.ts @@ -0,0 +1,7 @@ +import AbilityStage from '@ohos.app.ability.AbilityStage'; + +export default class MyAbilityStage extends AbilityStage { + onCreate() { + console.log("[Demo] MyAbilityStage onCreate") + } +} \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/commonTestAbilityApp/src/main/ets/mainability/MainAbility.ets b/ability/crossplatform/ability_runtime/commonTestAbilityApp/src/main/ets/mainability/MainAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..a3449a6d158a1c7db6aee28b4d5b1adb880faafe --- /dev/null +++ b/ability/crossplatform/ability_runtime/commonTestAbilityApp/src/main/ets/mainability/MainAbility.ets @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2023 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 UIAbility from '@ohos.app.ability.UIAbility'; +import window from '@ohos.window'; + +export default class MainAbility extends UIAbility { + onCreate(want, launchParam) { + globalThis.commonList1 = []; + console.log('testTag', '%{public}s', 'Ability onCreate'); + globalThis.commonList1.push('common MainAbility onCreate'); + } + + onDestroy() { + console.log('testTag', '%{public}s', 'Ability onDestroy'); + globalThis.commonList1.push('common MainAbility onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + // Main window is created, set main page for this ability + console.log('testTag', '%{public}s', 'Ability onWindowStageCreate'); + globalThis.commonList1.push('common MainAbility onWindowStageCreate'); + globalThis.commonAbilityContext = this.context; + + windowStage.loadContent('pages/Index', (err, data) => { + if (err.code) { + console.log('testTag', '%{public}s', 'Ability onWindowStageCreate'); + return; + } + console.log('testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + console.log('testTag', '%{public}s', 'Ability onWindowStageDestroy'); + globalThis.commonList1.push('common MainAbility onWindowStageDestroy'); + } + + onForeground() { + // Ability has brought to foreground + console.log('testTag', '%{public}s', 'Ability onForeground'); + globalThis.commonList1.push('common MainAbility onForeground'); + setTimeout(function () { + console.log("[Demo] MainAbility onForeground after 1500ms") + globalThis.commonAbilityContext.terminateSelf() + .then((data) => { + console.info('[Demo] MainAbility terminateself succeeded: ' + data); + }).catch((error) => { + console.error('[Demo] MainAbility terminateself failed. Cause: ' + error); + }) + }, 1500); + } + + onBackground() { + // Ability has back to background + console.log('testTag', '%{public}s', 'Ability onBackground'); + globalThis.commonList1.push('common MainAbility onBackground'); + } +} diff --git a/ability/crossplatform/ability_runtime/commonTestAbilityApp/src/main/ets/mainability/pages/Index.ets b/ability/crossplatform/ability_runtime/commonTestAbilityApp/src/main/ets/mainability/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..891ff5436743d7cb73a3c8dbb446280c8647dc65 --- /dev/null +++ b/ability/crossplatform/ability_runtime/commonTestAbilityApp/src/main/ets/mainability/pages/Index.ets @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2023 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 hilog from '@ohos.hilog'; + +@Entry +@Component +struct Index { + aboutToAppear() { + hilog.info(0x0000, 'testTag', '%{public}s', 'MainAbility index aboutToAppear'); + } + @State message: string = 'Hello World' + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .width('35%') + .height('5%') + .onClick(()=>{ + }) + } + .width('100%') + } + .height('100%') + } + } \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/commonTestAbilityApp/src/main/module.json b/ability/crossplatform/ability_runtime/commonTestAbilityApp/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..d2ae7a6077544af2b4e66954c7d905566ed6c00a --- /dev/null +++ b/ability/crossplatform/ability_runtime/commonTestAbilityApp/src/main/module.json @@ -0,0 +1,37 @@ +{ + "module": { + "name": "entry_test", + "type": "feature", + "description": "$string:module_test_desc", + "srcEntry": "./ets/Application/AbilityStage.ts", + "mainElement": "MainAbility", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "MainAbility", + "srcEntry": "./ets/mainability/MainAbility.ets", + "description": "$string:MainAbility_desc", + "icon": "$media:icon", + "label": "$string:MainAbility_label", + "exported": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/ability/crossplatform/ability_runtime/commonTestAbilityApp/src/main/resources/base/element/color.json b/ability/crossplatform/ability_runtime/commonTestAbilityApp/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ability/crossplatform/ability_runtime/commonTestAbilityApp/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/commonTestAbilityApp/src/main/resources/base/element/string.json b/ability/crossplatform/ability_runtime/commonTestAbilityApp/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..1f973e16265333ac77a3b7cdbea1a5a72f456ce2 --- /dev/null +++ b/ability/crossplatform/ability_runtime/commonTestAbilityApp/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_test_desc", + "value": "test ability description" + }, + { + "name": "MainAbility_desc", + "value": "the main ability" + }, + { + "name": "MainAbility_label", + "value": "main label" + } + ] +} \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/commonTestAbilityApp/src/main/resources/base/media/icon.png b/ability/crossplatform/ability_runtime/commonTestAbilityApp/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ability/crossplatform/ability_runtime/commonTestAbilityApp/src/main/resources/base/media/icon.png differ diff --git a/ability/crossplatform/ability_runtime/commonTestAbilityApp/src/main/resources/base/profile/test_pages.json b/ability/crossplatform/ability_runtime/commonTestAbilityApp/src/main/resources/base/profile/test_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..2870480434df2f95a947b51106e322389fa5eda3 --- /dev/null +++ b/ability/crossplatform/ability_runtime/commonTestAbilityApp/src/main/resources/base/profile/test_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "mainability/pages/Index" + ] +}