diff --git a/ability/ability_runtime/BUILD.gn b/ability/ability_runtime/BUILD.gn index d03507b9b177323a24ecb7e9d7d79850f4ab99e2..0529f18562da315ef11bf2dc03f158c0906be91a 100644 --- a/ability/ability_runtime/BUILD.gn +++ b/ability/ability_runtime/BUILD.gn @@ -25,6 +25,7 @@ group("ability_runtime") { "actsabilitydelegatorcase:ActsAbilityDelegatorCaseTest", "actsabilitymanageretstest:ActsAbilityManagerEtsTest", "actsabilityusertest:ActsAbilityuserTest", + "actsactionextensionability:actsactionextensionability", "actscalldataabilitytest:ActsCallDataAbilityTest", "actscalltest:actscalltest", "actscrosscall:actscrosscall", diff --git a/ability/ability_runtime/actsactionextensionability/BUILD.gn b/ability/ability_runtime/actsactionextensionability/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..762a3075ddce2a6b6ca8e3ed9265f3441a52d7b9 --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/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("//test/xts/tools/build/suite.gni") + +group("actsactionextensionability") { + testonly = true + if (is_standard_system) { + deps = [ + "actsactionextensionabilityotherrely:ActsActionExtensionAbilityOtherRely", + "actsactionextensionabilityself:ActsActionExtensionAbilitySelfRely", + "actsactionextensionabilityself:ActsActionExtensionAbilitySelfModule", + "actsactionextensionabilitytest:ActsActionExtensionAbilityTest", + ] + } +} \ No newline at end of file diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/AppScope/app.json b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..1b1ec18b9a2794ff0f36eded760300eba4712bf2 --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/AppScope/app.json @@ -0,0 +1,19 @@ +{ + "app": { + "bundleName": "com.example.actsactionextensionabilityrely", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name", + "distributedNotificationEnabled": true, + "keepAlive" : true, + "singleUser": true, + "minAPIVersion": 10, + "targetAPIVersion": 10, + "car": { + "apiCompatibleVersion": 10, + "singleUser": false + } + } +} diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/AppScope/resources/base/element/string.json b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..d71e5ead1ce20b4ac3384d18e6d104f1ea4d83b4 --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "MyApplication" + } + ] +} diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/AppScope/resources/base/media/app_icon.png b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/AppScope/resources/base/media/app_icon.png differ diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/BUILD.gn b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..4f8e383391764629bca89da7900d2342fe0ec8f6 --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/BUILD.gn @@ -0,0 +1,43 @@ +# 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("ActsActionExtensionAbilityOtherRely") { + hap_profile = "entry/src/main/module.json" + js_build_mode = "debug" + deps = [ + ":actsactionextensionabilityotherrely_js_assets", + ":actsactionextensionabilityotherrely_resources", + ] + ets2abc = true + certificate_profile = "signature/openharmony_sx.p7b" + hap_name = "ActsActionExtensionAbilityOtherRely" + subsystem_name = "ability" + part_name = "ability_runtime" +} + +ohos_app_scope("actsactionextensionabilityotherrely_app_profile") { + app_profile = "AppScope/app.json" + sources = [ "AppScope/resources" ] +} + +ohos_js_assets("actsactionextensionabilityotherrely_js_assets") { + source_dir = "entry/src/main/ets" +} + +ohos_resources("actsactionextensionabilityotherrely_resources") { + sources = [ "entry/src/main/resources" ] + deps = [ ":actsactionextensionabilityotherrely_app_profile" ] + hap_profile = "entry/src/main/module.json" +} diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/entry/src/main/ets/UIExtensionAbility/UIExtAbility.ts b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/entry/src/main/ets/UIExtensionAbility/UIExtAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..6ea098872555f01decc864a8502fb0f19c055d1c --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/entry/src/main/ets/UIExtensionAbility/UIExtAbility.ts @@ -0,0 +1,47 @@ +/* + * 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 ActionExtensionAbility from '@ohos.app.ability.ActionExtensionAbility'; +import wantConstant from '@ohos.app.ability.wantConstant'; +import commonEvent from '@ohos.commonEventManager'; +import hilog from '@ohos.hilog'; + +export default class UiExtAbility extends ActionExtensionAbility { + onCreate() { + hilog.info(0x0000, 'testTag', 'UIExtAbility onCreate want: %{public}s'); + console.info('=======>UIExtAbility onCreate======>'); + } + + onSessionCreate(want, session) { + console.log(`want: ${JSON.stringify(want)}}`); + var storage: LocalStorage = new LocalStorage({ + 'session': session + }); + session.loadContent('pages/Page', storage); + console.info('=======>UIExtAbility onSessionCreate======>'); + } + + onSessionDestroy(session) { + console.log('onSessionDestroy'); + } + + onDestroy() { + console.info('=======>UIExtensionAbility onDestroy ======>'); + } + + onForeground() { + // Ability has brought to foreground + console.log('=====> UIExtAbility onForeground =====> '); + } +}; diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/entry/src/main/ets/actionextensionability/ActsActionExtensionAbility.ts b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/entry/src/main/ets/actionextensionability/ActsActionExtensionAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..8aa8a6d982cb97a5c556141645c1330f585adc09 --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/entry/src/main/ets/actionextensionability/ActsActionExtensionAbility.ts @@ -0,0 +1,76 @@ +/* + * 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 ActionExtensionAbility from '@ohos.app.ability.ActionExtensionAbility'; +import commonEventManager from '@ohos.commonEventManager'; + +var count = 0; +const TIME_OUT = 500; +export default class ActsActionExtensionAbility extends ActionExtensionAbility { + storage: LocalStorage; + message: string; + onCreate() { + console.log('====>ActsActionExtensionAbility onCreate called'); + count++; + } + + onForeground() { + console.log('====>ActsActionExtensionAbility onForeground called'); + count++; + var options = { + parameters: { + 'count': count + } + } + commonEventManager.publish('ACTS_TEST_FOREGROUND', options, function (){}); + } + + onBackground() { + console.log('====>ActsActionExtensionAbility onBackground called'); + count++; + commonEventManager.publish('ACTS_TEST_BACKGROUND', function (){}); + setTimeout(() => { + globalThis.session.terminateSelf(); + }, TIME_OUT); + } + + onSessionCreate(want, session) { + console.log('====>ActsActionExtensionAbility onSessionCreate called'); + count++; + this.message = want.parameters.shareMessages; + this.storage = new LocalStorage( + { + 'session': session, + 'messages': this.message + }); + session.loadContent('pages/PageThree', this.storage); + globalThis.session = session; + } + + onDestroy() { + console.log('====>ActsActionExtensionAbility onDestroy called'); + count++; + var options = { + parameters: { + 'count': count + } + } + commonEventManager.publish('ACTS_TEST_DESTROY', options, function (){}); + } + + onSessionDestroy(session) { + console.log('====>ActsActionExtensionAbility onSessionDestroy called'); + count++; + } +} diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/entry/src/main/ets/calledability/CalledAbility.ts b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/entry/src/main/ets/calledability/CalledAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..e3749435fb75da9c3d1997af0a4a07d3d559891b --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/entry/src/main/ets/calledability/CalledAbility.ts @@ -0,0 +1,70 @@ +/* + * 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 hilog from '@ohos.hilog'; +import type window from '@ohos.window'; + +export default class CalledAbility extends UIAbility { + onCreate(want, launchParam) { + hilog.info(0x0000, 'testTag', '%{public}s', 'CalledAbility onCreate'); + + console.log('=====> second app CalledAbility bas been created =====>'); + + if (want.action === 'AsyncCallback_0200') { + this.context.terminateSelfWithResult({ + resultCode: 0, + want: { + parameters: { + action: 'ACTION' + } + } + }, (err) => { + console.log('=====> AsyncCallback_0200 CalledAbilityCallBack terminateSelfWithResult =====>' + err.code); + }); + } + } + + onDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'CalledAbility onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/PageTwo', (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() { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'CalledAbility onWindowStageDestroy'); + } + + onForeground() { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'CalledAbility onForeground'); + } + + onBackground() { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'CalledAbility onBackground'); + } +} diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/entry/src/main/ets/entryability/EntryAbility.ts b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/entry/src/main/ets/entryability/EntryAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..4ddabe2dcce37d164715f0fcbc7e5ebab6f2ac0d --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/entry/src/main/ets/entryability/EntryAbility.ts @@ -0,0 +1,110 @@ +/* + * 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 hilog from '@ohos.hilog'; +import window from '@ohos.window'; + +export default class EntryAbility extends UIAbility { + onCreate(want, launchParam) { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + console.info('====>another EntryAbility'); + + if (want.action === 'ActionExtensionAbility_0100') { + this.context.startAbility({ + bundleName: 'com.example.actsactionextensionabilityrely', + abilityName: 'ActsActionExtensionAbility', + parameters: { + 'ability.want.params.uiExtensionType': 'action' + } + }).catch((err)=>{ + console.info('====>ActionExtensionAbility_0100 err:'+ JSON.stringify(err)); + }) + } + + if (want.action === 'AsyncCallback_0200') { + console.info("====>EntryAbility want.action == 'AsyncCallback_0200':"); + AppStorage.SetOrCreate('want', { + action: 'AsyncCallback_0200', + bundleName: 'com.example.actsactionextensionabilityrely', + abilityName: 'UIExtAbility', + parameters: { + 'ability.want.params.uiExtensionType': 'action' + } + }); + } + + if (want.action === 'AsyncCallback_0300') { + console.info("====>EntryAbility want.action == 'AsyncCallback_0300':"); + AppStorage.SetOrCreate('want', { + action: 'AsyncCallback_0300', + bundleName: 'com.example.actsactionextensionabilityrely', + abilityName: 'UIExtAbility', + parameters: { + 'ability.want.params.uiExtensionType': 'action' + } + }); + } + + if (want.action === 'Promise_0200') { + console.info("====>EntryAbility want.action == 'Promise_0200':"); + AppStorage.SetOrCreate('want', { + action: 'Promise_0200', + bundleName: 'com.example.actsactionextensionabilityrely', + abilityName: 'UIExtAbility', + parameters: { + 'ability.want.params.uiExtensionType': 'action' + } + }); + } + if (want.action === 'Promise_0300') { + console.info("====>EntryAbility want.action == 'Promise_0300':"); + AppStorage.SetOrCreate('want', { + action: 'Promise_0300', + bundleName: 'com.example.actsactionextensionabilityrely', + abilityName: 'UIExtAbility', + parameters: { + 'ability.want.params.uiExtensionType': 'action' + } + }); + } + } + + onDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('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() { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onBackground() { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/entry/src/main/ets/pages/Index.ets b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..94dc20c72c65cf9be57a0be469151b5e9706476b --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,44 @@ +/* + * 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 Want from '@ohos.app.ability.Want'; + +@Entry +@Component +struct Index { + @State message: string = 'Second application' + @StorageLink('want') want: Want = { + action: "AsyncCallback_0200", + bundleName: 'com.example.actsactionextensionabilityrely', + abilityName: 'UIExtAbility', + parameters: { + 'ability.want.params.uiExtensionType': 'action' + } + } + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + UIExtensionComponent(this.want) + .size({width:'100%',height:'100'}) + .backgroundColor(Color.Blue) + .border({width:5,color:Color.Red}) + } + .width('100%') + } + .height('100%') + } +} \ No newline at end of file diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/entry/src/main/ets/pages/Page.ets b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/entry/src/main/ets/pages/Page.ets new file mode 100644 index 0000000000000000000000000000000000000000..30c9b5a2f7e75b03173a384e337ad60c0b80cb7e --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/entry/src/main/ets/pages/Page.ets @@ -0,0 +1,34 @@ +/* + * 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. + */ + +var storage = LocalStorage.GetShared() + +@Entry(storage) +@Component +struct Page { + @State message: string = 'UIExtAbility' + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .fontWeight(FontWeight.Bold) + } + .width('100%') + } + .height('100%') + } +} \ No newline at end of file diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/entry/src/main/ets/pages/PageThree.ets b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/entry/src/main/ets/pages/PageThree.ets new file mode 100644 index 0000000000000000000000000000000000000000..ac2520e897db322879878f3f837456a6845ac1ab --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/entry/src/main/ets/pages/PageThree.ets @@ -0,0 +1,35 @@ +/* + * 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. + */ + +var storage = LocalStorage.GetShared(); + +@Entry(storage) +@Component +struct PageThree { + + build() { + Row() { + Column() { + Text('acton') + .fontSize(24) + .fontWeight(FontWeight.Bold) + } + .width('100%') + } + .height('100%') + .backgroundColor('#e0ffff') + .borderRadius(16) + } +} \ No newline at end of file diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/entry/src/main/ets/pages/PageTwo.ets b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/entry/src/main/ets/pages/PageTwo.ets new file mode 100644 index 0000000000000000000000000000000000000000..5bb697ee1221ff320034b8001f4a5ad6577f881d --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/entry/src/main/ets/pages/PageTwo.ets @@ -0,0 +1,31 @@ +/* + * 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 PageTwo { + @State message: string = 'Second application' + + 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/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/entry/src/main/module.json b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/entry/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..df6a7eaf9f44160ec126c18b5bb83ee620012c50 --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/entry/src/main/module.json @@ -0,0 +1,73 @@ +{ + "module": { + "name": "entry_assist", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ts", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + }, + { + "name": "CalledAbility", + "srcEntry": "./ets/calledability/CalledAbility.ts", + "description": "$string:CalledAbility_desc", + "visible": true, + "icon": "$media:icon", + "label": "$string:CalledAbility_label", + "launchType": "standard", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background" + } + ], + "extensionAbilities": [ + { + "name": "UIExtAbility", + "icon": "$media:icon", + "description": "UIExtAbility", + "type": "action", + "visible": true, + "srcEntrance": "./ets/UIExtensionAbility/UIExtAbility.ts" + }, + { + "name": "ActsActionExtensionAbility", + "icon": "$media:icon", + "description": "ActsActionExtensionAbility", + "type": "action", + "visible": true, + "srcEntrance": "./ets/actionextensionability/ActsActionExtensionAbility.ts" + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.START_ABILITIES_FROM_BACKGROUND" + }, + { + "name": "ohos.permission.START_INVISIBLE_ABILITY" + } + ] + } +} \ No newline at end of file diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/entry/src/main/resources/base/element/color.json b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33 --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/entry/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/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/entry/src/main/resources/base/element/string.json b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..3b2c2fd7e60fabd14e9df8409557306c4149dbae --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/entry/src/main/resources/base/element/string.json @@ -0,0 +1,24 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + }, + { + "name": "CalledAbility_desc", + "value": "description" + }, + { + "name": "CalledAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/entry/src/main/resources/base/media/icon.png b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/entry/src/main/resources/base/media/icon.png differ diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/entry/src/main/resources/base/profile/main_pages.json b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..89988b33b16b497e845f11a9dc191b779637c269 --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,6 @@ +{ + "src": [ + "pages/Index", + "pages/PageThree" + ] +} diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/entry/src/main/resources/en_US/element/string.json b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..3b2c2fd7e60fabd14e9df8409557306c4149dbae --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/entry/src/main/resources/en_US/element/string.json @@ -0,0 +1,24 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + }, + { + "name": "CalledAbility_desc", + "value": "description" + }, + { + "name": "CalledAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/entry/src/main/resources/zh_CN/element/string.json b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..73838f7ea8aee9962adb53d5a9b39528744719e7 --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/entry/src/main/resources/zh_CN/element/string.json @@ -0,0 +1,24 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "模块描述" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + }, + { + "name": "CalledAbility_desc", + "value": "description" + }, + { + "name": "CalledAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/signature/openharmony_sx.p7b b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..18ad78cd25e345508fe9ee47538372a711e9a9bd Binary files /dev/null and b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityotherrely/signature/openharmony_sx.p7b differ diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/AppScope/app.json b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..abf2fd00b542cf0bb6edf44ca16d802867fef7b6 --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/AppScope/app.json @@ -0,0 +1,19 @@ +{ + "app": { + "bundleName": "com.example.actsactionextensionabilitytest", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name", + "distributedNotificationEnabled": true, + "keepAlive" : true, + "singleUser": true, + "minAPIVersion": 10, + "targetAPIVersion": 10, + "car": { + "apiCompatibleVersion": 10, + "singleUser": false + } + } +} diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/AppScope/resources/base/element/string.json b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..d71e5ead1ce20b4ac3384d18e6d104f1ea4d83b4 --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "MyApplication" + } + ] +} diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/AppScope/resources/base/media/app_icon.png b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/AppScope/resources/base/media/app_icon.png differ diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/BUILD.gn b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..bfc9757942fd319f6ca95ad714abf7752e9e39a9 --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/BUILD.gn @@ -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("//test/xts/tools/build/suite.gni") + +ohos_hap_assist_suite("ActsActionExtensionAbilitySelfRely") { + hap_profile = "entry/src/main/module.json" + js_build_mode = "debug" + deps = [ + ":actsactionextensionabilityselfrely_js_assets", + ":actsactionextensionabilityselfrely_resources", + ] + ets2abc = true + certificate_profile = "signature/openharmony_sx.p7b" + hap_name = "ActsActionExtensionAbilitySelfRely" + subsystem_name = "ability" + part_name = "ability_runtime" +} + +ohos_app_scope("actsactionextensionabilityselfrely_app_profile") { + app_profile = "AppScope/app.json" + sources = [ "AppScope/resources" ] +} + +ohos_js_assets("actsactionextensionabilityselfrely_js_assets") { + source_dir = "entry/src/main/ets" +} + +ohos_resources("actsactionextensionabilityselfrely_resources") { + sources = [ "entry/src/main/resources" ] + deps = [ ":actsactionextensionabilityselfrely_app_profile" ] + hap_profile = "entry/src/main/module.json" +} + +ohos_hap_assist_suite("ActsActionExtensionAbilitySelfModule") { + hap_profile = "feature/src/main/module.json" + js_build_mode = "debug" + deps = [ + ":actsactionextensionabilityselfmodule_js_assets", + ":actsactionextensionabilityselfmodule_resources", + ] + ets2abc = true + certificate_profile = "signature/openharmony_sx.p7b" + hap_name = "ActsActionExtensionAbilitySelfModule" + subsystem_name = "ability" + part_name = "ability_runtime" +} + +ohos_app_scope("actsactionextensionabilityselfmodule_app_profile") { + app_profile = "AppScope/app.json" + sources = [ "AppScope/resources" ] +} + +ohos_js_assets("actsactionextensionabilityselfmodule_js_assets") { + source_dir = "feature/src/main/ets" +} + +ohos_resources("actsactionextensionabilityselfmodule_resources") { + sources = [ "feature/src/main/resources" ] + deps = [ ":actsactionextensionabilityselfmodule_app_profile" ] + hap_profile = "feature/src/main/module.json" +} diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/src/main/ets/UIExtensionAbility/UIExtAbility.ts b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/src/main/ets/UIExtensionAbility/UIExtAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..193cd8e8ab0ed04423495135839843cccd46a580 --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/src/main/ets/UIExtensionAbility/UIExtAbility.ts @@ -0,0 +1,428 @@ +/* + * 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 ActionExtensionAbility from '@ohos.app.ability.ActionExtensionAbility'; +import wantConstant from '@ohos.app.ability.wantConstant'; +import commonEvent from '@ohos.commonEventManager'; +import hilog from '@ohos.hilog'; + +export default class UiExtAbility extends ActionExtensionAbility { + onCreate() { + hilog.info(0x0000, 'testTag', 'UIExtAbility onCreate want: %{public}s'); + console.info('=======>UIExtAbility onCreate======>'); + } + + onSessionCreate(want, session) { + console.log(`want: ${JSON.stringify(want)}}`); + var storage: LocalStorage = new LocalStorage({ + 'session': session + }); + session.loadContent('pages/Page', storage); + console.info('=======>UIExtAbility onSessionCreate======>'); + + if (want.action === 'Acts_ActionExtensionAbility_1000') { + console.info('=======>UIExtAbility onSessionCreate want.action == Acts_ActionExtensionAbility_1000======>'); + this.context.startAbility({ + action: 'Acts_ActionExtensionAbility_1000', + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'CalledAbility', + parameters: { + [wantConstant.Params.ABILITY_BACK_TO_OTHER_MISSION_STACK]: true + } + }, (error) => { + console.info('=======>Acts_ActionExtensionAbility_1000 error.code ======>' + error.code); + var commonEventData = { + parameters: { + num: error.code + } + }; + commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => { + console.debug('====>Acts_ActionExtensionAbility_1000 publish err:' + JSON.stringify(err)); + }); + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_1100') { + console.info('=======>UIExtAbility onSessionCreate want.action == Acts_ActionExtensionAbility_1100======>'); + this.context.startAbility({ + action: 'Acts_ActionExtensionAbility_1100', + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'CalledAbility', + parameters: { + [wantConstant.Params.ABILITY_BACK_TO_OTHER_MISSION_STACK]: true + } + }).then(() => { + console.info('=======>Acts_ActionExtensionAbility_1100 UIExtAbility startAbility success ======>'); + var commonEventData = { + parameters: { + str: 'success' + } + }; + commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => { + console.debug('====>Acts_ActionExtensionAbility_1100 publish err:' + JSON.stringify(err)); + }); + }).catch((err) => { + console.debug('====>Acts_ActionExtensionAbility_1100 UIExtAbility startAbility err:' + JSON.stringify(err)); + }) + } + + if (want.action === 'Acts_ActionExtensionAbility_1200') { + console.info('=======>UIExtAbility onSessionCreate want.action == Acts_ActionExtensionAbility_1200======>'); + this.context.startAbility({ + action: 'Acts_ActionExtensionAbility_1200', + bundleName: 'xxx.xxxx.xxxxx', + abilityName: 'CalledAbility', + parameters: { + [wantConstant.Params.ABILITY_BACK_TO_OTHER_MISSION_STACK]: true + } + }, (error) => { + console.info('=======>Acts_ActionExtensionAbility_1200 error.code ======>' + error.code); + var commonEventData = { + parameters: { + num: error.code + } + }; + commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => { + console.debug('====>Acts_ActionExtensionAbility_1200 publish err:' + JSON.stringify(err)); + }); + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_1300') { + console.info('=======>UIExtAbility onSessionCreate want.action == Acts_ActionExtensionAbility_1300======>'); + this.context.startAbilityForResult({ + action: 'Acts_ActionExtensionAbility_1300', + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'CalledAbility', + parameters: { + [wantConstant.Params.ABILITY_BACK_TO_OTHER_MISSION_STACK]: true + } + }, (error, data) => { + console.info('=======>Acts_ActionExtensionAbility_1300 error.code ======>' + error.code); + console.info('=======>Acts_ActionExtensionAbility_1300 data.resultCode ======>' + data.resultCode); + console.info('=======>Acts_ActionExtensionAbility_1300 data.action ======>' + data.want.parameters.action); + var commonEventData = { + parameters: { + num: error.code, + str: data.want.parameters.action, + result: data.resultCode + } + }; + commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => { + console.debug('====>Acts_ActionExtensionAbility_1300 publish err:' + JSON.stringify(err)); + }); + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_1400') { + console.info('=======>UIExtAbility onSessionCreate want.action == Acts_ActionExtensionAbility_1300======>'); + this.context.startAbilityForResult({ + action: 'Acts_ActionExtensionAbility_1400', + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'CalledAbility', + parameters: { + [wantConstant.Params.ABILITY_BACK_TO_OTHER_MISSION_STACK]: true + } + }).then((data) => { + console.info('=======>Acts_ActionExtensionAbility_1400 data.resultCode ======>' + data.resultCode); + console.info('=======>Acts_ActionExtensionAbility_1400 data.action ======>' + data.want.parameters.action); + var commonEventData = { + parameters: { + str: data.want.parameters.action, + result: data.resultCode + } + }; + commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => { + console.debug('====>Acts_ActionExtensionAbility_1400 publish err:' + JSON.stringify(err)); + }); + }).catch((error) => { + console.info('=======>Acts_ActionExtensionAbility_1400 error.code ======>' + error.code); + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_1500') { + console.info('=======>UIExtAbility onSessionCreate want.action == Acts_ActionExtensionAbility_1500======>'); + this.context.startAbilityForResult({ + action: 'Acts_ActionExtensionAbility_1500', + bundleName: 'xxx.xxxxxxx.xxx', + abilityName: 'CalledAbility', + parameters: { + [wantConstant.Params.ABILITY_BACK_TO_OTHER_MISSION_STACK]: true + } + }, (error, data) => { + console.info('=======>Acts_ActionExtensionAbility_1500 first from own error.code ======>' + error.code); + var commonEventData = { + parameters: { + num: error.code + } + }; + commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => { + console.debug('====>Acts_ActionExtensionAbility_1500 first publish err:' + JSON.stringify(err)); + }); + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_1600') { + session.setReceiveDataCallback((data) => { + let options = { + parameters: { + 'result': data + } + } + commonEvent.publish('setReceiveDataCallback', options, (err) => { + console.log('Acts_ActionExtensionAbility_1600'); + }); + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_1800') { + console.info('=======>UIExtAbility onSessionCreate want.action == Acts_ActionExtensionAbility_1800======>'); + this.context.startAbility({ + action: 'Acts_ActionExtensionAbility_1800', + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'ActsActionExtensionAbility' + }, (error, data) => { + console.info('=======>Acts_ActionExtensionAbility_1800 first from own error.code ======>' + error.code); + var commonEventData = { + parameters: { + num: error.code + } + }; + commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => { + console.debug('====>Acts_ActionExtensionAbility_1800 first publish err:' + JSON.stringify(err)); + }); + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_context') { + let options = { + parameters: { + 'context': this.context + } + } + commonEvent.publish('ACTS_TEST_CONTEXT', options, (err) => { + console.log('Acts_ActionExtensionAbility_context'); + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_2200') { + console.info('=======>UIExtAbility onSessionCreate want.action == Acts_ActionExtensionAbility_2200======>'); + console.info('Acts_ActionExtensionAbility_2200 resourceManager: ' + this.context.resourceManager); + let commonEventData = { + parameters: { + resourceManager: this.context.resourceManager + } + }; + commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => { + console.debug('====>Acts_ActionExtensionAbility_2200 first publish err:' + JSON.stringify(err)); + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_2300') { + console.info('=======>UIExtAbility onSessionCreate want.action == Acts_ActionExtensionAbility_2300======>'); + console.info('Acts_ActionExtensionAbility_2300 applicationInfo: ' + this.context.applicationInfo); + let applicationInfo = this.context.applicationInfo; + + let commonEventData = { + parameters: { + name: applicationInfo.name, + description_length: applicationInfo.description.length, + descriptionId: applicationInfo.descriptionId, + label: applicationInfo.label, + labelId: applicationInfo.labelId, + icon: applicationInfo.icon, + iconId: applicationInfo.iconId, + codePath: typeof (applicationInfo.codePath) + } + }; + commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => { + console.debug('====>Acts_ActionExtensionAbility_2300 first publish err:' + JSON.stringify(err)); + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_2400') { + console.info('=======>UIExtAbility onSessionCreate want.action == Acts_ActionExtensionAbility_2400======>'); + + let commonEventData = { + parameters: { + cacheDir: this.context.cacheDir + } + }; + commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => { + console.debug('====>Acts_ActionExtensionAbility_2400 first publish err:' + JSON.stringify(err)); + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_2500') { + console.info('=======>UIExtAbility onSessionCreate want.action == Acts_ActionExtensionAbility_2500======>'); + + let commonEventData = { + parameters: { + tempDir: this.context.tempDir + } + }; + commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => { + console.debug('====>Acts_ActionExtensionAbility_2500 first publish err:' + JSON.stringify(err)); + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_2600') { + console.info('=======>UIExtAbility onSessionCreate want.action == Acts_ActionExtensionAbility_2600======>'); + + let commonEventData = { + parameters: { + filesDir: this.context.filesDir + } + }; + commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => { + console.debug('====>Acts_ActionExtensionAbility_2600 first publish err:' + JSON.stringify(err)); + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_2700') { + console.info('=======>UIExtAbility onSessionCreate want.action == Acts_ActionExtensionAbility_2700======>'); + + let commonEventData = { + parameters: { + databaseDir: this.context.databaseDir + } + }; + commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => { + console.debug('====>Acts_ActionExtensionAbility_2700 first publish err:' + JSON.stringify(err)); + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_2800') { + console.info('=======>UIExtAbility onSessionCreate want.action == Acts_ActionExtensionAbility_2800======>'); + + let commonEventData = { + parameters: { + preferencesDir: this.context.preferencesDir + } + }; + commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => { + console.debug('====>Acts_ActionExtensionAbility_2800 first publish err:' + JSON.stringify(err)); + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_2900') { + console.info('=======>UIExtAbility onSessionCreate want.action == Acts_ActionExtensionAbility_2900======>'); + + let commonEventData = { + parameters: { + bundleCodeDir: this.context.bundleCodeDir + } + }; + commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => { + console.debug('====>Acts_ActionExtensionAbility_2900 first publish err:' + JSON.stringify(err)); + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_3000') { + var moduleContext = this.context.createModuleContext('entry'); + let options = { + parameters: { + 'bundleName': moduleContext.applicationInfo.name + } + } + commonEvent.publish('ACTS_TEST_CONTEXT', options, (err) => { + console.log('Acts_ActionExtensionAbility_context'); + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_3100') { + var moduleContext = this.context.createModuleContext('entry_test'); + let options = { + parameters: { + 'bundleName': moduleContext.applicationInfo.name + } + } + commonEvent.publish('ACTS_TEST_CONTEXT', options, (err) => { + console.log('Acts_ActionExtensionAbility_context'); + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_3200') { + try { + var moduleContext = this.context.createModuleContext('entry_assist'); + } catch { + console.log('createModuleContext err'); + } + let options = { + parameters: { + 'moduleContext': moduleContext + } + } + commonEvent.publish('ACTS_TEST_CONTEXT', options, (err) => { + console.log('Acts_ActionExtensionAbility_context'); + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_3300') { + try { + var moduleContext = this.context.createModuleContext('abc'); + } catch { + console.log('createModuleContext err'); + } + let options = { + parameters: { + 'moduleContext': moduleContext + } + } + commonEvent.publish('ACTS_TEST_CONTEXT', options, (err) => { + console.log('Acts_ActionExtensionAbility_context'); + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_3400') { + try { + var moduleContext = this.context.createModuleContext(undefined); + } catch { + console.log('createModuleContext err'); + } + let options = { + parameters: { + 'moduleContext': moduleContext + } + } + commonEvent.publish('ACTS_TEST_CONTEXT', options, (err) => { + console.log('Acts_ActionExtensionAbility_context'); + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_3500') { + var applicationContext = this.context.getApplicationContext(); + let options = { + parameters: { + 'applicationContext': applicationContext + } + } + commonEvent.publish('ACTS_TEST_CONTEXT', options, (err) => { + console.log('Acts_ActionExtensionAbility_context'); + }); + } + } + + onSessionDestroy(session) { + console.log('onSessionDestroy'); + } + + onDestroy() { + console.info('=======>UIExtensionAbility onDestroy ======>'); + } + + onForeground() { + console.log('=====> UIExtAbility onForeground =====> '); + } +}; diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/src/main/ets/actionextensionability/ActsActionExtensionAbility.ts b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/src/main/ets/actionextensionability/ActsActionExtensionAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..8d8fcc7b2adc6f84379405d7885813b59ccce2c1 --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/src/main/ets/actionextensionability/ActsActionExtensionAbility.ts @@ -0,0 +1,76 @@ +/* + * 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 ActionExtensionAbility from '@ohos.app.ability.ActionExtensionAbility'; +import commonEventManager from '@ohos.commonEventManager'; + +var count = 0; +const TIME_OUT = 500; +export default class ActsActionExtensionAbility extends ActionExtensionAbility { + storage: LocalStorage; + message: string; + onCreate() { + console.log('====>ActsActionExtensionAbility onCreate called'); + count++; + } + + onForeground() { + console.log('====>ActsActionExtensionAbility onForeground called'); + count++; + let options = { + parameters: { + 'count': count + } + } + commonEventManager.publish('ACTS_TEST_FOREGROUND', options, function (){}); + } + + onBackground() { + console.log('====>ActsActionExtensionAbility onBackground called'); + count++; + commonEventManager.publish('ACTS_TEST_BACKGROUND', function (){}); + setTimeout(() => { + globalThis.session.terminateSelf(); + }, TIME_OUT); + } + + onSessionCreate(want, session) { + console.log('====>ActsActionExtensionAbility onSessionCreate called'); + count++; + this.message = want.parameters.shareMessages; + this.storage = new LocalStorage( + { + 'session': session, + 'messages': this.message + }); + session.loadContent('pages/PageThree', this.storage); + globalThis.session = session; + } + + onDestroy() { + console.log('====>ActsActionExtensionAbility onDestroy called'); + count++; + var options = { + parameters: { + 'count': count + } + } + commonEventManager.publish('ACTS_TEST_DESTROY', options, function (){}); + } + + onSessionDestroy(session) { + console.log('====>ActsActionExtensionAbility onSessionDestroy called'); + count++; + } +} diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/src/main/ets/calledability/CalledAbility.ts b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/src/main/ets/calledability/CalledAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..0aba6b9a91514f0b1a75b1b49383d2872ff1c206 --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/src/main/ets/calledability/CalledAbility.ts @@ -0,0 +1,100 @@ +/* + * 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 hilog from '@ohos.hilog'; +import type window from '@ohos.window'; + +export default class CalledAbility extends UIAbility { + onCreate(want, launchParam) { + hilog.info(0x0000, 'testTag', '%{public}s', 'CalledAbility onCreate'); + console.log('=====> first app CalledAbility =====>'); + const TIMEOUT = 50; + globalThis.terminateCalledAbility = (str) => { + setTimeout(() => { + this.context.terminateSelf().then(() => { + console.info('====>terminateSelf' + JSON.stringify(str) + ' end'); + }).catch((err) => { + console.info('====>terminateSelf ' + JSON.stringify(str) + ' err:' + JSON.stringify(err)); + }); + }, TIMEOUT); + }; + + if (want.action === 'Acts_ActionExtensionAbility_1000') { + this.context.terminateSelf(); + } + + if (want.action === 'Acts_ActionExtensionAbility_1100') { + this.context.terminateSelf(); + } + + if (want.action === 'Acts_ActionExtensionAbility_1300') { + this.context.terminateSelfWithResult({ + resultCode: 0, + want: { + parameters: { + action: 'ACTION' + } + } + }, (err) => { + console.log('=====> Acts_ActionExtensionAbility_1300 CalledAbilityCallBack terminateSelfWithResult =====>' + err.code); + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_1400') { + this.context.terminateSelfWithResult({ + resultCode: 0, + want: { + parameters: { + action: 'ACTION' + } + } + }, (err) => { + console.log('=====> Acts_ActionExtensionAbility_1400 CalledAbilityCallBack terminateSelfWithResult =====>' + err.code); + }); + } + } + + onDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'CalledAbility onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/PageTwo', (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() { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'CalledAbility onWindowStageDestroy'); + } + + onForeground() { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'CalledAbility onForeground'); + } + + onBackground() { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'CalledAbility onBackground'); + } +} diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/src/main/ets/entryability/EntryAbility.ts b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/src/main/ets/entryability/EntryAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..357e8bd4b2e6e396159f0742ba6197ada10371a8 --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/src/main/ets/entryability/EntryAbility.ts @@ -0,0 +1,430 @@ +/* + * 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 hilog from '@ohos.hilog'; +import type window from '@ohos.window'; + +export default class EntryAbility extends UIAbility { + onCreate(want, launchParam) { + const TIMEOUT = 50; + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + globalThis.terminate = (str) => { + setTimeout(() => { + this.context.terminateSelf().then(() => { + console.info('====>terminateSelf' + JSON.stringify(str) + ' end'); + }).catch((err) => { + console.info('====>terminateSelf ' + JSON.stringify(str) + ' err:' + JSON.stringify(err)); + }); + }, TIMEOUT); + }; + + if (want.action === 'Acts_ActionExtensionAbility_0100') { + console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_0100'); + AppStorage.SetOrCreate('want', { + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'ActsActionExtensionAbility', + parameters: { + 'ability.want.params.uiExtensionType': 'action' + } + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_0300') { + console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_0300'); + AppStorage.SetOrCreate('want', { + bundleName: 'com.example.actsactionextensionabilityrely', + abilityName: 'ActsActionExtensionAbility', + parameters: { + 'ability.want.params.uiExtensionType': 'action' + } + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_0400') { + console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_0400'); + AppStorage.SetOrCreate('want', { + action: 'Acts_ActionExtensionAbility_0400', + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'FeatureActionExtensionAbility', + parameters: { + 'ability.want.params.uiExtensionType': 'action' + } + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_0500') { + console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_0500'); + AppStorage.SetOrCreate('want', { + bundleName: '', + abilityName: 'ActsActionExtensionAbility', + parameters: { + 'ability.want.params.uiExtensionType': 'action' + } + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_0600') { + console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_0600'); + AppStorage.SetOrCreate('want', { + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: '', + parameters: { + 'ability.want.params.uiExtensionType': 'action' + } + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_0700') { + console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_0700'); + AppStorage.SetOrCreate('want', { + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'ActsActionExtensionAbility', + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_DEFAULT') { + console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_DEFAULT'); + AppStorage.SetOrCreate('want', { + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'UIExtAbility', + parameters: { + 'ability.want.params.uiExtensionType': 'action' + } + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_1000') { + console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_1000'); + AppStorage.SetOrCreate('want', { + action: 'Acts_ActionExtensionAbility_1000', + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'UIExtAbility', + parameters: { + 'ability.want.params.uiExtensionType': 'action' + } + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_1100') { + console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_1100'); + AppStorage.SetOrCreate('want', { + action: 'Acts_ActionExtensionAbility_1100', + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'UIExtAbility', + parameters: { + 'ability.want.params.uiExtensionType': 'action' + } + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_1200') { + console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_1200'); + AppStorage.SetOrCreate('want', { + action: 'Acts_ActionExtensionAbility_1200', + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'UIExtAbility', + parameters: { + 'ability.want.params.uiExtensionType': 'action' + } + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_1300') { + console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_1300'); + AppStorage.SetOrCreate('want', { + action: 'Acts_ActionExtensionAbility_1300', + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'UIExtAbility', + parameters: { + 'ability.want.params.uiExtensionType': 'action' + } + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_1400') { + console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_1400'); + AppStorage.SetOrCreate('want', { + action: 'Acts_ActionExtensionAbility_1400', + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'UIExtAbility', + parameters: { + 'ability.want.params.uiExtensionType': 'action' + } + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_1500') { + console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_1500'); + AppStorage.SetOrCreate('want', { + action: 'Acts_ActionExtensionAbility_1500', + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'UIExtAbility', + parameters: { + 'ability.want.params.uiExtensionType': 'action' + } + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_1600') { + console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_1600'); + AppStorage.SetOrCreate('want', { + action: 'Acts_ActionExtensionAbility_1600', + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'UIExtAbility', + parameters: { + 'ability.want.params.uiExtensionType': 'action' + } + }); + } + + + if (want.action === 'Acts_ActionExtensionAbility_1700') { + console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_1700'); + AppStorage.SetOrCreate('want', { + action: 'Acts_ActionExtensionAbility_1700', + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'UIExtAbility', + parameters: { + 'ability.want.params.uiExtensionType': 'action' + } + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_1800') { + console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_1800'); + AppStorage.SetOrCreate('want', { + action: 'Acts_ActionExtensionAbility_1800', + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'UIExtAbility', + parameters: { + 'ability.want.params.uiExtensionType': 'action' + } + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_context') { + console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_context'); + AppStorage.SetOrCreate('want', { + action: 'Acts_ActionExtensionAbility_context', + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'UIExtAbility', + parameters: { + 'ability.want.params.uiExtensionType': 'action' + } + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_2200') { + console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_2200'); + AppStorage.SetOrCreate('want', { + action: 'Acts_ActionExtensionAbility_2200', + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'UIExtAbility', + parameters: { + 'ability.want.params.uiExtensionType': 'action' + } + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_2300') { + console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_2300'); + AppStorage.SetOrCreate('want', { + action: 'Acts_ActionExtensionAbility_2300', + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'UIExtAbility', + parameters: { + 'ability.want.params.uiExtensionType': 'action' + } + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_2400') { + console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_2400'); + AppStorage.SetOrCreate('want', { + action: 'Acts_ActionExtensionAbility_2400', + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'UIExtAbility', + parameters: { + 'ability.want.params.uiExtensionType': 'action' + } + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_2500') { + console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_2500'); + AppStorage.SetOrCreate('want', { + action: 'Acts_ActionExtensionAbility_2500', + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'UIExtAbility', + parameters: { + 'ability.want.params.uiExtensionType': 'action' + } + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_2600') { + console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_2600'); + AppStorage.SetOrCreate('want', { + action: 'Acts_ActionExtensionAbility_2600', + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'UIExtAbility', + parameters: { + 'ability.want.params.uiExtensionType': 'action' + } + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_2700') { + console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_2700'); + AppStorage.SetOrCreate('want', { + action: 'Acts_ActionExtensionAbility_2700', + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'UIExtAbility', + parameters: { + 'ability.want.params.uiExtensionType': 'action' + } + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_2800') { + console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_2800'); + AppStorage.SetOrCreate('want', { + action: 'Acts_ActionExtensionAbility_2800', + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'UIExtAbility', + parameters: { + 'ability.want.params.uiExtensionType': 'action' + } + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_2900') { + console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_2900'); + AppStorage.SetOrCreate('want', { + action: 'Acts_ActionExtensionAbility_2900', + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'UIExtAbility', + parameters: { + 'ability.want.params.uiExtensionType': 'action' + } + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_3000') { + console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_3000'); + AppStorage.SetOrCreate('want', { + action: 'Acts_ActionExtensionAbility_3000', + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'UIExtAbility', + parameters: { + 'ability.want.params.uiExtensionType': 'action' + } + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_3100') { + console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_3100'); + AppStorage.SetOrCreate('want', { + action: 'Acts_ActionExtensionAbility_3100', + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'UIExtAbility', + parameters: { + 'ability.want.params.uiExtensionType': 'action' + } + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_3200') { + console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_3200'); + AppStorage.SetOrCreate('want', { + action: 'Acts_ActionExtensionAbility_3200', + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'UIExtAbility', + parameters: { + 'ability.want.params.uiExtensionType': 'action' + } + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_3300') { + console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_3300'); + AppStorage.SetOrCreate('want', { + action: 'Acts_ActionExtensionAbility_3300', + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'UIExtAbility', + parameters: { + 'ability.want.params.uiExtensionType': 'action' + } + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_3400') { + console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_3400'); + AppStorage.SetOrCreate('want', { + action: 'Acts_ActionExtensionAbility_3400', + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'UIExtAbility', + parameters: { + 'ability.want.params.uiExtensionType': 'action' + } + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_3500') { + console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_3500'); + AppStorage.SetOrCreate('want', { + action: 'Acts_ActionExtensionAbility_3500', + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'UIExtAbility', + parameters: { + 'ability.want.params.uiExtensionType': 'action' + } + }); + } + } + + onDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + windowStage.loadContent('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() { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground() { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + + } + + onBackground() { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/src/main/ets/otherability/OtherAbility.ts b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/src/main/ets/otherability/OtherAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..e8f3616fcb39201b217e7fde3cf9e612195003d9 --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/src/main/ets/otherability/OtherAbility.ts @@ -0,0 +1,71 @@ +/* + * 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 hilog from '@ohos.hilog'; +import type window from '@ohos.window'; + +const CUMULATIVE = 2; + +export default class OtherAbility extends UIAbility { + circulate: number = 0; + + onCreate(want, launchParam) { + console.log('=====> OtherAbility onCreate =====>'); + } + + onDestroy() { + console.log('=====> OtherAbility onDestroy =====>'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + // Main window is created, set main page for this ability + console.log('=====> OtherAbility onWindowStageCreate =====>'); + windowStage.loadContent('pages/IndexTwo', (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() { + // Main window is destroyed, release UI related resources + console.log('=====> OtherAbility onWindowStageDestroy =====>'); + } + + onForeground() { + console.log('=====> OtherAbility onForeground =====>'); + this.circulate++; + console.log(`=====> OtherAbility circulate count: ${this.circulate}`); + if (this.circulate === CUMULATIVE) { + this.context.terminateSelfWithResult({ + resultCode: 0, + want: { + parameters: { + action: 'ACTION' + } + } + }, (err) => { + console.log('=====> OtherAbility CalledAbilityCallBack terminateSelfWithResult =====>' + err.code); + }); + } + } + + onBackground() { + // Ability has back to background + console.log('=====> OtherAbility onBackground =====>'); + } +} diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/src/main/ets/pages/Index.ets b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..418b90077ef454109ae11e8f4fd3703d00be8172 --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,92 @@ +/* + * 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 Want from '@ohos.app.ability.Want'; +import commonEventManager from '@ohos.commonEventManager'; + +@Entry +@Component +struct Index { + @State message: string = 'First application'; + @StorageLink('want') want: Want = { + action: 'AsyncCallback_0100', + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'UIExtAbility', + parameters: { + 'ability.want.params.uiExtensionType': 'action' + } + }; + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + UIExtensionComponent(this.want) + .size({width:'100%',height:'100'}) + .backgroundColor(Color.Blue) + .border({width:5,color:Color.Red}) + .onRemoteReady((proxy) => { + setTimeout(() => { + proxy.send({ + name: { + test: 'actionExtensionTest' + } + }); + }, 1000); + }) + .onResult((data)=>{ + var onResultEvent = 'ACTS_UIExtension_OnResult'; + var options = { + parameters: { + 'result': data + } + } + commonEventManager.publish(onResultEvent, options, (err) => { + console.log('ACTS_UIExtension_OnResult'); + }); + }) + .onReceive((data)=>{ + var onReceiveEvent = 'ACTS_UIExtension_OnReceive'; + var options = { + parameters: { + 'result': data + } + } + commonEventManager.publish(onReceiveEvent, options, (err) => { + console.log('ACTS_UIExtension_OnReceive'); + }); + }) + .onError((err) => { + var options = { + parameters: { + 'err': err + } + } + commonEventManager.publish('ACTS_TEST_START_ERR', options, function (){}); + }) + .onRelease((releaseCode) => { + var options = { + parameters: { + 'releaseCode': releaseCode + } + } + commonEventManager.publish('ACTS_TEST_RELEASE', options, function (){}); + }) + } + .width('100%') + } + .height('100%') + } +} \ No newline at end of file diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/src/main/ets/pages/IndexTwo.ets b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/src/main/ets/pages/IndexTwo.ets new file mode 100644 index 0000000000000000000000000000000000000000..183421e58e29fb55a1032a9ae55e70264776cd5f --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/src/main/ets/pages/IndexTwo.ets @@ -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. + */ +@Entry +@Component +struct IndexTwo { + @State message: string = 'Other Ability!'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button('TerminateCallback0100') + .fontSize(30) + .fontWeight(FontWeight.Bold) + .onClick(() => { + globalThis.StartAbilityForResult_CallBack() + }) + .margin({ + top: 5 + }) + } + .width('100%') + } + .height('100%') + } +} \ No newline at end of file diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/src/main/ets/pages/Page.ets b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/src/main/ets/pages/Page.ets new file mode 100644 index 0000000000000000000000000000000000000000..1d8aff2769ea82072980666241feb310e0d21ebb --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/src/main/ets/pages/Page.ets @@ -0,0 +1,95 @@ +/* + * 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 Want from '@ohos.app.ability.Want'; +import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession'; +import commonEventManager from '@ohos.commonEventManager'; + +const sleepTimeOne = 1000; +var storage = LocalStorage.GetShared(); + +@Entry(storage) +@Component +struct Page { + @State message: string = 'UIExtAbility'; + @StorageLink('actionWant') want: Want = { + action: "Acts_ActionExtensionAbility_1700", + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'ActsActionExtensionAbility', + parameters: { + 'ability.want.params.uiExtensionType': 'action' + } + }; + private session: UIExtensionContentSession = storage.get('session'); + + aboutToAppear() { + var appearEvent = 'ACTS_UIExtension_AboutToAppear'; + var terminateSelfWithResultEvent = 'ACTS_UIExtension_TerminateSelfWithResult'; + var sendDataEvent = 'ACTS_UIExtension_SendData'; + + var subscriber; + var subscribeInfo = { + events: [terminateSelfWithResultEvent, sendDataEvent] + }; + commonEventManager.createSubscriber(subscribeInfo).then(async (data) => { + console.log('createSubscriber data : ' + JSON.stringify(data)); + subscriber = data; + + commonEventManager.subscribe(subscriber, async (err, data) => { + console.log('SubscribeInfoCallback : ' + JSON.stringify(data)); + if (data.event === terminateSelfWithResultEvent) { + this.session.terminateSelfWithResult({ + 'resultCode': 1, + 'want': { + 'action': 'ACTION' + } + }); + commonEventManager.unsubscribe(subscriber, async (err, data) => { + console.log('UnSubscribeInfoCallback : ' + JSON.stringify(data)); + }); + } else if (data.event === sendDataEvent) { + this.session.sendData({ + name: { + test: 'actionExtensionTest' + } + }); + commonEventManager.unsubscribe(subscriber, async (err, data) => { + console.log('UnSubscribeInfoCallback : ' + JSON.stringify(data)); + }); + } + }); + }).catch((error) => { + console.log('createSubscriber error : ' + JSON.stringify(error)); + }) + setTimeout(() => { + commonEventManager.publish(appearEvent, function (){}); + }, sleepTimeOne); + } + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .fontWeight(FontWeight.Bold) + UIExtensionComponent(this.want) + .size({width:'100%',height:'100'}) + .backgroundColor(Color.Blue) + .border({width:5,color:Color.Red}) + } + .width('100%') + } + .height('100%') + } +} \ No newline at end of file diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/src/main/ets/pages/PageThree.ets b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/src/main/ets/pages/PageThree.ets new file mode 100644 index 0000000000000000000000000000000000000000..8bedf00eeb1460e9820612cb6bac761d54275fb1 --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/src/main/ets/pages/PageThree.ets @@ -0,0 +1,35 @@ +/* + * 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. + */ + +var storage = LocalStorage.GetShared(); + +@Entry(storage) +@Component +struct Index3 { + + build() { + Row() { + Column() { + Text('acton') + .fontSize(24) + .fontWeight(FontWeight.Bold) + } + .width('100%') + } + .height('100%') + .backgroundColor('#e0ffff') + .borderRadius(16) + } +} \ No newline at end of file diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/src/main/ets/pages/PageTwo.ets b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/src/main/ets/pages/PageTwo.ets new file mode 100644 index 0000000000000000000000000000000000000000..b10b4f79827b8b7d5a7c24598c63779295eeebb6 --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/src/main/ets/pages/PageTwo.ets @@ -0,0 +1,31 @@ +/* + * 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 PageTwo { + @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/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/src/main/module.json b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..3731f2bba13a5a7b617a7f1f91b5b21b15a94a70 --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/src/main/module.json @@ -0,0 +1,86 @@ +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "metadata":[ + { + "name":"test_metadata" + } + ], + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ts", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + }, + { + "name": "OtherAbility", + "srcEntry": "./ets/otherability/OtherAbility.ts", + "description": "$string:OtherAbility_desc", + "visible": true, + "icon": "$media:icon", + "label": "$string:OtherAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background" + }, + { + "name": "CalledAbility", + "srcEntry": "./ets/calledability/CalledAbility.ts", + "description": "$string:CalledAbility_desc", + "visible": true, + "icon": "$media:icon", + "label": "$string:CalledAbility_label", + "launchType": "standard", + "exported": false, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background" + } + ], + "extensionAbilities": [ + { + "name": "UIExtAbility", + "icon": "$media:icon", + "description": "UIExtAbility", + "type": "action", + "visible": true, + "srcEntrance": "./ets/UIExtensionAbility/UIExtAbility.ts" + }, + { + "name": "ActsActionExtensionAbility", + "icon": "$media:icon", + "description": "ActsActionExtensionAbility", + "type": "action", + "visible": true, + "srcEntrance": "./ets/actionextensionability/ActsActionExtensionAbility.ts" + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.START_ABILITIES_FROM_BACKGROUND" + } + ] + } +} \ No newline at end of file diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/src/main/resources/base/element/color.json b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33 --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/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/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/src/main/resources/base/element/string.json b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..c27bb840373b2dd01bebd64a52879e477220748b --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/src/main/resources/base/element/string.json @@ -0,0 +1,32 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "OtherAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + }, + { + "name": "OtherAbility_label", + "value": "label" + }, + { + "name": "CalledAbility_desc", + "value": "description" + }, + { + "name": "CalledAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/src/main/resources/base/media/icon.png b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/src/main/resources/base/media/icon.png differ diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/src/main/resources/base/profile/main_pages.json b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..ea969f22f0989da218c0b4ea652a1fd33da89f98 --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,8 @@ +{ + "src": [ + "pages/Index", + "pages/Page", + "pages/PageTwo", + "pages/PageThree" + ] +} \ No newline at end of file diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/src/main/resources/en_US/element/string.json b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..c27bb840373b2dd01bebd64a52879e477220748b --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/src/main/resources/en_US/element/string.json @@ -0,0 +1,32 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "OtherAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + }, + { + "name": "OtherAbility_label", + "value": "label" + }, + { + "name": "CalledAbility_desc", + "value": "description" + }, + { + "name": "CalledAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/src/main/resources/zh_CN/element/string.json b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..73838f7ea8aee9962adb53d5a9b39528744719e7 --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/entry/src/main/resources/zh_CN/element/string.json @@ -0,0 +1,24 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "模块描述" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + }, + { + "name": "CalledAbility_desc", + "value": "description" + }, + { + "name": "CalledAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/feature/src/main/ets/actionextensionability/FeatureActionExtensionAbility.ts b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/feature/src/main/ets/actionextensionability/FeatureActionExtensionAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..6bc49943a467f9f5b96d4a90dbc506b71b28d805 --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/feature/src/main/ets/actionextensionability/FeatureActionExtensionAbility.ts @@ -0,0 +1,58 @@ +/* + * 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 ActionExtensionAbility from '@ohos.app.ability.ActionExtensionAbility'; +import commonEventManager from '@ohos.commonEventManager'; + +export default class FeatureActionExtensionAbility extends ActionExtensionAbility { + storage: LocalStorage; + message: string; + onCreate() { + } + + onForeground() { + console.log('====>FeatureActionExtensionAbility onForeground called'); + } + + onBackground() { + console.log('====>FeatureActionExtensionAbility onBackground called'); + } + + onSessionCreate(want, session) { + console.log('====>FeatureActionExtensionAbility onSessionCreate called'); + commonEventManager.publish('ACTS_FEATURE_CREATE', function (){}); + if (want.action === 'Acts_ActionExtensionAbility_0400') { + this.context.startAbility({ + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'FeatureAbility', + action: 'Acts_ActionExtensionAbility_0400' + }) + } + this.message = want.parameters.shareMessages; + this.storage = new LocalStorage( + { + 'session': session, + 'messages': this.message + }); + session.loadContent('pages/Index2', this.storage); + } + + onDestroy() { + console.log('====>FeatureActionExtensionAbility onDestroy called'); + } + + onSessionDestroy(session) { + console.log('====>FeatureActionExtensionAbility onSessionDestroy called'); + } +} diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/feature/src/main/ets/featureability/FeatureAbility.ts b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/feature/src/main/ets/featureability/FeatureAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..77878edc692767f753264c782d6eef5dcd8bd366 --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/feature/src/main/ets/featureability/FeatureAbility.ts @@ -0,0 +1,88 @@ +/* + * 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 hilog from '@ohos.hilog'; +import window from '@ohos.window'; + +export default class FeatureAbility extends UIAbility { + onCreate(want, launchParam) { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + const TIMEOUT = 50; + globalThis.featureTerminate = (str) => { + setTimeout(() => { + this.context.terminateSelf().then(() => { + console.info('====>terminateSelf' + JSON.stringify(str) + ' end'); + }).catch((err) => { + console.info('====>terminateSelf ' + JSON.stringify(str) + ' err:' + JSON.stringify(err)); + }); + }, TIMEOUT); + }; + + if (want.action === 'Acts_ActionExtensionAbility_0400') { + console.info('====>FeatureAbility want.action == Acts_ActionExtensionAbility_0400'); + AppStorage.SetOrCreate('want', { + action: 'Acts_ActionExtensionAbility_0400', + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'FeatureActionExtensionAbility', + parameters: { + 'ability.want.params.uiExtensionType': 'action' + } + }); + } + + if (want.action === 'Acts_ActionExtensionAbility_0200') { + console.info('====>FeatureAbility want.action == Acts_ActionExtensionAbility_0200'); + AppStorage.SetOrCreate('want', { + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'ActsActionExtensionAbility', + parameters: { + 'ability.want.params.uiExtensionType': 'action' + } + }); + } + } + + onDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('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() { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground() { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground() { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/feature/src/main/ets/pages/Index.ets b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/feature/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..e51777e09c365fbd4a5f25d761f8c3b4d63948b9 --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/feature/src/main/ets/pages/Index.ets @@ -0,0 +1,41 @@ +/* + * 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 Want from '@ohos.app.ability.Want'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World' + @StorageLink('want') want: Want = { + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'ActsActionExtensionAbility', + parameters: { + 'ability.want.params.uiExtensionType': 'action' + } + } + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + UIExtensionComponent(this.want).width('100%').height('35%') + } + .width('100%') + } + .height('100%') + } +} \ No newline at end of file diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/feature/src/main/ets/pages/Index2.ets b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/feature/src/main/ets/pages/Index2.ets new file mode 100644 index 0000000000000000000000000000000000000000..8269a4e97038193a2bcdbae1d0f3202aecb62420 --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/feature/src/main/ets/pages/Index2.ets @@ -0,0 +1,34 @@ +/* + * 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. + */ + +var storage = LocalStorage.GetShared(); + +@Entry(storage) +@Component +struct Index2 { + @State message: string = 'FeatureActionExtensionAbility'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .fontWeight(FontWeight.Bold) + } + .width('100%') + } + .height('100%') + } +} \ No newline at end of file diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/feature/src/main/module.json b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/feature/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..124739b629eb2ebd2df1ecb86881813e75462fd1 --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/feature/src/main/module.json @@ -0,0 +1,41 @@ +{ + "module": { + "name": "feature", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "FeatureAbility", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "FeatureAbility", + "srcEntry": "./ets/featureability/FeatureAbility.ts", + "description": "$string:FeatureAbility_desc", + "icon": "$media:icon", + "label": "$string:FeatureAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ], + "extensionAbilities": [ + { + "name": "FeatureActionExtensionAbility", + "icon": "$media:icon", + "description": "FeatureActionExtensionAbility", + "type": "action", + "exported": true, + "srcEntrance": "./ets/actionextensionability/FeatureActionExtensionAbility.ts" + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.START_ABILITIES_FROM_BACKGROUND" + } + ] + } +} \ No newline at end of file diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/feature/src/main/resources/base/element/color.json b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/feature/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33 --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/feature/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/ability_runtime/actsactionextensionability/actsactionextensionabilityself/feature/src/main/resources/base/element/string.json b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/feature/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..01a21433fd9b713f8e23c5168d556447263eaca9 --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/feature/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "FeatureAbility_desc", + "value": "description" + }, + { + "name": "FeatureAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/feature/src/main/resources/base/media/icon.png b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/feature/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/feature/src/main/resources/base/media/icon.png differ diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/feature/src/main/resources/base/profile/main_pages.json b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/feature/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..f9a6423252cdb1b3afbc0a80bb3f9eda611228e7 --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/feature/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,6 @@ +{ + "src": [ + "pages/Index", + "pages/Index2" + ] +} diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/feature/src/main/resources/en_US/element/string.json b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/feature/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..01a21433fd9b713f8e23c5168d556447263eaca9 --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/feature/src/main/resources/en_US/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "FeatureAbility_desc", + "value": "description" + }, + { + "name": "FeatureAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/feature/src/main/resources/zh_CN/element/string.json b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/feature/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..b591066bb68f1accd7fd339a37fb07d00a90d96e --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/feature/src/main/resources/zh_CN/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "模块描述" + }, + { + "name": "FeatureAbility_desc", + "value": "description" + }, + { + "name": "FeatureAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/signature/openharmony_sx.p7b b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..1528e8b94770f99bd9c2235b86ce4bf72623bdcd Binary files /dev/null and b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilityself/signature/openharmony_sx.p7b differ diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilitytest/AppScope/app.json b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilitytest/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..abf2fd00b542cf0bb6edf44ca16d802867fef7b6 --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilitytest/AppScope/app.json @@ -0,0 +1,19 @@ +{ + "app": { + "bundleName": "com.example.actsactionextensionabilitytest", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name", + "distributedNotificationEnabled": true, + "keepAlive" : true, + "singleUser": true, + "minAPIVersion": 10, + "targetAPIVersion": 10, + "car": { + "apiCompatibleVersion": 10, + "singleUser": false + } + } +} diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilitytest/AppScope/resources/base/element/string.json b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilitytest/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..d71e5ead1ce20b4ac3384d18e6d104f1ea4d83b4 --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilitytest/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "MyApplication" + } + ] +} diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilitytest/AppScope/resources/base/media/app_icon.png b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilitytest/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilitytest/AppScope/resources/base/media/app_icon.png differ diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilitytest/BUILD.gn b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilitytest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..abf7c76797a5fb8d5fba3e00dbfd694fdb70edd1 --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilitytest/BUILD.gn @@ -0,0 +1,43 @@ +# 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("ActsActionExtensionAbilityTest") { + hap_profile = "entry/src/main/module.json" + js_build_mode = "debug" + deps = [ + ":actsactionextensionabilitytest_js_assets", + ":actsactionextensionabilitytest_resources", + ] + ets2abc = true + certificate_profile = "signature/openharmony_sx.p7b" + hap_name = "ActsActionExtensionAbilityTest" + subsystem_name = "ability" + part_name = "ability_runtime" +} + +ohos_app_scope("actsactionextensionabilitytest_app_profile") { + app_profile = "AppScope/app.json" + sources = [ "AppScope/resources" ] +} + +ohos_js_assets("actsactionextensionabilitytest_js_assets") { + source_dir = "entry/src/main/ets" +} + +ohos_resources("actsactionextensionabilitytest_resources") { + sources = [ "entry/src/main/resources" ] + deps = [ ":actsactionextensionabilitytest_app_profile" ] + hap_profile = "entry/src/main/module.json" +} diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilitytest/Test.json b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilitytest/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..825ca732a3ae4e3294e4661a52df4fa8ccd9fc97 --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilitytest/Test.json @@ -0,0 +1,38 @@ +{ + "description": "Configuration for aceceshi Tests", + "driver": { + "type": "OHJSUnitTest", + "test-timeout": "600000", + "bundle-name": "com.example.actsactionextensionabilitytest", + "module-name": "entry_test", + "shell-timeout": "600000", + "testcase-timeout": 25000 + }, + "kits": [ + { + "test-file-name": [ + "ActsActionExtensionAbilityOtherRely.hap", + "ActsActionExtensionAbilitySelfRely.hap", + "ActsActionExtensionAbilitySelfModule.hap", + "ActsActionExtensionAbilityTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + }, + { + "type": "ShellKit", + "run-command": [ + "param set persist.sys.suspend_manager_enabled false", + "reboot", + "power-shell wakeup", + "uinput -T -d 300 600 -m 300 600 300 100 -u 300 100", + "power-shell setmode 602" + ], + "teardown-command": [ + "param set persist.sys.suspend_manager_enabled true", + "power-shell setmode 601", + "reboot" + ] + } + ] +} \ No newline at end of file diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilitytest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilitytest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..548b9215d16a5721de9aca1a1d977d2fc9b8147e --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilitytest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,62 @@ +/* + * 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'; +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'; + var 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/ability_runtime/actsactionextensionability/actsactionextensionabilitytest/entry/src/main/ets/test/Ability.test.ets b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilitytest/entry/src/main/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7e0b001235ab6979075140e228bb6a6044bf4fc6 --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilitytest/entry/src/main/ets/test/Ability.test.ets @@ -0,0 +1,1672 @@ +/* + * 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 commonEvent from '@ohos.commonEventManager'; +import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; +import { Driver, ON } from '@ohos.UiTest'; + +var abilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +var ACTS_CallFunction = { + events: ['ACTS_CALL_EVENT', 'ACTS_CALL_EVENT_ANOTHER'] +}; +var ACTS_EVENT = { + events: ['ACTS_TEST_FOREGROUND', 'ACTS_TEST_DESTROY', 'ACTS_TEST_RELEASE', 'ACTS_TEST_START_ERR'] +}; +const CONTEXT_WANT = { + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'EntryAbility', + action: 'Acts_ActionExtensionAbility_context' +}; +export default function abilityTest() { + describe('ActsAbilityTest', function () { + + /** + * @tc.number: Acts_ActionExtensionAbility_0100 + * @tc.name: Test ActionExtensionAbility basic function. + * @tc.desc: With the same application with the same module, test ActionExtensionAbility lifecycle. + */ + it('Acts_ActionExtensionAbility_0100',0, async function (done) { + var subscriber; + commonEvent.createSubscriber(ACTS_EVENT).then(async (data) => { + console.info(`====>Acts_ActionExtensionAbility_0100 createSubscriber ${data}`); + subscriber = data; + commonEvent.subscribe(data, subscribeCallBack); + globalThis.context.startAbility({ + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'EntryAbility', + action: 'Acts_ActionExtensionAbility_0100' + }, (err) => { + expect(err.code).assertEqual(0); + }); + + async function subscribeCallBack(err, data) { + console.log('====>Acts_ActionExtensionAbility_0100 subscribeCallBack :' + JSON.stringify(data)); + if (data.event == 'ACTS_TEST_FOREGROUND') { + expect(data.parameters.count).assertEqual(3); + await abilityDelegator.executeShellCommand('aa dump -a').then((data) => { + console.info('====>Acts_ActionExtensionAbility_0100 : data : ' + JSON.stringify(data.stdResult)); + var firstString = data.stdResult.split("entry/ActsActionExtensionAbility"); + var result = firstString[1].split("uri"); + console.info('====>Acts_ActionExtensionAbility_0100 result aa string: ' + JSON.stringify(result[0])); + try { + expect(result[0]).assertContain("main name [ActsActionExtensionAbility]"); + expect(result[0]).assertContain("bundle name [com.example.actsactionextensionabilitytest]"); + expect(result[0]).assertContain("ability type [SERVICE]"); + expect(result[0]).assertContain("app state #FOREGROUND"); + } catch { + expect().assertFail(); + } + }); + + setTimeout(() => { + globalThis.context.startAbility({ + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'CalledAbility' + }, (err) => { + expect(err.code).assertEqual(0); + }); + }, 1000); + } + if (data.event == 'ACTS_TEST_RELEASE') { + expect(data.parameters.releaseCode).assertEqual(0); + } + if (data.event == 'ACTS_TEST_DESTROY') { + expect(data.parameters.count).assertEqual(6); + setTimeout(() => { + commonEvent.unsubscribe(subscriber, unSubscribeCallback); + }, 500); + } + } + + async function unSubscribeCallback() { + await globalThis.terminate('Acts_ActionExtensionAbility_0100'); + await globalThis.terminateCalledAbility('Acts_ActionExtensionAbility_0100'); + setTimeout(() => { + console.info(`====>Acts_ActionExtensionAbility_0100 unSubscribeCallback`); + done(); + }, 2000); + } + }); + }) + + /** + * @tc.number: Acts_ActionExtensionAbility_0200 + * @tc.name: Test ActionExtensionAbility basic function. + * @tc.desc: With the same application with the different module, test ActionExtensionAbility lifecycle. + */ + it('Acts_ActionExtensionAbility_0200',0, async function (done) { + var subscriber; + commonEvent.createSubscriber(ACTS_EVENT).then(async (data) => { + subscriber = data; + commonEvent.subscribe(data, subscribeCallBack); + globalThis.context.startAbility({ + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'FeatureAbility', + action: 'Acts_ActionExtensionAbility_0200' + }, (err) => { + expect(err.code).assertEqual(0); + }); + + async function subscribeCallBack(err, data) { + console.log('====>Acts_ActionExtensionAbility_0200 subscribeCallBack :' + JSON.stringify(data)); + if (data.event == 'ACTS_TEST_FOREGROUND') { + expect(data.parameters.count).assertEqual(3); + await abilityDelegator.executeShellCommand('aa dump -a').then((data) => { + console.info('====>Acts_ActionExtensionAbility_0200 : data : ' + JSON.stringify(data.stdResult)); + var firstString = data.stdResult.split("entry/ActsActionExtensionAbility"); + var result = firstString[1].split("uri"); + console.info('====>Acts_ActionExtensionAbility_0200 result aa string: ' + JSON.stringify(result[0])); + try { + expect(result[0]).assertContain("main name [ActsActionExtensionAbility]"); + expect(result[0]).assertContain("bundle name [com.example.actsactionextensionabilitytest]"); + expect(result[0]).assertContain("ability type [SERVICE]"); + expect(result[0]).assertContain("app state #FOREGROUND"); + } catch { + expect().assertFail(); + }; + }); + setTimeout(() => { + globalThis.context.startAbility({ + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'CalledAbility' + }, (err) => { + expect(err.code).assertEqual(0); + }); + }, 1000); + } + if (data.event == 'ACTS_TEST_RELEASE') { + expect(data.parameters.releaseCode).assertEqual(0); + } + if (data.event == 'ACTS_TEST_DESTROY') { + expect(data.parameters.count).assertEqual(6); + setTimeout(() => { + commonEvent.unsubscribe(subscriber, unSubscribeCallback); + }, 500); + } + } + + async function unSubscribeCallback() { + await globalThis.featureTerminate('Acts_ActionExtensionAbility_0200'); + await globalThis.terminateCalledAbility('Acts_ActionExtensionAbility_0200'); + setTimeout(() => { + console.info(`====>Acts_ActionExtensionAbility_0200 unSubscribeCallback`); + done(); + }, 2000); + } + }); + }) + + /** + * @tc.number: Acts_ActionExtensionAbility_0300 + * @tc.name: Test ActionExtensionAbility basic function. + * @tc.desc: With the different application, test ActionExtensionAbility lifecycle. + */ + it('Acts_ActionExtensionAbility_0300',0, async function (done) { + var subscriber; + commonEvent.createSubscriber(ACTS_EVENT).then(async (data) => { + subscriber = data; + commonEvent.subscribe(data, subscribeCallBack); + globalThis.context.startAbility({ + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'EntryAbility', + action: 'Acts_ActionExtensionAbility_0300' + }, (err) => { + expect(err.code).assertEqual(0); + }); + + async function subscribeCallBack(err, data) { + console.log('====>Acts_ActionExtensionAbility_0300 subscribeCallBack :' + JSON.stringify(data)); + if (data.event == 'ACTS_TEST_FOREGROUND') { + expect(data.parameters.count).assertEqual(3); + await abilityDelegator.executeShellCommand('aa dump -a').then((data) => { + console.info('====>Acts_ActionExtensionAbility_0300 : data : ' + JSON.stringify(data.stdResult)); + var firstString = data.stdResult.split("entry_assist/ActsActionExtensionAbility"); + var result = firstString[1].split("uri"); + console.info('====>Acts_ActionExtensionAbility_0300 result aa string: ' + JSON.stringify(result[0])); + try { + expect(result[0]).assertContain("main name [ActsActionExtensionAbility]"); + expect(result[0]).assertContain("bundle name [com.example.actsactionextensionabilityrely]"); + expect(result[0]).assertContain("ability type [SERVICE]"); + expect(result[0]).assertContain("app state #FOREGROUND"); + } catch { + expect().assertFail(); + } + }); + + setTimeout(() => { + globalThis.context.startAbility({ + bundleName: 'com.example.actsactionextensionabilityrely', + abilityName: 'CalledAbility' + }, (err) => { + expect(err.code).assertEqual(0); + }) + }, 1000); + } + if (data.event == 'ACTS_TEST_RELEASE') { + expect(data.parameters.releaseCode).assertEqual(0); + } + if (data.event == 'ACTS_TEST_DESTROY') { + expect(data.parameters.count).assertEqual(6); + setTimeout(() => { + commonEvent.unsubscribe(subscriber, unSubscribeCallback); + }, 500); + } + } + + async function unSubscribeCallback() { + await globalThis.terminate('Acts_ActionExtensionAbility_0300'); + var cmd = 'aa force-stop com.example.actsactionextensionabilityrely'; + await abilityDelegator.executeShellCommand(cmd).catch((error) => { + console.log("====>Acts_ActionExtensionAbility_0300 executeShellCommand error : " + JSON.stringify(error)); + }); + setTimeout(() => { + console.info(`====>Acts_ActionExtensionAbility_0300 unSubscribeCallback`); + done(); + }, 2000); + } + }); + }) + + /** + * @tc.number: Acts_ActionExtensionAbility_0400 + * @tc.name: Test ActionExtensionAbility basic function. + * @tc.desc: Start the same ActionExtensionAbility with different UI components, and the test is successful. + */ + it('Acts_ActionExtensionAbility_0400',0, async function (done) { + var subscriber; + var ACTS_MODULE = { + events: ['ACTS_FEATURE_CREATE'] + }; + commonEvent.createSubscriber(ACTS_MODULE).then(async (data) => { + subscriber = data; + commonEvent.subscribe(data, subscribeCallBack); + globalThis.context.startAbility({ + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'EntryAbility', + action: 'Acts_ActionExtensionAbility_0400' + }, (err) => { + expect(err.code).assertEqual(0); + }); + + var count = 0; + function subscribeCallBack(err, data) { + console.log('====>Acts_ActionExtensionAbility_0400 subscribeCallBack :' + JSON.stringify(data)); + if (data.event == 'ACTS_FEATURE_CREATE') { + count++; + } + if (count == 2) { + commonEvent.unsubscribe(subscriber, unSubscribeCallback); + } + } + + async function unSubscribeCallback() { + await globalThis.terminate('Acts_ActionExtensionAbility_0400'); + await globalThis.featureTerminate('Acts_ActionExtensionAbility_0400'); + setTimeout(() => { + console.info(`====>Acts_ActionExtensionAbility_0400 unSubscribeCallback`); + done(); + }, 2000); + } + }); + }) + + /** + * @tc.number: Acts_ActionExtensionAbility_0500 + * @tc.name: Test ActionExtensionAbility basic function. + * @tc.desc: Start ActionExtensionAbility with invalid bundleName, start failed. + */ + it('Acts_ActionExtensionAbility_0500',0, async function (done) { + var subscriber; + commonEvent.createSubscriber(ACTS_EVENT).then(async (data) => { + subscriber = data; + commonEvent.subscribe(data, subscribeCallBack); + globalThis.context.startAbility({ + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'EntryAbility', + action: 'Acts_ActionExtensionAbility_0500' + }, (err) => { + expect(err.code).assertEqual(0); + }); + + var flag = true; + function subscribeCallBack(err, data) { + console.log('====>Acts_ActionExtensionAbility_0500 subscribeCallBack :' + JSON.stringify(data)); + if (data.event == 'ACTS_TEST_START_ERR' && flag) { + flag = false; + expect(data.parameters.err.code).assertEqual(1011); + commonEvent.unsubscribe(subscriber, unSubscribeCallback) + } + } + + async function unSubscribeCallback() { + await globalThis.terminate('Acts_ActionExtensionAbility_0500'); + setTimeout(() => { + console.info(`====>Acts_ActionExtensionAbility_0500 unSubscribeCallback`); + done(); + }, 2000); + } + }); + }) + + /** + * @tc.number: Acts_ActionExtensionAbility_0600 + * @tc.name: Test ActionExtensionAbility basic function. + * @tc.desc: Start ActionExtensionAbility with invalid abilityName, start failed. + */ + it('Acts_ActionExtensionAbility_0600',0, async function (done) { + var subscriber; + commonEvent.createSubscriber(ACTS_EVENT).then(async (data) => { + subscriber = data; + commonEvent.subscribe(data, subscribeCallBack); + globalThis.context.startAbility({ + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'EntryAbility', + action: 'Acts_ActionExtensionAbility_0600' + }, (err) => { + expect(err.code).assertEqual(0); + }); + + var flag = true; + function subscribeCallBack(err, data) { + console.log('====>Acts_ActionExtensionAbility_0600 subscribeCallBack :' + JSON.stringify(data)); + if (data.event == 'ACTS_TEST_START_ERR' && flag) { + flag = false; + expect(data.parameters.err.code).assertEqual(1011); + commonEvent.unsubscribe(subscriber, unSubscribeCallback) + } + } + + function unSubscribeCallback() { + globalThis.terminate('Acts_ActionExtensionAbility_0600'); + setTimeout(() => { + console.info(`====>Acts_ActionExtensionAbility_0600 unSubscribeCallback`); + done(); + }, 2000); + } + }); + }) + + /** + * @tc.number: Acts_ActionExtensionAbility_0700 + * @tc.name: Test ActionExtensionAbility basic function. + * @tc.desc: Start ActionExtensionAbility with invalid parameters, start failed. + */ + it('Acts_ActionExtensionAbility_0700',0, async function (done) { + var subscriber; + commonEvent.createSubscriber(ACTS_EVENT).then(async (data) => { + console.info(`====>Acts_ActionExtensionAbility_0700 createSubscriber ${data}`); + subscriber = data; + commonEvent.subscribe(data, subscribeCallBack); + globalThis.context.startAbility({ + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'EntryAbility', + action: 'Acts_ActionExtensionAbility_0700' + }, (err) => { + expect(err.code).assertEqual(0); + }); + + var flag = true; + function subscribeCallBack(err, data) { + console.info(`====>Acts_ActionExtensionAbility_0700 subscribeCallBack 'ACTS_CALL_EVENT' ${data}`); + if (data.event == 'ACTS_TEST_START_ERR' && flag) { + flag = false; + expect(data.parameters.err.code).assertEqual(1011); + commonEvent.unsubscribe(subscriber, unSubscribeCallback) + } + } + + function unSubscribeCallback() { + globalThis.terminate('Acts_ActionExtensionAbility_0700'); + setTimeout(() => { + console.info(`====>Acts_ActionExtensionAbility_0700 unSubscribeCallback`); + done(); + }, 2000); + } + }); + }) + + /** + * @tc.number: Acts_ActionExtensionAbility_0800 + * @tc.name: Test ActionExtensionAbility basic function. + * @tc.desc: Test terminateSelfWithResultEvent successful. + */ + it('Acts_ActionExtensionAbility_0800',0, async function (done) { + var appearEvent = 'ACTS_UIExtension_AboutToAppear'; + var onResultEvent = 'ACTS_UIExtension_OnResult'; + var terminateSelfWithResultEvent = 'ACTS_UIExtension_TerminateSelfWithResult'; + + var subscriber; + var subscribeInfo = { + events: [appearEvent, onResultEvent] + } + await commonEvent.createSubscriber(subscribeInfo).then(async (data) => { + console.log("createSubscriber data : " + JSON.stringify(data)); + subscriber = data; + globalThis.context.startAbility({ + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'EntryAbility', + action: 'Acts_ActionExtensionAbility_DEFAULT' + }, (err) => { + expect(err.code).assertEqual(0); + }); + + commonEvent.subscribe(subscriber, async (err, data) => { + console.log("SubscribeInfoCallback : " + JSON.stringify(data)); + + if (data.event == appearEvent) { + commonEvent.publish(terminateSelfWithResultEvent, function (){}); + } else if (data.event == onResultEvent) { + var result = data.parameters.result; + setTimeout(async () => { + commonEvent.unsubscribe(subscriber, async (err, data) => { + expect(result.want.action).assertEqual('ACTION'); + globalThis.terminate('Acts_ActionExtensionAbility_0800'); + setTimeout(() => { + console.info(`====>Acts_ActionExtensionAbility_0800 unSubscribeCallback`); + done(); + }, 2000); + }); + }, 1000); + } + }); + }).catch((error) => { + globalThis.terminate('Acts_ActionExtensionAbility_0800'); + setTimeout(() => { + console.log("createSubscriber err : " + JSON.stringify(error)); + expect().assertFail(); + }, 2000); + }); + }) + + /** + * @tc.number: Acts_ActionExtensionAbility_0900 + * @tc.name: Test ActionExtensionAbility basic function. + * @tc.desc: Test sendData successful. + */ + it('Acts_ActionExtensionAbility_0900',0, async function (done) { + var appearEvent = 'ACTS_UIExtension_AboutToAppear'; + var onReceiveEvent = 'ACTS_UIExtension_OnReceive'; + var sendDataEvent = 'ACTS_UIExtension_SendData'; + + var subscriber; + var subscribeInfo = { + events: [appearEvent, onReceiveEvent] + } + await commonEvent.createSubscriber(subscribeInfo).then(async (data) => { + console.log("createSubscriber data : " + JSON.stringify(data)); + subscriber = data; + globalThis.context.startAbility({ + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'EntryAbility', + action: 'Acts_ActionExtensionAbility_DEFAULT' + }, (err) => { + expect(err.code).assertEqual(0); + }); + + commonEvent.subscribe(subscriber, async (err, data) => { + console.log("SubscribeInfoCallback : " + JSON.stringify(data)); + + if (data.event == appearEvent) { + commonEvent.publish(sendDataEvent, (err) => { + if (err) { + console.log(`publish ACTS_UIExtension_SendData failed, code is ${err.code}, message is ${err.message}`); + } else { + console.log('publish ACTS_UIExtension_SendData success'); + } + }); + } else if (data.event == onReceiveEvent) { + var result = data.parameters.result; + var resultCheck = { + name: { + test: 'actionExtensionTest' + } + }; + setTimeout(async () => { + commonEvent.unsubscribe(subscriber, async (err, data) => { + expect(JSON.stringify(result)).assertEqual(JSON.stringify(resultCheck)); + globalThis.terminate('Acts_ActionExtensionAbility_0900'); + setTimeout(() => { + console.info(`====>Acts_ActionExtensionAbility_0900 unSubscribeCallback`); + done(); + }, 2000); + }); + }, 1000); + } + }); + }).catch((error) => { + globalThis.terminate('Acts_ActionExtensionAbility_0900'); + setTimeout(() => { + console.log("createSubscriber err : " + JSON.stringify(error)); + expect().assertFail(); + }, 2000); + }); + }) + + /** + * @tc.number: Acts_ActionExtensionAbility_1000 + * @tc.name: Test ActionExtensionAbility basic function. + * @tc.desc: Test the startAbility interface in callback form. + */ + it('Acts_ActionExtensionAbility_1000',0, async function (done) { + var subscriber; + commonEvent.createSubscriber(ACTS_CallFunction).then(async (data) => { + console.info(`====>Acts_ActionExtensionAbility_1000 createSubscriber ${data}`) + subscriber = data + commonEvent.subscribe(data, subscribeCallBack) + globalThis.context.startAbility({ + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'EntryAbility', + action: 'Acts_ActionExtensionAbility_1000' + },(err) => { + console.info('====>Acts_ActionExtensionAbility_1000 startAbility err:' + JSON.stringify(err)); + }); + }) + + function subscribeCallBack(err, data) { + if(data.event == 'ACTS_CALL_EVENT') { + console.info(`====>Acts_ActionExtensionAbility_1000 subscribeCallBack 'ACTS_CALL_EVENT' ${data}`) + expect(data.parameters.num).assertEqual(0); + commonEvent.unsubscribe(subscriber, unSubscribeCallback); + } + } + + function unSubscribeCallback() { + console.info(`====>Acts_ActionExtensionAbility_1000 unSubscribeCallback 'ACTS_CALL_EVENT'`); + globalThis.terminate('Acts_ActionExtensionAbility_1000'); + setTimeout(() => { + done(); + }, 2000); + } + }) + + /** + * @tc.number: Acts_ActionExtensionAbility_1100 + * @tc.name: Test ActionExtensionAbility basic function. + * @tc.desc: Test the startAbility interface in promiss form. + */ + it('Acts_ActionExtensionAbility_1100',0, async function (done) { + var subscriber; + commonEvent.createSubscriber(ACTS_CallFunction).then(async (data) => { + console.info(`====>Acts_ActionExtensionAbility_1100 createSubscriber ${data}`) + subscriber = data; + commonEvent.subscribe(data, subscribeCallBack); + globalThis.context.startAbility({ + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'EntryAbility', + action: 'Acts_ActionExtensionAbility_1100' + },(err) => { + console.info('====>Acts_ActionExtensionAbility_1100 startAbility err:' + JSON.stringify(err)); + }); + }); + + function subscribeCallBack(err, data) { + if(data.event == 'ACTS_CALL_EVENT') { + console.info('====>Acts_ActionExtensionAbility_1100 subscribeCallBack ' + JSON.stringify(data)); + expect(data.parameters.str).assertEqual('success'); + commonEvent.unsubscribe(subscriber, unSubscribeCallback); + } + } + + function unSubscribeCallback() { + console.info(`====>Acts_ActionExtensionAbility_1100 unSubscribeCallback 'ACTS_CALL_EVENT'`); + globalThis.terminate('Acts_ActionExtensionAbility_1100'); + setTimeout(() => { + done(); + }, 2000); + } + }) + + /** + * @tc.number: Acts_ActionExtensionAbility_1200 + * @tc.name: Test ActionExtensionAbility basic function. + * @tc.desc: Test the startAbility interface with invalid want. + */ + it('Acts_ActionExtensionAbility_1200',0, async function (done) { + var subscriber; + commonEvent.createSubscriber(ACTS_CallFunction).then(async (data) => { + console.info(`====>Acts_ActionExtensionAbility_1200 createSubscriber ${data}`); + subscriber = data; + commonEvent.subscribe(data, subscribeCallBack); + globalThis.context.startAbility({ + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'EntryAbility', + action: 'Acts_ActionExtensionAbility_1200' + },(err) => { + console.info('====>Acts_ActionExtensionAbility_1200 startAbility err:' + JSON.stringify(err)); + }); + }); + + function subscribeCallBack(err, data) { + if(data.event == 'ACTS_CALL_EVENT') { + console.info('====>Acts_ActionExtensionAbility_1200 subscribeCallBack' + JSON.stringify(data)); + expect(data.parameters.num).assertEqual(16000001); + commonEvent.unsubscribe(subscriber, unSubscribeCallback); + } + } + + function unSubscribeCallback() { + console.info(`====>Acts_ActionExtensionAbility_1200 unSubscribeCallback 'ACTS_CALL_EVENT'`); + globalThis.terminate('Acts_ActionExtensionAbility_1200'); + setTimeout(() => { + done(); + }, 2000); + } + }) + + /** + * @tc.number: Acts_ActionExtensionAbility_1300 + * @tc.name: Test ActionExtensionAbility basic function. + * @tc.desc: Test the startAbilityForResult interface in callback form. + */ + it('Acts_ActionExtensionAbility_1300',0, async function (done) { + var subscriber; + commonEvent.createSubscriber(ACTS_CallFunction).then(async (data) => { + console.info(`====>Acts_ActionExtensionAbility_1300 createSubscriber ${data}`); + subscriber = data; + commonEvent.subscribe(data, subscribeCallBack); + globalThis.context.startAbility({ + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'EntryAbility', + action: 'Acts_ActionExtensionAbility_1300' + },(err) => { + console.info('====>Acts_ActionExtensionAbility_1300 startAbility err:' + JSON.stringify(err)); + }); + }); + + function subscribeCallBack(err, data) { + if(data.event == 'ACTS_CALL_EVENT') { + console.info(`====>Acts_ActionExtensionAbility_1300 subscribeCallBack 'ACTS_CALL_EVENT' ${data}`); + expect(data.parameters.str).assertEqual('ACTION'); + expect(data.parameters.result).assertEqual(0); + commonEvent.unsubscribe(subscriber, unSubscribeCallback); + } + }; + + function unSubscribeCallback() { + console.info(`====>Acts_ActionExtensionAbility_1300 unSubscribeCallback 'ACTS_CALL_EVENT'`); + globalThis.terminate('Acts_ActionExtensionAbility_1300'); + setTimeout(() => { + done(); + }, 2000); + } + }) + + /** + * @tc.number: Acts_ActionExtensionAbility_1400 + * @tc.name: Test ActionExtensionAbility basic function. + * @tc.desc: Test the startAbilityForResult interface in promiss form. + */ + it('Acts_ActionExtensionAbility_1400',0, async function (done) { + await Driver.create().delayMs(2000); + var subscriber; + commonEvent.createSubscriber(ACTS_CallFunction).then(async (data) => { + console.info(`====>Acts_ActionExtensionAbility_1400 createSubscriber ${data}`); + subscriber = data; + commonEvent.subscribe(data, subscribeCallBack); + globalThis.context.startAbility({ + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'EntryAbility', + action: 'Acts_ActionExtensionAbility_1400' + },(err) => { + console.info('====>Acts_ActionExtensionAbility_1400 startAbility err:' + JSON.stringify(err)); + }); + }); + + function subscribeCallBack(err, data) { + if(data.event == 'ACTS_CALL_EVENT') { + console.info(`====>Acts_ActionExtensionAbility_1400 subscribeCallBack 'ACTS_CALL_EVENT' ${data}`); + expect(data.parameters.str).assertEqual('ACTION'); + expect(data.parameters.result).assertEqual(0); + commonEvent.unsubscribe(subscriber, unSubscribeCallback); + } + } + + function unSubscribeCallback() { + console.info(`====>Acts_ActionExtensionAbility_1400 unSubscribeCallback 'ACTS_CALL_EVENT'`); + globalThis.terminate('Acts_ActionExtensionAbility_1400'); + setTimeout(() => { + done(); + }, 2000); + } + }) + + /** + * @tc.number: Acts_ActionExtensionAbility_1500 + * @tc.name: Test ActionExtensionAbility basic function. + * @tc.desc: Test the startAbilityForResult interface with invalid want. + */ + it('Acts_ActionExtensionAbility_1500',0, async function (done) { + await Driver.create().delayMs(2000); + var subscriber; + commonEvent.createSubscriber(ACTS_CallFunction).then(async (data) => { + console.info(`====>Acts_ActionExtensionAbility_1500 createSubscriber ${data}`); + subscriber = data; + commonEvent.subscribe(data, subscribeCallBack); + globalThis.context.startAbility({ + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'EntryAbility', + action: 'Acts_ActionExtensionAbility_1500' + },(err) => { + console.info('====>Acts_ActionExtensionAbility_1400 start Own Ability err:' + JSON.stringify(err)); + }); + }); + + function subscribeCallBack(err, data) { + console.info(`====>Acts_ActionExtensionAbility_1500 subscribeCallBack all ${data.event}`); + if(data.event == 'ACTS_CALL_EVENT') { + console.info(`====>Acts_ActionExtensionAbility_1500 subscribeCallBack 'ACTS_CALL_EVENT' ${data}`); + expect(data.parameters.num).assertEqual(16000001); + commonEvent.unsubscribe(subscriber, unSubscribeCallback); + } + } + + function unSubscribeCallback() { + console.info(`====>Acts_ActionExtensionAbility_1500 unSubscribeCallback 'ACTS_CALL_EVENT'`); + setTimeout(() => { + globalThis.terminate('Acts_ActionExtensionAbility_1500'); + done(); + }, 2000); + } + }) + + /** + * @tc.number: Acts_ActionExtensionAbility_1600 + * @tc.name: Test ActionExtensionAbility basic function. + * @tc.desc: Test setReceiveDataCallback successful. + */ + it('Acts_ActionExtensionAbility_1600',0, async function (done) { + await Driver.create().delayMs(2000); + var subscriber; + var subscribeInfo = { + events: ['setReceiveDataCallback'] + }; + await commonEvent.createSubscriber(subscribeInfo).then(async (data) => { + console.log("createSubscriber data : " + JSON.stringify(data)); + subscriber = data; + globalThis.context.startAbility({ + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'EntryAbility', + action: 'Acts_ActionExtensionAbility_1600' + }, (err) => { + expect(err.code).assertEqual(0); + }); + commonEvent.subscribe(subscriber, async (err, data) => { + console.log("SubscribeInfoCallback : " + JSON.stringify(data)); + if (data.event == 'setReceiveDataCallback') { + var resultCheck = { + name: { + test: 'actionExtensionTest' + } + }; + expect(JSON.stringify(data.parameters.result)).assertEqual(JSON.stringify(resultCheck)); + commonEvent.unsubscribe(subscriber, async (err, data) => { + globalThis.terminate('Acts_ActionExtensionAbility_1600'); + setTimeout(() => { + console.info(`====>Acts_ActionExtensionAbility_1600 unSubscribeCallback`); + done(); + }, 2000); + }); + } + }); + }); + }) + + /** + * @tc.number: Acts_ActionExtensionAbility_1700 + * @tc.name: Test ActionExtensionAbility basic function. + * @tc.desc: Use ui components continuously to start two ActionExtensionAbility. + */ + it('Acts_ActionExtensionAbility_1700',0, async function (done) { + await Driver.create().delayMs(2000); + globalThis.context.startAbility({ + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'EntryAbility', + action: 'Acts_ActionExtensionAbility_1700' + }, (err) => { + expect(err.code).assertEqual(0); + }); + await Driver.create().delayMs(2000); + await abilityDelegator.executeShellCommand('aa dump -a').then((data) => { + console.info('====>Acts_ActionExtensionAbility_1700 : data : ' + JSON.stringify(data.stdResult)); + try { + expect(JSON.stringify(data)).assertContain("main name [ActsActionExtensionAbility]"); + expect(JSON.stringify(data)).assertContain("main name [UIExtAbility]"); + } catch { + expect().assertFail(); + } + }); + globalThis.terminate('Acts_ActionExtensionAbility_1700'); + setTimeout(() => { + console.info(`====>Acts_ActionExtensionAbility_1700 unSubscribeCallback`); + done(); + }, 2000); + }) + + /** + * @tc.number: Acts_ActionExtensionAbility_1800 + * @tc.name: Test ActionExtensionAbility basic function. + * @tc.desc: Test starts ActionExtensionAbility using startAbility interface. + */ + it('Acts_ActionExtensionAbility_1800',0, async function (done) { + await Driver.create().delayMs(2000); + var subscriber; + var subscribeInfo = { + events: ['ACTS_CALL_EVENT'] + }; + await commonEvent.createSubscriber(subscribeInfo).then(async (data) => { + console.log("createSubscriber data : " + JSON.stringify(data)); + subscriber = data; + globalThis.context.startAbility({ + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'EntryAbility', + action: 'Acts_ActionExtensionAbility_1800' + }, (err) => { + expect(err.code).assertEqual(0); + }); + commonEvent.subscribe(subscriber, async (err, data) => { + console.log("SubscribeInfoCallback : " + JSON.stringify(data)); + if (data.event == 'ACTS_CALL_EVENT') { + await abilityDelegator.executeShellCommand('aa dump -a').then((data) => { + console.info('====>Acts_ActionExtensionAbility_1800 : data : ' + JSON.stringify(data.stdResult)); + try { + expect(JSON.stringify(data)).assertContain("main name [ActsActionExtensionAbility]"); + expect(JSON.stringify(data)).assertContain("main name [UIExtAbility]"); + } catch { + expect().assertFail(); + } + }); + commonEvent.unsubscribe(subscriber, async (err, data) => { + globalThis.terminate('Acts_ActionExtensionAbility_1800'); + setTimeout(() => { + console.info(`====>Acts_ActionExtensionAbility_1800 unSubscribeCallback`); + done(); + }, 2000); + }); + } + }); + }); + }) + + /** + * @tc.number: Acts_ActionExtensionAbility_1900 + * @tc.name: Test ActionExtensionAbility basic function. + * @tc.desc: Test hapModuleInfo in context + */ + it('Acts_ActionExtensionAbility_1900',0, async function (done) { + await Driver.create().delayMs(2000); + var subscriber; + var subscribeInfo = { + events: ['ACTS_TEST_CONTEXT'] + }; + await commonEvent.createSubscriber(subscribeInfo).then(async (data) => { + console.log("createSubscriber data : " + JSON.stringify(data)); + subscriber = data; + globalThis.context.startAbility(CONTEXT_WANT, (err) => { + expect(err.code).assertEqual(0); + }); + commonEvent.subscribe(subscriber, async (err, data) => { + console.log("SubscribeInfoCallback : " + JSON.stringify(data)); + if (data.event == 'ACTS_TEST_CONTEXT') { + try { + expect(data.parameters.context != null).assertTrue(); + var hapModuleInfo = data.parameters.context.currentHapModuleInfo; + expect(hapModuleInfo != null).assertTrue(); + console.log("====>Acts_ActionExtensionAbility_1900 hapModuleInfo : " + JSON.stringify(hapModuleInfo)); + console.log(`Acts_ActionExtensionAbility_1900 hapModuleInfo.name: ` + hapModuleInfo.name); + expect(hapModuleInfo.name == "entry").assertTrue(); + console.log(`Acts_ActionExtensionAbility_1900 hapModuleInfo.icon: ` + hapModuleInfo.icon); + expect(hapModuleInfo.icon == "$media:icon").assertTrue(); + console.log(`Acts_ActionExtensionAbility_1900 hapModuleInfo.iconId: ` + hapModuleInfo.iconId); + expect(typeof (hapModuleInfo.iconId) == 'number').assertTrue(); + console.log(`Acts_ActionExtensionAbility_1900 hapModuleInfo.label: ` + hapModuleInfo.label); + expect(hapModuleInfo.label == "$string:EntryAbility_label").assertTrue(); + console.log(`Acts_ActionExtensionAbility_1900 hapModuleInfo.labelId: ` + hapModuleInfo.labelId); + expect(typeof (hapModuleInfo.labelId) == 'number').assertTrue(); + console.log(`Acts_ActionExtensionAbility_1900 hapModuleInfo.description: ` + hapModuleInfo.description); + expect(hapModuleInfo.description == "$string:module_desc").assertTrue(); + console.log(`Acts_ActionExtensionAbility_1900 hapModuleInfo.descriptionId: ` + hapModuleInfo.descriptionId); + expect(typeof (hapModuleInfo.descriptionId) == 'number').assertTrue(); + console.log(`Acts_ActionExtensionAbility_1900 hapModuleInfo.mainElementName: ` + hapModuleInfo.mainElementName); + expect(hapModuleInfo.mainElementName == "EntryAbility").assertTrue(); + console.log(`Acts_ActionExtensionAbility_1900 hapModuleInfo.metadata: ` + hapModuleInfo.metadata.length); + expect(hapModuleInfo.metadata.length >= 0).assertTrue(); + + console.log(`Acts_ActionExtensionAbility_1900 success`); + setTimeout(async () => { + commonEvent.unsubscribe(subscriber, async (err, data) => { + globalThis.terminate('Acts_ActionExtensionAbility_1900'); + setTimeout(() => { + console.info(`====>Acts_ActionExtensionAbility_1900 unSubscribeCallback`); + done(); + }, 2000); + }); + }, 1000); + } catch (err) { + globalThis.terminate('Acts_ActionExtensionAbility_1900'); + setTimeout(() => { + console.log(`Acts_ActionExtensionAbility_1900 fail: ` + err); + expect().assertFail(); + }, 2000); + } + } + }); + }); + }) + + /** + * @tc.number: Acts_ActionExtensionAbility_2000 + * @tc.name: Test ActionExtensionAbility basic function. + * @tc.desc: Test config in context + */ + it('Acts_ActionExtensionAbility_2000',0, async function (done) { + await Driver.create().delayMs(2000); + var subscriber; + var subscribeInfo = { + events: ['ACTS_TEST_CONTEXT'] + }; + await commonEvent.createSubscriber(subscribeInfo).then(async (data) => { + console.log("createSubscriber data : " + JSON.stringify(data)); + subscriber = data; + globalThis.context.startAbility(CONTEXT_WANT, (err) => { + expect(err.code).assertEqual(0); + }); + commonEvent.subscribe(subscriber, async (err, data) => { + console.log("SubscribeInfoCallback : " + JSON.stringify(data)); + if (data.event == 'ACTS_TEST_CONTEXT') { + try { + expect(data.parameters.context != null).assertTrue(); + expect(data.parameters.context != null).assertTrue(); + var config = data.parameters.context.config; + expect(config != null).assertTrue(); + console.log(`Acts_ActionExtensionAbility_2000 config.colorMode: ` + config.colorMode); + expect(typeof (config.colorMode) == 'number').assertTrue(); + console.log(`Acts_ActionExtensionAbility_2000 config.direction: ` + config.direction); + expect(typeof (config.direction) == 'number').assertTrue(); + console.log(`Acts_ActionExtensionAbility_2000 success`); + setTimeout(async () => { + commonEvent.unsubscribe(subscriber, async (err, data) => { + globalThis.terminate('Acts_ActionExtensionAbility_2000'); + setTimeout(() => { + console.info(`====>Acts_ActionExtensionAbility_2000 unSubscribeCallback`); + done(); + }, 2000); + }); + }, 1000); + } catch (err) { + globalThis.terminate('Acts_ActionExtensionAbility_2000'); + setTimeout(() => { + console.log(`Acts_ActionExtensionAbility_2000 fail: ` + err); + expect().assertFail(); + }, 2000); + } + } + }); + }); + }) + + /** + * @tc.number: Acts_ActionExtensionAbility_2100 + * @tc.name: Test ActionExtensionAbility basic function. + * @tc.desc: Test extensionAbilityInfo in context + */ + it('Acts_ActionExtensionAbility_2100',0, async function (done) { + await Driver.create().delayMs(2000); + var subscriber; + var subscribeInfo = { + events: ['ACTS_TEST_CONTEXT'] + }; + await commonEvent.createSubscriber(subscribeInfo).then(async (data) => { + console.log("createSubscriber data : " + JSON.stringify(data)); + subscriber = data; + globalThis.context.startAbility(CONTEXT_WANT, (err) => { + expect(err.code).assertEqual(0); + }); + commonEvent.subscribe(subscriber, async (err, data) => { + console.log("SubscribeInfoCallback : " + JSON.stringify(data)); + if (data.event == 'ACTS_TEST_CONTEXT') { + try { + expect(data.parameters.context != null).assertTrue(); + var extensionAbilityInfo = data.parameters.context.extensionAbilityInfo; + expect(extensionAbilityInfo != null).assertTrue(); + console.log(`Acts_ActionExtensionAbility_2100 extensionAbilityInfo: ` + JSON.stringify(extensionAbilityInfo)); + expect(extensionAbilityInfo.bundleName == 'com.example.actsactionextensionabilitytest').assertTrue(); + console.log(`extensionAbilityInfo.descriptionId: ` + JSON.stringify(extensionAbilityInfo.descriptionId)); + expect(typeof (extensionAbilityInfo.descriptionId) == 'number').assertTrue(); + console.log(`extensionAbilityInfo.enabled: ` + JSON.stringify(extensionAbilityInfo.enabled)); + expect(typeof (extensionAbilityInfo.enabled) == 'boolean').assertTrue(); + console.log(`extensionAbilityInfo.exported: ` + JSON.stringify(extensionAbilityInfo.exported)); + expect(typeof (extensionAbilityInfo.exported) == 'boolean').assertTrue(); + console.log(`extensionAbilityInfo.extensionAbilityType: ` + JSON.stringify(extensionAbilityInfo.extensionAbilityType)); + expect(extensionAbilityInfo.extensionAbilityType == 19).assertTrue(); + console.log(`extensionAbilityInfo.iconId: ` + JSON.stringify(extensionAbilityInfo.iconId)); + expect(typeof (extensionAbilityInfo.iconId) == 'number').assertTrue(); + console.log(`extensionAbilityInfo.isVisible: ` + JSON.stringify(extensionAbilityInfo.isVisible)); + expect(typeof (extensionAbilityInfo.isVisible) == 'boolean').assertTrue(); + console.log(`extensionAbilityInfo.labelId: ` + JSON.stringify(extensionAbilityInfo.labelId)); + expect(typeof (extensionAbilityInfo.labelId) == 'number').assertTrue(); + console.log(`extensionAbilityInfo.moduleName: ` + JSON.stringify(extensionAbilityInfo.moduleName)); + expect(extensionAbilityInfo.moduleName == 'entry').assertTrue(); + console.log(`extensionAbilityInfo.name: ` + JSON.stringify(extensionAbilityInfo.name)); + expect(extensionAbilityInfo.name == 'UIExtAbility').assertTrue(); + setTimeout(async () => { + commonEvent.unsubscribe(subscriber, async (err, data) => { + globalThis.terminate('Acts_ActionExtensionAbility_2100'); + setTimeout(() => { + console.info(`====>Acts_ActionExtensionAbility_2100 unSubscribeCallback`); + done(); + }, 2000); + }); + }, 1000); + } catch (err) { + globalThis.terminate('Acts_ActionExtensionAbility_2100'); + setTimeout(() => { + console.log(`Acts_ActionExtensionAbility_2100 fail: ` + err); + expect().assertFail(); + }, 2000); + } + } + }); + }); + }) + + /** + * @tc.number: Acts_ActionExtensionAbility_2200 + * @tc.name: Test ActionExtensionAbility basic function. + * @tc.desc: Test resourceManager in context + */ + it('Acts_ActionExtensionAbility_2200', 0, async function (done) { + await Driver.create().delayMs(2000); + var subscriber; + var subscribeInfo = { + events: ['ACTS_CALL_EVENT'] + }; + + await commonEvent.createSubscriber(subscribeInfo).then(async (data) => { + console.log("createSubscriber data : " + JSON.stringify(data)); + subscriber = data; + globalThis.context.startAbility({ + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'EntryAbility', + action: 'Acts_ActionExtensionAbility_2200' + }, (err) => { + expect(err.code).assertEqual(0); + }); + commonEvent.subscribe(subscriber, async (err, data) => { + console.log("SubscribeInfoCallback : " + JSON.stringify(data)); + if (data.event == 'ACTS_CALL_EVENT') { + expect(data.parameters.resourceManager != null).assertTrue(); + console.log('Acts_ActionExtensionAbility_2200 success'); + commonEvent.unsubscribe(subscriber, async (err, data) => { + globalThis.terminate('Acts_ActionExtensionAbility_2200'); + setTimeout(() => { + console.info(`====>Acts_ActionExtensionAbility_2200 unSubscribeCallback`); + done(); + }, 2000); + }); + } + }); + }); + }) + + /** + * @tc.number: Acts_ActionExtensionAbility_2300 + * @tc.name: Test ActionExtensionAbility basic function. + * @tc.desc: Test applicationInfo in context + */ + it('Acts_ActionExtensionAbility_2300', 0, async function (done) { + await Driver.create().delayMs(2000); + var subscriber; + var subscribeInfo = { + events: ['ACTS_CALL_EVENT'] + }; + + await commonEvent.createSubscriber(subscribeInfo).then(async (data) => { + console.log("createSubscriber data : " + JSON.stringify(data)); + subscriber = data; + globalThis.context.startAbility({ + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'EntryAbility', + action: 'Acts_ActionExtensionAbility_2300' + }, (err) => { + expect(err.code).assertEqual(0); + }); + commonEvent.subscribe(subscriber, async (err, data) => { + console.log("SubscribeInfoCallback : " + JSON.stringify(data)); + if (data.event == 'ACTS_CALL_EVENT') { + console.log(`Acts_ActionExtensionAbility_2300 applicationInfo.name: ` + data.parameters.name); + expect(data.parameters.name == 'com.example.actsactionextensionabilitytest').assertTrue(); + console.log(`Acts_ActionExtensionAbility_2300 applicationInfo.description: ` + data.parameters.description_length); + expect(data.parameters.description_length >= 0).assertTrue(); + console.log(`Acts_ActionExtensionAbility_2300 applicationInfo.descriptionId: ` + data.parameters.descriptionId); + expect(data.parameters.descriptionId == 0).assertTrue(); + console.log(`Acts_ActionExtensionAbility_2300 applicationInfo.label: ` + data.parameters.label); + expect(data.parameters.label == '$string:app_name').assertTrue(); + console.log(`Acts_ActionExtensionAbility_2300 applicationInfo.labelId: ` + data.parameters.labelId); + expect(data.parameters.labelId != null).assertTrue(); + console.log(`Acts_ActionExtensionAbility_2300 applicationInfo.icon: ` + data.parameters.icon); + expect(data.parameters.icon == '$media:app_icon').assertTrue(); + console.log(`Acts_ActionExtensionAbility_2300 applicationInfo.iconId: ` + data.parameters.iconId); + expect(data.parameters.iconId != null).assertTrue(); + console.log(`Acts_ActionExtensionAbility_2300 applicationInfo.codePath: ` + data.parameters.codePath); + expect(data.parameters.codePath == 'string').assertTrue(); + console.log(`Acts_ActionExtensionAbility_2300 success`); + + commonEvent.unsubscribe(subscriber, async (err, data) => { + globalThis.terminate('Acts_ActionExtensionAbility_2300'); + setTimeout(() => { + console.info(`====>Acts_ActionExtensionAbility_2300 unSubscribeCallback`); + done(); + }, 2000); + }); + } + }); + }); + }) + + /** + * @tc.number: Acts_ActionExtensionAbility_2400 + * @tc.name: Test ActionExtensionAbility basic function. + * @tc.desc: Test cacheDir in context + */ + it('Acts_ActionExtensionAbility_2400', 0, async function (done) { + await Driver.create().delayMs(2000); + var subscriber; + var subscribeInfo = { + events: ['ACTS_CALL_EVENT'] + }; + + await commonEvent.createSubscriber(subscribeInfo).then(async (data) => { + console.log("createSubscriber data : " + JSON.stringify(data)); + subscriber = data; + globalThis.context.startAbility({ + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'EntryAbility', + action: 'Acts_ActionExtensionAbility_2400' + }, (err) => { + expect(err.code).assertEqual(0); + }); + commonEvent.subscribe(subscriber, async (err, data) => { + console.log("SubscribeInfoCallback : " + JSON.stringify(data)); + if (data.event == 'ACTS_CALL_EVENT') { + let cacheDir = data.parameters.cacheDir; + console.log(`Acts_ActionExtensionAbility_2400 cacheDir:` + cacheDir); + expect(typeof (cacheDir) == 'string').assertTrue(); + console.log(`Acts_ActionExtensionAbility_2400 success`); + + commonEvent.unsubscribe(subscriber, async (err, data) => { + globalThis.terminate('Acts_ActionExtensionAbility_2400'); + setTimeout(() => { + console.info(`====>Acts_ActionExtensionAbility_2400 unSubscribeCallback`); + done(); + }, 2000); + }); + } + }); + }); + }) + + /** + * @tc.number: Acts_ActionExtensionAbility_2500 + * @tc.name: Test ActionExtensionAbility basic function. + * @tc.desc: Test tempDir in context + */ + it('Acts_ActionExtensionAbility_2500', 0, async function (done) { + await Driver.create().delayMs(2000); + var subscriber; + var subscribeInfo = { + events: ['ACTS_CALL_EVENT'] + }; + + await commonEvent.createSubscriber(subscribeInfo).then(async (data) => { + console.log("createSubscriber data : " + JSON.stringify(data)); + subscriber = data; + globalThis.context.startAbility({ + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'EntryAbility', + action: 'Acts_ActionExtensionAbility_2500' + }, (err) => { + expect(err.code).assertEqual(0); + }); + commonEvent.subscribe(subscriber, async (err, data) => { + console.log("SubscribeInfoCallback : " + JSON.stringify(data)); + if (data.event == 'ACTS_CALL_EVENT') { + let tempDir = data.parameters.tempDir; + console.log(`Acts_ActionExtensionAbility_2500 tempDir:` + tempDir); + expect(typeof (tempDir) == 'string').assertTrue(); + console.log(`Acts_ActionExtensionAbility_2500 success`); + + commonEvent.unsubscribe(subscriber, async (err, data) => { + globalThis.terminate('Acts_ActionExtensionAbility_2500'); + setTimeout(() => { + console.info(`====>Acts_ActionExtensionAbility_2500 unSubscribeCallback`); + done(); + }, 2000); + }); + } + }); + }); + }) + + /** + * @tc.number: Acts_ActionExtensionAbility_2600 + * @tc.name: Test ActionExtensionAbility basic function. + * @tc.desc: Test filesDir in context + */ + it('Acts_ActionExtensionAbility_2600', 0, async function (done) { + await Driver.create().delayMs(2000); + var subscriber; + var subscribeInfo = { + events: ['ACTS_CALL_EVENT'] + }; + + await commonEvent.createSubscriber(subscribeInfo).then(async (data) => { + console.log("createSubscriber data : " + JSON.stringify(data)); + subscriber = data; + globalThis.context.startAbility({ + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'EntryAbility', + action: 'Acts_ActionExtensionAbility_2600' + }, (err) => { + expect(err.code).assertEqual(0); + }); + commonEvent.subscribe(subscriber, async (err, data) => { + console.log("SubscribeInfoCallback : " + JSON.stringify(data)); + if (data.event == 'ACTS_CALL_EVENT') { + let filesDir = data.parameters.filesDir; + console.log(`Acts_ActionExtensionAbility_2600 filesDir:` + filesDir); + expect(typeof (filesDir) == 'string').assertTrue(); + console.log(`Acts_ActionExtensionAbility_2600 success`); + commonEvent.unsubscribe(subscriber, async (err, data) => { + globalThis.terminate('Acts_ActionExtensionAbility_2600'); + setTimeout(() => { + console.info(`====>Acts_ActionExtensionAbility_2600 unSubscribeCallback`); + done(); + }, 2000); + }); + } + }); + }); + }) + + /** + * @tc.number: Acts_ActionExtensionAbility_2700 + * @tc.name: Test ActionExtensionAbility basic function. + * @tc.desc: Test databaseDir in context + */ + it('Acts_ActionExtensionAbility_2700', 0, async function (done) { + await Driver.create().delayMs(2000); + var subscriber; + var subscribeInfo = { + events: ['ACTS_CALL_EVENT'] + }; + + await commonEvent.createSubscriber(subscribeInfo).then(async (data) => { + console.log("createSubscriber data : " + JSON.stringify(data)); + subscriber = data; + globalThis.context.startAbility({ + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'EntryAbility', + action: 'Acts_ActionExtensionAbility_2700' + }, (err) => { + expect(err.code).assertEqual(0); + }); + commonEvent.subscribe(subscriber, async (err, data) => { + console.log("SubscribeInfoCallback : " + JSON.stringify(data)); + if (data.event == 'ACTS_CALL_EVENT') { + let databaseDir = data.parameters.databaseDir; + console.log(`Acts_ActionExtensionAbility_2700 databaseDir:` + databaseDir); + expect(typeof (databaseDir) == 'string').assertTrue(); + console.log(`Acts_ActionExtensionAbility_2700 success`); + commonEvent.unsubscribe(subscriber, async (err, data) => { + globalThis.terminate('Acts_ActionExtensionAbility_2700'); + setTimeout(() => { + console.info(`====>Acts_ActionExtensionAbility_2700 unSubscribeCallback`); + done(); + }, 2000); + }); + } + }); + }); + }) + + /** + * @tc.number: Acts_ActionExtensionAbility_2800 + * @tc.name: Test ActionExtensionAbility basic function. + * @tc.desc: Test preferencesDir in context + */ + it('Acts_ActionExtensionAbility_2800', 0, async function (done) { + await Driver.create().delayMs(2000); + var subscriber; + var subscribeInfo = { + events: ['ACTS_CALL_EVENT'] + }; + + await commonEvent.createSubscriber(subscribeInfo).then(async (data) => { + console.log("createSubscriber data : " + JSON.stringify(data)); + subscriber = data; + globalThis.context.startAbility({ + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'EntryAbility', + action: 'Acts_ActionExtensionAbility_2800' + }, (err) => { + expect(err.code).assertEqual(0); + }); + commonEvent.subscribe(subscriber, async (err, data) => { + console.log("SubscribeInfoCallback : " + JSON.stringify(data)); + if (data.event == 'ACTS_CALL_EVENT') { + let preferencesDir = data.parameters.preferencesDir; + console.log(`Acts_ActionExtensionAbility_2800 preferencesDir:` + preferencesDir); + expect(typeof (preferencesDir) == 'string').assertTrue(); + console.log(`Acts_ActionExtensionAbility_2800 success`); + + commonEvent.unsubscribe(subscriber, async (err, data) => { + globalThis.terminate('Acts_ActionExtensionAbility_2800'); + setTimeout(() => { + console.info(`====>Acts_ActionExtensionAbility_2800 unSubscribeCallback`); + done(); + }, 2000); + }); + } + }); + }); + }) + + /** + * @tc.number: Acts_ActionExtensionAbility_2900 + * @tc.name: Test ActionExtensionAbility basic function. + * @tc.desc: Test bundleCodeDir in context + */ + it('Acts_ActionExtensionAbility_2900', 0, async function (done) { + await Driver.create().delayMs(2000); + var subscriber; + var subscribeInfo = { + events: ['ACTS_CALL_EVENT'] + }; + + await commonEvent.createSubscriber(subscribeInfo).then(async (data) => { + console.log("createSubscriber data : " + JSON.stringify(data)); + subscriber = data; + globalThis.context.startAbility({ + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'EntryAbility', + action: 'Acts_ActionExtensionAbility_2900' + }, (err) => { + expect(err.code).assertEqual(0); + }); + commonEvent.subscribe(subscriber, async (err, data) => { + console.log("SubscribeInfoCallback : " + JSON.stringify(data)); + if (data.event == 'ACTS_CALL_EVENT') { + let bundleCodeDir = data.parameters.bundleCodeDir; + console.log(`Acts_ActionExtensionAbility_2900 bundleCodeDir:` + bundleCodeDir); + expect(typeof (bundleCodeDir) == 'string').assertTrue(); + console.log(`Acts_ActionExtensionAbility_2900 success`); + + commonEvent.unsubscribe(subscriber, async (err, data) => { + globalThis.terminate('Acts_ActionExtensionAbility_2900'); + setTimeout(() => { + console.info(`====>Acts_ActionExtensionAbility_2900 unSubscribeCallback`); + done(); + }, 2000); + }); + } + }); + }); + }) + + /** + * @tc.number: Acts_ActionExtensionAbility_3000 + * @tc.name: Test ActionExtensionAbility basic function. + * @tc.desc: Context calls createModuleContext, passing in the moduleName of the current application hap1 + */ + it('Acts_ActionExtensionAbility_3000',0, async function (done) { + await Driver.create().delayMs(2000); + var subscriber; + var subscribeInfo = { + events: ['ACTS_TEST_CONTEXT'] + }; + await commonEvent.createSubscriber(subscribeInfo).then(async (data) => { + console.log("createSubscriber data : " + JSON.stringify(data)); + subscriber = data; + globalThis.context.startAbility({ + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'EntryAbility', + action: 'Acts_ActionExtensionAbility_3000' + }, (err) => { + expect(err.code).assertEqual(0); + }); + commonEvent.subscribe(subscriber, async (err, data) => { + console.log("SubscribeInfoCallback : " + JSON.stringify(data)); + if (data.event == 'ACTS_TEST_CONTEXT') { + try { + expect(data.parameters.bundleName != null).assertTrue(); + expect(data.parameters.bundleName).assertEqual("com.example.actsactionextensionabilitytest"); + setTimeout(async () => { + commonEvent.unsubscribe(subscriber, async (err, data) => { + globalThis.terminate('Acts_ActionExtensionAbility_3000'); + setTimeout(() => { + console.info(`====>Acts_ActionExtensionAbility_3000 unSubscribeCallback`); + done(); + }, 2000); + }); + }, 1000); + } catch (err) { + globalThis.terminate('Acts_ActionExtensionAbility_3000'); + setTimeout(() => { + console.log(`Acts_ActionExtensionAbility_3000 fail: ` + err); + expect().assertFail(); + }, 2000); + } + } + }); + }); + }) + + /** + * @tc.number: Acts_ActionExtensionAbility_3100 + * @tc.name: Test ActionExtensionAbility basic function. + * @tc.desc: Context calls createModuleContext, passing in the moduleName of the current application hap2 + */ + it('Acts_ActionExtensionAbility_3100',0, async function (done) { + await Driver.create().delayMs(2000); + var subscriber; + var subscribeInfo = { + events: ['ACTS_TEST_CONTEXT'] + }; + await commonEvent.createSubscriber(subscribeInfo).then(async (data) => { + console.log("createSubscriber data : " + JSON.stringify(data)); + subscriber = data; + globalThis.context.startAbility({ + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'EntryAbility', + action: 'Acts_ActionExtensionAbility_3100' + }, (err) => { + expect(err.code).assertEqual(0); + }); + commonEvent.subscribe(subscriber, async (err, data) => { + console.log("SubscribeInfoCallback : " + JSON.stringify(data)); + if (data.event == 'ACTS_TEST_CONTEXT') { + try { + expect(data.parameters.bundleName != null).assertTrue(); + expect(data.parameters.bundleName).assertEqual("com.example.actsactionextensionabilitytest"); + setTimeout(async () => { + commonEvent.unsubscribe(subscriber, async (err, data) => { + globalThis.terminate('Acts_ActionExtensionAbility_3000'); + setTimeout(() => { + console.info(`====>Acts_ActionExtensionAbility_3000 unSubscribeCallback`); + done(); + }, 2000); + }); + }, 1000); + } catch (err) { + globalThis.terminate('Acts_ActionExtensionAbility_3100'); + setTimeout(() => { + console.log(`Acts_ActionExtensionAbility_3100 fail: ` + err); + expect().assertFail(); + }, 2000); + } + } + }); + }); + }) + + /** + * @tc.number: Acts_ActionExtensionAbility_3200 + * @tc.name: Test ActionExtensionAbility basic function. + * @tc.desc: Context calls createModuleContext, passing in the moduleName of the cross-application hap1 + */ + it('Acts_ActionExtensionAbility_3200',0, async function (done) { + await Driver.create().delayMs(2000); + var subscriber; + var subscribeInfo = { + events: ['ACTS_TEST_CONTEXT'] + }; + await commonEvent.createSubscriber(subscribeInfo).then(async (data) => { + console.log("createSubscriber data : " + JSON.stringify(data)); + subscriber = data; + globalThis.context.startAbility({ + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'EntryAbility', + action: 'Acts_ActionExtensionAbility_3200' + }, (err) => { + expect(err.code).assertEqual(0); + }); + commonEvent.subscribe(subscriber, async (err, data) => { + console.log("SubscribeInfoCallback : " + JSON.stringify(data)); + if (data.event == 'ACTS_TEST_CONTEXT') { + try { + expect(!data.parameters.moduleContext).assertTrue(); + setTimeout(async () => { + commonEvent.unsubscribe(subscriber, async (err, data) => { + globalThis.terminate('Acts_ActionExtensionAbility_3200'); + setTimeout(() => { + console.info(`====>Acts_ActionExtensionAbility_3200 unSubscribeCallback`); + done(); + }, 2000); + }); + }, 1000); + } catch (err) { + globalThis.terminate('Acts_ActionExtensionAbility_3200'); + setTimeout(() => { + console.log(`Acts_ActionExtensionAbility_3200 fail: ` + err); + expect().assertFail(); + }, 2000); + } + } + }); + }); + }) + + /** + * @tc.number: Acts_ActionExtensionAbility_3300 + * @tc.name: Test ActionExtensionAbility basic function. + * @tc.desc: Context calls createModuleContext, passing in a non-existing moduleName + */ + it('Acts_ActionExtensionAbility_3300',0, async function (done) { + await Driver.create().delayMs(2000); + var subscriber; + var subscribeInfo = { + events: ['ACTS_TEST_CONTEXT'] + }; + await commonEvent.createSubscriber(subscribeInfo).then(async (data) => { + console.log("createSubscriber data : " + JSON.stringify(data)); + subscriber = data; + globalThis.context.startAbility({ + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'EntryAbility', + action: 'Acts_ActionExtensionAbility_3300' + }, (err) => { + expect(err.code).assertEqual(0); + }); + commonEvent.subscribe(subscriber, async (err, data) => { + console.log("SubscribeInfoCallback : " + JSON.stringify(data)); + if (data.event == 'ACTS_TEST_CONTEXT') { + try { + expect(!data.parameters.moduleContext).assertTrue(); + setTimeout(async () => { + commonEvent.unsubscribe(subscriber, async (err, data) => { + globalThis.terminate('Acts_ActionExtensionAbility_3300'); + setTimeout(() => { + console.info(`====>Acts_ActionExtensionAbility_3300 unSubscribeCallback`); + done(); + }, 2000); + }); + }, 1000); + } catch (err) { + globalThis.terminate('Acts_ActionExtensionAbility_3300'); + setTimeout(() => { + console.log(`Acts_ActionExtensionAbility_3300 fail: ` + err); + expect().assertFail(); + }, 2000); + } + } + }); + }); + }) + + /** + * @tc.number: Acts_ActionExtensionAbility_3400 + * @tc.name: Test ActionExtensionAbility basic function. + * @tc.desc: Context calls createModuleContext, and the incoming moduleName is undefined + */ + it('Acts_ActionExtensionAbility_3400',0, async function (done) { + await Driver.create().delayMs(2000); + var subscriber; + var subscribeInfo = { + events: ['ACTS_TEST_CONTEXT'] + }; + await commonEvent.createSubscriber(subscribeInfo).then(async (data) => { + console.log("createSubscriber data : " + JSON.stringify(data)); + subscriber = data; + globalThis.context.startAbility({ + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'EntryAbility', + action: 'Acts_ActionExtensionAbility_3400' + }, (err) => { + expect(err.code).assertEqual(0); + }); + commonEvent.subscribe(subscriber, async (err, data) => { + console.log("SubscribeInfoCallback : " + JSON.stringify(data)); + if (data.event == 'ACTS_TEST_CONTEXT') { + try { + expect(!data.parameters.moduleContext).assertTrue(); + setTimeout(async () => { + commonEvent.unsubscribe(subscriber, async (err, data) => { + globalThis.terminate('Acts_ActionExtensionAbility_3400'); + setTimeout(() => { + console.info(`====>Acts_ActionExtensionAbility_3400 unSubscribeCallback`); + done(); + }, 2000); + }); + }, 1000); + } catch (err) { + globalThis.terminate('Acts_ActionExtensionAbility_3400'); + setTimeout(() => { + console.log(`Acts_ActionExtensionAbility_3400 fail: ` + err); + expect().assertFail(); + }, 2000); + } + } + }); + }); + }) + + /** + * @tc.number: Acts_ActionExtensionAbility_3500 + * @tc.name: Test ActionExtensionAbility basic function. + * @tc.desc: test getApplicationContext return not empty + */ + it('Acts_ActionExtensionAbility_3500',0, async function (done) { + await Driver.create().delayMs(2000); + var subscriber; + var subscribeInfo = { + events: ['ACTS_TEST_CONTEXT'] + }; + await commonEvent.createSubscriber(subscribeInfo).then(async (data) => { + console.log("createSubscriber data : " + JSON.stringify(data)); + subscriber = data; + globalThis.context.startAbility({ + bundleName: 'com.example.actsactionextensionabilitytest', + abilityName: 'EntryAbility', + action: 'Acts_ActionExtensionAbility_3500' + }, (err) => { + expect(err.code).assertEqual(0); + }); + commonEvent.subscribe(subscriber, async (err, data) => { + console.log("SubscribeInfoCallback : " + JSON.stringify(data)); + if (data.event == 'ACTS_TEST_CONTEXT') { + try { + expect(data.parameters.applicationContext != null).assertTrue(); + setTimeout(async () => { + commonEvent.unsubscribe(subscriber, async (err, data) => { + globalThis.terminate('Acts_ActionExtensionAbility_3500'); + setTimeout(() => { + console.info(`====>Acts_ActionExtensionAbility_3500 unSubscribeCallback`); + done(); + }, 2000); + }); + }, 1000); + } catch (err) { + globalThis.terminate('Acts_ActionExtensionAbility_3500'); + setTimeout(() => { + console.log(`Acts_ActionExtensionAbility_3500 fail: ` + err); + expect().assertFail(); + }, 2000); + } + } + }); + }); + }) + }) +} \ No newline at end of file diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilitytest/entry/src/main/ets/test/List.test.ets b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilitytest/entry/src/main/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f133cdf57d2447ffd6d0adf3f0fefb11d8b87eed --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilitytest/entry/src/main/ets/test/List.test.ets @@ -0,0 +1,19 @@ +/* + * 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 abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilitytest/entry/src/main/ets/testability/TestAbility.ets b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilitytest/entry/src/main/ets/testability/TestAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..3f8a95b41e00274e9b3cedcd9cadf1b77f8f150b --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilitytest/entry/src/main/ets/testability/TestAbility.ets @@ -0,0 +1,63 @@ +/* + * 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) ?? ''); + globalThis.context = this.context; + 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) ?? ''); + }); + } + + 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/ability_runtime/actsactionextensionability/actsactionextensionabilitytest/entry/src/main/ets/testability/pages/Index.ets b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilitytest/entry/src/main/ets/testability/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..8d97b5c218570b4abb8530db2e8cdabeb157a70c --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilitytest/entry/src/main/ets/testability/pages/Index.ets @@ -0,0 +1,48 @@ +/* + * 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/ability_runtime/actsactionextensionability/actsactionextensionabilitytest/entry/src/main/module.json b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilitytest/entry/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..83894d37b71428d6a6a0c5041faf88568d249b16 --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilitytest/entry/src/main/module.json @@ -0,0 +1,41 @@ +{ + "module": { + "name": "entry_test", + "type": "feature", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "default" + ], + "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" + ] + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.START_ABILITIES_FROM_BACKGROUND" + } + ] + } +} diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilitytest/entry/src/main/resources/base/element/color.json b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilitytest/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilitytest/entry/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/ability_runtime/actsactionextensionability/actsactionextensionabilitytest/entry/src/main/resources/base/element/string.json b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilitytest/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..65d8fa5a7cf54aa3943dcd0214f58d1771bc1f6c --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilitytest/entry/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/ability_runtime/actsactionextensionability/actsactionextensionabilitytest/entry/src/main/resources/base/media/icon.png b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilitytest/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilitytest/entry/src/main/resources/base/media/icon.png differ diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilitytest/entry/src/main/resources/base/profile/test_pages.json b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilitytest/entry/src/main/resources/base/profile/test_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..b7e7343cacb32ce982a45e76daad86e435e054fe --- /dev/null +++ b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilitytest/entry/src/main/resources/base/profile/test_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "testability/pages/Index" + ] +} diff --git a/ability/ability_runtime/actsactionextensionability/actsactionextensionabilitytest/signature/openharmony_sx.p7b b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilitytest/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..1528e8b94770f99bd9c2235b86ce4bf72623bdcd Binary files /dev/null and b/ability/ability_runtime/actsactionextensionability/actsactionextensionabilitytest/signature/openharmony_sx.p7b differ