diff --git a/ability/ability_runtime/BUILD.gn b/ability/ability_runtime/BUILD.gn index b5a7cce5e55260c2dd424c5524d1c5255b8ff1a2..d03507b9b177323a24ecb7e9d7d79850f4ab99e2 100644 --- a/ability/ability_runtime/BUILD.gn +++ b/ability/ability_runtime/BUILD.gn @@ -29,6 +29,7 @@ group("ability_runtime") { "actscalltest:actscalltest", "actscrosscall:actscrosscall", "actsdataabilityaccessdatasharetest:dataabilityaccessdatashare", + "actsforresult:actsforresult", "actsfwkdataaccessortest:dataability", "actsmultiplecall:actsmultiplecall", "actsnfcselecttypes:actsnfcselecttypes", diff --git a/ability/ability_runtime/actsforresult/BUILD.gn b/ability/ability_runtime/actsforresult/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..ce2bea86afdb9768e24952c8aad262f27a400353 --- /dev/null +++ b/ability/ability_runtime/actsforresult/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("actsforresult") { + testonly = true + if (is_standard_system) { + deps = [ + "forresulttest:forresulttest", + "forresulttestnopermission:forresulttestnopermission", + "main:main", + "maintest:maintest", + ] + } +} diff --git a/ability/ability_runtime/actsforresult/forresulttest/AppScope/app.json b/ability/ability_runtime/actsforresult/forresulttest/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..e41282a67d0a289854cc56580dcb6283a1a552d3 --- /dev/null +++ b/ability/ability_runtime/actsforresult/forresulttest/AppScope/app.json @@ -0,0 +1,19 @@ +{ + "app": { + "bundleName": "com.example.forresulttestsecond", + "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/actsforresult/forresulttest/AppScope/resources/base/element/string.json b/ability/ability_runtime/actsforresult/forresulttest/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..d71e5ead1ce20b4ac3384d18e6d104f1ea4d83b4 --- /dev/null +++ b/ability/ability_runtime/actsforresult/forresulttest/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "MyApplication" + } + ] +} diff --git a/ability/ability_runtime/actsforresult/forresulttest/AppScope/resources/base/media/app_icon.png b/ability/ability_runtime/actsforresult/forresulttest/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ability/ability_runtime/actsforresult/forresulttest/AppScope/resources/base/media/app_icon.png differ diff --git a/ability/ability_runtime/actsforresult/forresulttest/BUILD.gn b/ability/ability_runtime/actsforresult/forresulttest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..483d5d3622ac04b0ea443c56c3c835ad7c19c004 --- /dev/null +++ b/ability/ability_runtime/actsforresult/forresulttest/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("forresulttest") { + hap_profile = "entry/src/main/module.json" + js_build_mode = "debug" + deps = [ + ":forresulttest_js_assets", + ":forresulttest_resources", + ] + ets2abc = true + certificate_profile = "signature/openharmony_sx.p7b" + hap_name = "forresulttest" + subsystem_name = "ability" + part_name = "ability_runtime" +} + +ohos_app_scope("forresulttest_app_profile") { + app_profile = "AppScope/app.json" + sources = [ "AppScope/resources" ] +} + +ohos_js_assets("forresulttest_js_assets") { + source_dir = "entry/src/main/ets" +} + +ohos_resources("forresulttest_resources") { + sources = [ "entry/src/main/resources" ] + deps = [ ":forresulttest_app_profile" ] + hap_profile = "entry/src/main/module.json" +} diff --git a/ability/ability_runtime/actsforresult/forresulttest/entry/src/main/ets/UIExtensionAbility/UIExtAbility.ts b/ability/ability_runtime/actsforresult/forresulttest/entry/src/main/ets/UIExtensionAbility/UIExtAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..bea25f9672330b3a9e0aceee3c52c2eb2d7491db --- /dev/null +++ b/ability/ability_runtime/actsforresult/forresulttest/entry/src/main/ets/UIExtensionAbility/UIExtAbility.ts @@ -0,0 +1,151 @@ +/* + * 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 UIExtensionAbility from '@ohos.app.ability.UIExtensionAbility'; +import wantConstant from '@ohos.app.ability.wantConstant'; +import commonEvent from '@ohos.commonEventManager'; +import hilog from '@ohos.hilog'; + +export default class UiExtAbility extends UIExtensionAbility { + onCreate() { + hilog.info(0x0000, 'testTag', 'UIExtAbility onCreate want: %{public}s'); + console.info('=======>UIExtAbility onCreate======>'); + } + + onSessionCreate(want, session) { + console.log(`want: ${JSON.stringify(want)}}`); + let storage: LocalStorage = new LocalStorage({ + 'session': session + }); + session.loadContent('pages/Page', storage); + console.info('=======>UIExtAbility onSessionCreate======>'); + + if (want.action === 'AsyncCallback_0200') { + console.info('=======>UIExtAbility onSessionCreate want.action == AsyncCallback_0200======>'); + this.context.startAbilityForResult({ + action: 'AsyncCallback_0200', + bundleName: 'com.example.mainhap', + abilityName: 'CalledAbility', + parameters: { + [wantConstant.Params.ABILITY_BACK_TO_OTHER_MISSION_STACK]: true + } + }, (error, data) => { + console.info('=======>Callback_0200 first from another error.code ======>' + error.code); + console.info('=======>Callback_0200 first from another data.resultCode ======>' + data.resultCode); + console.info('=======>Callback_0200 first from another data.action ======>' + data.want.parameters.action); + let commonEventData = { + parameters: { + num: error.code, + str: data.want.parameters.action, + result: data.resultCode + } + }; + commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => { + console.debug('====>AsyncCallback_0200 first publish err:' + JSON.stringify(err)); + }); + }); + } + + if (want.action === 'AsyncCallback_0300') { + console.info('=======>UIExtAbility onSessionCreate want.action == AsyncCallback_0200======>'); + this.context.startAbilityForResult({ + action: 'AsyncCallback_0300', + bundleName: 'com.example.mainhap', + abilityName: 'OtherAbility', + parameters: { + [wantConstant.Params.ABILITY_BACK_TO_OTHER_MISSION_STACK]: true + } + }, (error, data) => { + console.info('=======>Callback_0300 first from another error.code ======>' + error.code); + console.info('=======>Callback_0300 first from another data.resultCode ======>' + data.resultCode); + console.info('=======>Callback_0300 first from another data.action ======>' + data.want.parameters.action); + let commonEventData = { + parameters: { + num: error.code, + str: data.want.parameters.action, + result: data.resultCode + } + }; + commonEvent.publish('ACTS_CALL_EVENT_ANOTHER', commonEventData, (err) => { + console.debug('====>AsyncCallback_0300 first publish err:' + JSON.stringify(err)); + }); + }); + } + + if (want.action === 'Promise_0200') { + console.info('=======>UIExtAbility onSessionCreate want.action == Promise_0200======>'); + this.context.startAbilityForResult({ + action: 'Promise_0200', + bundleName: 'com.example.mainhap', + abilityName: 'CalledAbility', + parameters: { + [wantConstant.Params.ABILITY_BACK_TO_OTHER_MISSION_STACK]: true + } + }).then((data) => { + console.info('=======>Promise_0200 first from another data.resultCode ======>' + data.resultCode); + console.info('=======>Promise_0200 first from another data.action ======>' + data.want.parameters.action); + let commonEventData = { + parameters: { + str: data.want.parameters.action, + result: data.resultCode + } + }; + commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => { + console.debug('====>Promise_0200 first publish err:' + JSON.stringify(err)); + }); + }).catch((error) => { + console.info('=======>Promise_0200 first from another error.code ======>' + error.code); + }); + } + + if (want.action === 'Promise_0300') { + console.info('=======>UIExtAbility onSessionCreate want.action == Promise_0300======>'); + this.context.startAbilityForResult({ + action: 'Promise_0300', + bundleName: 'com.example.mainhap', + abilityName: 'OtherAbility', + parameters: { + [wantConstant.Params.ABILITY_BACK_TO_OTHER_MISSION_STACK]: true + } + }).then((data) => { + console.info('=======>Promise_0300 first from another data.resultCode ======>' + data.resultCode); + console.info('=======>Promise_0300 first from another data.action ======>' + data.want.parameters.action); + let commonEventData = { + parameters: { + str: data.want.parameters.action, + result: data.resultCode + } + }; + commonEvent.publish('ACTS_CALL_EVENT_ANOTHER', commonEventData, (err) => { + console.debug('====>Promise_0300 first publish err:' + JSON.stringify(err)); + }); + }).catch((error) => { + console.info('=======>Promise_0300 first from another error.code ======>' + error.code); + }); + } + } + + 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/actsforresult/forresulttest/entry/src/main/ets/calledability/CalledAbility.ts b/ability/ability_runtime/actsforresult/forresulttest/entry/src/main/ets/calledability/CalledAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..e3749435fb75da9c3d1997af0a4a07d3d559891b --- /dev/null +++ b/ability/ability_runtime/actsforresult/forresulttest/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/actsforresult/forresulttest/entry/src/main/ets/entryability/EntryAbility.ts b/ability/ability_runtime/actsforresult/forresulttest/entry/src/main/ets/entryability/EntryAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..d9d8b6d3a97ff027dd59e0a5b09bbede4a74b80b --- /dev/null +++ b/ability/ability_runtime/actsforresult/forresulttest/entry/src/main/ets/entryability/EntryAbility.ts @@ -0,0 +1,86 @@ +/* + * 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 === 'AsyncCallback_0200') { + console.info("====>EntryAbility want.action == 'AsyncCallback_0200':"); + AppStorage.SetOrCreate('want', { + action: 'AsyncCallback_0200', + bundleName: 'com.example.forresulttestsecond', + abilityName: 'UIExtAbility' + }); + } + + if (want.action === 'AsyncCallback_0300') { + console.info("====>EntryAbility want.action == 'AsyncCallback_0300':"); + AppStorage.SetOrCreate('want', { + action: 'AsyncCallback_0300', + bundleName: 'com.example.forresulttestsecond', + abilityName: 'UIExtAbility' + }); + } + + if (want.action === 'Promise_0200') { + console.info("====>EntryAbility want.action == 'Promise_0200':"); + AppStorage.SetOrCreate('want', { + action: 'Promise_0200', + bundleName: 'com.example.forresulttestsecond', + abilityName: 'UIExtAbility' + }); + } + if (want.action === 'Promise_0300') { + console.info("====>EntryAbility want.action == 'Promise_0300':"); + AppStorage.SetOrCreate('want', { + action: 'Promise_0300', + bundleName: 'com.example.forresulttestsecond', + abilityName: 'UIExtAbility' + }); + } + } + + 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/actsforresult/forresulttest/entry/src/main/ets/pages/Index.ets b/ability/ability_runtime/actsforresult/forresulttest/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..eed30c96c79d54a098c2f0cc723788d41a448479 --- /dev/null +++ b/ability/ability_runtime/actsforresult/forresulttest/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,78 @@ +/* + * 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.forresulttestsecond', + abilityName: 'UIExtAbility' + } + 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}) + Button('StartAbilityForResult') + .fontSize(30) + .fontWeight(FontWeight.Bold) + .onClick(() => { + globalThis.StartAbilityForResult() + }) + .margin({ + top: 5 + }) + Button('StartUI') + .fontSize(30) + .fontWeight(FontWeight.Bold) + .onClick(() => { + globalThis.startUIExtension() + }) + .margin({ + top: 5 + }) + Button('StartCalledAbilitybyUIExtension') + .fontSize(30) + .fontWeight(FontWeight.Bold) + .onClick(() => { + console.info('=======>button======>'); + globalThis.StartAbilityForResult_AsyncCallback_0100() + }) + .margin({ + top: 5 + }) + Button('terminal') + .fontSize(30) + .fontWeight(FontWeight.Bold) + .onClick(() => { + globalThis.terminal() + }) + .margin({ + top: 5 + }) + } + .width('100%') + } + .height('100%') + } +} \ No newline at end of file diff --git a/ability/ability_runtime/actsforresult/forresulttest/entry/src/main/ets/pages/Page.ets b/ability/ability_runtime/actsforresult/forresulttest/entry/src/main/ets/pages/Page.ets new file mode 100644 index 0000000000000000000000000000000000000000..9cd7f775f66196089f21a0568bcd0780dafb3a60 --- /dev/null +++ b/ability/ability_runtime/actsforresult/forresulttest/entry/src/main/ets/pages/Page.ets @@ -0,0 +1,37 @@ +/* + * 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'; + +let storage = LocalStorage.GetShared() + +@Entry(storage) +@Component +struct Page { + @State message: string = 'UIExtAbility' + private session: UIExtensionContentSession = storage.get('session'); + + 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/actsforresult/forresulttest/entry/src/main/ets/pages/PageTwo.ets b/ability/ability_runtime/actsforresult/forresulttest/entry/src/main/ets/pages/PageTwo.ets new file mode 100644 index 0000000000000000000000000000000000000000..d45a7123faedd3ce8ea5093bd704864a9c09ff24 --- /dev/null +++ b/ability/ability_runtime/actsforresult/forresulttest/entry/src/main/ets/pages/PageTwo.ets @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +@Entry +@Component +struct PageTwo { + @State message: string = 'Second application' + + 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 + }) + Button('TerminatePromise0100') + .fontSize(30) + .fontWeight(FontWeight.Bold) + .onClick(() => { + globalThis.StartAbilityForResult_Promise() + }) + .margin({ + top: 5 + }) + } + .width('100%') + } + .height('100%') + } +} \ No newline at end of file diff --git a/ability/ability_runtime/actsforresult/forresulttest/entry/src/main/module.json b/ability/ability_runtime/actsforresult/forresulttest/entry/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..04c0315ef1ebe946de3bcd7edf8f4323096d6e0b --- /dev/null +++ b/ability/ability_runtime/actsforresult/forresulttest/entry/src/main/module.json @@ -0,0 +1,65 @@ +{ + "module": { + "name": "entry", + "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": "ui", + "visible": true, + "srcEntrance": "./ets/UIExtensionAbility/UIExtAbility.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/actsforresult/forresulttest/entry/src/main/resources/base/element/color.json b/ability/ability_runtime/actsforresult/forresulttest/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33 --- /dev/null +++ b/ability/ability_runtime/actsforresult/forresulttest/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/actsforresult/forresulttest/entry/src/main/resources/base/element/string.json b/ability/ability_runtime/actsforresult/forresulttest/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..3b2c2fd7e60fabd14e9df8409557306c4149dbae --- /dev/null +++ b/ability/ability_runtime/actsforresult/forresulttest/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/actsforresult/forresulttest/entry/src/main/resources/base/media/icon.png b/ability/ability_runtime/actsforresult/forresulttest/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ability/ability_runtime/actsforresult/forresulttest/entry/src/main/resources/base/media/icon.png differ diff --git a/ability/ability_runtime/actsforresult/forresulttest/entry/src/main/resources/base/profile/main_pages.json b/ability/ability_runtime/actsforresult/forresulttest/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/ability/ability_runtime/actsforresult/forresulttest/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/ability/ability_runtime/actsforresult/forresulttest/entry/src/main/resources/en_US/element/string.json b/ability/ability_runtime/actsforresult/forresulttest/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..3b2c2fd7e60fabd14e9df8409557306c4149dbae --- /dev/null +++ b/ability/ability_runtime/actsforresult/forresulttest/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/actsforresult/forresulttest/entry/src/main/resources/zh_CN/element/string.json b/ability/ability_runtime/actsforresult/forresulttest/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..73838f7ea8aee9962adb53d5a9b39528744719e7 --- /dev/null +++ b/ability/ability_runtime/actsforresult/forresulttest/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/actsforresult/forresulttest/signature/openharmony_sx.p7b b/ability/ability_runtime/actsforresult/forresulttest/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..a2d09096e3a6018969de68d273fa723cb67d3fd2 Binary files /dev/null and b/ability/ability_runtime/actsforresult/forresulttest/signature/openharmony_sx.p7b differ diff --git a/ability/ability_runtime/actsforresult/forresulttestnopermission/AppScope/app.json b/ability/ability_runtime/actsforresult/forresulttestnopermission/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..adb5bc5c4c1be4bf85b72be1f22987093a830b8b --- /dev/null +++ b/ability/ability_runtime/actsforresult/forresulttestnopermission/AppScope/app.json @@ -0,0 +1,19 @@ +{ + "app": { + "bundleName": "com.example.forresulttestthrid", + "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/actsforresult/forresulttestnopermission/AppScope/resources/base/element/string.json b/ability/ability_runtime/actsforresult/forresulttestnopermission/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..d71e5ead1ce20b4ac3384d18e6d104f1ea4d83b4 --- /dev/null +++ b/ability/ability_runtime/actsforresult/forresulttestnopermission/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "MyApplication" + } + ] +} diff --git a/ability/ability_runtime/actsforresult/forresulttestnopermission/AppScope/resources/base/media/app_icon.png b/ability/ability_runtime/actsforresult/forresulttestnopermission/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ability/ability_runtime/actsforresult/forresulttestnopermission/AppScope/resources/base/media/app_icon.png differ diff --git a/ability/ability_runtime/actsforresult/forresulttestnopermission/BUILD.gn b/ability/ability_runtime/actsforresult/forresulttestnopermission/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..0f77ce72b2303bfb238dce2352858935c0efbae7 --- /dev/null +++ b/ability/ability_runtime/actsforresult/forresulttestnopermission/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("forresulttestnopermission") { + hap_profile = "entry/src/main/module.json" + js_build_mode = "debug" + deps = [ + ":forresulttestnopermission_js_assets", + ":forresulttestnopermission_resources", + ] + ets2abc = true + certificate_profile = "signature/openharmony_sx.p7b" + hap_name = "forresulttestnopermission" + subsystem_name = "ability" + part_name = "ability_runtime" +} + +ohos_app_scope("forresulttestnopermission_app_profile") { + app_profile = "AppScope/app.json" + sources = [ "AppScope/resources" ] +} + +ohos_js_assets("forresulttestnopermission_js_assets") { + source_dir = "entry/src/main/ets" +} + +ohos_resources("forresulttestnopermission_resources") { + sources = [ "entry/src/main/resources" ] + deps = [ ":forresulttestnopermission_app_profile" ] + hap_profile = "entry/src/main/module.json" +} diff --git a/ability/ability_runtime/actsforresult/forresulttestnopermission/entry/src/main/ets/UIExtensionAbility/UIExtAbility.ts b/ability/ability_runtime/actsforresult/forresulttestnopermission/entry/src/main/ets/UIExtensionAbility/UIExtAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..b341d5dd5094aa1011ecd5b86d7d7222532823f6 --- /dev/null +++ b/ability/ability_runtime/actsforresult/forresulttestnopermission/entry/src/main/ets/UIExtensionAbility/UIExtAbility.ts @@ -0,0 +1,139 @@ +/* + * 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 UIExtensionAbility from '@ohos.app.ability.UIExtensionAbility'; +import wantConstant from '@ohos.app.ability.wantConstant'; +import commonEvent from '@ohos.commonEventManager'; +import hilog from '@ohos.hilog'; + +export default class UiExtAbility extends UIExtensionAbility { + onCreate() { + hilog.info(0x0000, 'testTag', 'UIExtAbility onCreate want: %{public}s'); + console.info('=======>UIExtAbility onCreate======>'); + } + + onSessionCreate(want, session) { + console.log(`want: ${JSON.stringify(want)}}`); + let storage: LocalStorage = new LocalStorage({ + 'session': session + }); + session.loadContent('pages/Page', storage); + console.info('=======>UIExtAbility onSessionCreate======>'); + + if (want.action === 'AsyncCallback_0600') { + console.info('=======>UIExtAbility onSessionCreate want.action == AsyncCallback_0600======>'); + this.context.startAbilityForResult({ + action: 'AsyncCallback_0600', + bundleName: 'com.example.mainhap', + abilityName: 'CalledAbility', + parameters: { + [wantConstant.Params.ABILITY_BACK_TO_OTHER_MISSION_STACK]: true + } + }, (error, data) => { + console.info('=======>Callback_0600 first from own error.code ======>' + error.code); + let commonEventData = { + parameters: { + num: error.code + } + }; + commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => { + console.debug('====>AsyncCallback_0600 first publish err:' + JSON.stringify(err)); + }); + }); + } + + if (want.action === 'AsyncCallback_0700') { + console.info('=======>UIExtAbility onSessionCreate want.action == AsyncCallback_0700======>'); + this.context.startAbilityForResult({ + action: 'AsyncCallback_0700', + bundleName: 'com.example.mainhap', + abilityName: 'OtherAbility', + parameters: { + [wantConstant.Params.ABILITY_BACK_TO_OTHER_MISSION_STACK]: true + } + }, (error, data) => { + console.info('=======>Callback_0700 first from own error.code ======>' + error.code); + let commonEventData = { + parameters: { + num: error.code + } + }; + commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => { + console.debug('====>AsyncCallback_0700 first publish err:' + JSON.stringify(err)); + }); + }); + } + + if (want.action === 'Promise_0600') { + console.info('=======>UIExtAbility onSessionCreate want.action == Promise_0600======>'); + this.context.startAbilityForResult({ + action: 'Promise_0600', + bundleName: 'com.example.mainhap', + abilityName: 'CalledAbility', + parameters: { + [wantConstant.Params.ABILITY_BACK_TO_OTHER_MISSION_STACK]: true + } + }).then((data) => { + console.info('=======>Promise_0600 startAbilityForResult ok ======>'); + }).catch((error) => { + console.info('=======>Promise_0600 first from own error.code ======>' + error.code); + let commonEventData = { + parameters: { + num: error.code + } + }; + commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => { + console.debug('====>Promise_0600 first publish err:' + JSON.stringify(err)); + }); + }); + } + + if (want.action === 'Promise_0700') { + console.info('=======>UIExtAbility onSessionCreate want.action == Promise_0700======>'); + this.context.startAbilityForResult({ + action: 'Promise_0700', + bundleName: 'com.example.mainhap', + abilityName: 'OtherAbility', + parameters: { + [wantConstant.Params.ABILITY_BACK_TO_OTHER_MISSION_STACK]: true + } + }).then((data) => { + console.info('=======>Promise_0700 startAbilityForResult ok ======>'); + }).catch((error) => { + console.info('=======>Promise_0700 first from own error.code ======>' + error.code); + let commonEventData = { + parameters: { + num: error.code + } + }; + commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => { + console.debug('====>AsyncCallback_0700 first publish err:' + JSON.stringify(err)); + }); + }); + } + } + + 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/actsforresult/forresulttestnopermission/entry/src/main/ets/calledability/CalledAbility.ts b/ability/ability_runtime/actsforresult/forresulttestnopermission/entry/src/main/ets/calledability/CalledAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..e77991a1189dec58821ed72ffb4d6f7c67700c7c --- /dev/null +++ b/ability/ability_runtime/actsforresult/forresulttestnopermission/entry/src/main/ets/calledability/CalledAbility.ts @@ -0,0 +1,56 @@ +/* + * 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 =====>'); + } + + 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/actsforresult/forresulttestnopermission/entry/src/main/ets/entryability/EntryAbility.ts b/ability/ability_runtime/actsforresult/forresulttestnopermission/entry/src/main/ets/entryability/EntryAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..09bc161bc639abc1f5777149aa81977f1f2ba71d --- /dev/null +++ b/ability/ability_runtime/actsforresult/forresulttestnopermission/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 === 'AsyncCallback_0600') { + console.info("====>EntryAbility want.action == 'AsyncCallback_0600':"); + AppStorage.SetOrCreate('want', { + action: 'AsyncCallback_0600', + bundleName: 'com.example.forresulttestthrid', + abilityName: 'UIExtAbility' + }); + } + + if (want.action === 'AsyncCallback_0700') { + console.info("====>EntryAbility want.action == 'AsyncCallback_0700':"); + AppStorage.SetOrCreate('want', { + action: 'AsyncCallback_0700', + bundleName: 'com.example.forresulttestthrid', + abilityName: 'UIExtAbility' + }); + } + + if (want.action === 'Promise_0600') { + console.info("====>EntryAbility want.action == 'Promise_0600':"); + AppStorage.SetOrCreate('want', { + action: 'Promise_0600', + bundleName: 'com.example.forresulttestthrid', + abilityName: 'UIExtAbility' + }); + } + + if (want.action === 'Promise_0700') { + console.info("====>EntryAbility want.action == 'Promise_0700':"); + AppStorage.SetOrCreate('want', { + action: 'Promise_0700', + bundleName: 'com.example.forresulttestthrid', + abilityName: 'UIExtAbility' + }); + } + } + + 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'); + } + + onNewWant(want, launchParams) { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + + if (want.action === 'AsyncCallback_0200') { + console.info("====>EntryAbility want.action == 'AsyncCallback_0200':"); + AppStorage.SetOrCreate('want', { + action: 'AsyncCallback_0200', + bundleName: 'com.example.forresulttestsecond', + abilityName: 'UIExtAbility' + }); + } + + if (want.action === 'AsyncCallback_0300') { + console.info("====>EntryAbility want.action == 'AsyncCallback_0300':"); + AppStorage.SetOrCreate('want', { + action: 'AsyncCallback_0300', + bundleName: 'com.example.forresulttestsecond', + abilityName: 'UIExtAbility' + }); + } + } + + onBackground() { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/ability/ability_runtime/actsforresult/forresulttestnopermission/entry/src/main/ets/pages/Index.ets b/ability/ability_runtime/actsforresult/forresulttestnopermission/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..9c939e7fc512da2a741e0159cf3100190af3132d --- /dev/null +++ b/ability/ability_runtime/actsforresult/forresulttestnopermission/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,78 @@ +/* + * 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_0600", + bundleName: 'com.example.forresulttestthrid', + abilityName: 'UIExtAbility' + } + 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}) + Button('StartAbilityForResult') + .fontSize(30) + .fontWeight(FontWeight.Bold) + .onClick(() => { + globalThis.StartAbilityForResult() + }) + .margin({ + top: 5 + }) + Button('StartUI') + .fontSize(30) + .fontWeight(FontWeight.Bold) + .onClick(() => { + globalThis.startUIExtension() + }) + .margin({ + top: 5 + }) + Button('StartCalledAbilitybyUIExtension') + .fontSize(30) + .fontWeight(FontWeight.Bold) + .onClick(() => { + console.info('=======>button======>'); + globalThis.StartAbilityForResult_AsyncCallback_0100() + }) + .margin({ + top: 5 + }) + Button('terminal') + .fontSize(30) + .fontWeight(FontWeight.Bold) + .onClick(() => { + globalThis.terminal() + }) + .margin({ + top: 5 + }) + } + .width('100%') + } + .height('100%') + } +} \ No newline at end of file diff --git a/ability/ability_runtime/actsforresult/forresulttestnopermission/entry/src/main/ets/pages/Page.ets b/ability/ability_runtime/actsforresult/forresulttestnopermission/entry/src/main/ets/pages/Page.ets new file mode 100644 index 0000000000000000000000000000000000000000..9cd7f775f66196089f21a0568bcd0780dafb3a60 --- /dev/null +++ b/ability/ability_runtime/actsforresult/forresulttestnopermission/entry/src/main/ets/pages/Page.ets @@ -0,0 +1,37 @@ +/* + * 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'; + +let storage = LocalStorage.GetShared() + +@Entry(storage) +@Component +struct Page { + @State message: string = 'UIExtAbility' + private session: UIExtensionContentSession = storage.get('session'); + + 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/actsforresult/forresulttestnopermission/entry/src/main/ets/pages/PageTwo.ets b/ability/ability_runtime/actsforresult/forresulttestnopermission/entry/src/main/ets/pages/PageTwo.ets new file mode 100644 index 0000000000000000000000000000000000000000..d45a7123faedd3ce8ea5093bd704864a9c09ff24 --- /dev/null +++ b/ability/ability_runtime/actsforresult/forresulttestnopermission/entry/src/main/ets/pages/PageTwo.ets @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +@Entry +@Component +struct PageTwo { + @State message: string = 'Second application' + + 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 + }) + Button('TerminatePromise0100') + .fontSize(30) + .fontWeight(FontWeight.Bold) + .onClick(() => { + globalThis.StartAbilityForResult_Promise() + }) + .margin({ + top: 5 + }) + } + .width('100%') + } + .height('100%') + } +} \ No newline at end of file diff --git a/ability/ability_runtime/actsforresult/forresulttestnopermission/entry/src/main/module.json b/ability/ability_runtime/actsforresult/forresulttestnopermission/entry/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..05b2e5ab5216f922f4e66be0e06de1ff522a4b42 --- /dev/null +++ b/ability/ability_runtime/actsforresult/forresulttestnopermission/entry/src/main/module.json @@ -0,0 +1,57 @@ +{ + "module": { + "name": "entry", + "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": "ui", + "visible": true, + "srcEntrance": "./ets/UIExtensionAbility/UIExtAbility.ts" + } + ] + } +} \ No newline at end of file diff --git a/ability/ability_runtime/actsforresult/forresulttestnopermission/entry/src/main/resources/base/element/color.json b/ability/ability_runtime/actsforresult/forresulttestnopermission/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33 --- /dev/null +++ b/ability/ability_runtime/actsforresult/forresulttestnopermission/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/actsforresult/forresulttestnopermission/entry/src/main/resources/base/element/string.json b/ability/ability_runtime/actsforresult/forresulttestnopermission/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..3b2c2fd7e60fabd14e9df8409557306c4149dbae --- /dev/null +++ b/ability/ability_runtime/actsforresult/forresulttestnopermission/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/actsforresult/forresulttestnopermission/entry/src/main/resources/base/media/icon.png b/ability/ability_runtime/actsforresult/forresulttestnopermission/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ability/ability_runtime/actsforresult/forresulttestnopermission/entry/src/main/resources/base/media/icon.png differ diff --git a/ability/ability_runtime/actsforresult/forresulttestnopermission/entry/src/main/resources/base/profile/main_pages.json b/ability/ability_runtime/actsforresult/forresulttestnopermission/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/ability/ability_runtime/actsforresult/forresulttestnopermission/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/ability/ability_runtime/actsforresult/forresulttestnopermission/entry/src/main/resources/en_US/element/string.json b/ability/ability_runtime/actsforresult/forresulttestnopermission/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..3b2c2fd7e60fabd14e9df8409557306c4149dbae --- /dev/null +++ b/ability/ability_runtime/actsforresult/forresulttestnopermission/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/actsforresult/forresulttestnopermission/entry/src/main/resources/zh_CN/element/string.json b/ability/ability_runtime/actsforresult/forresulttestnopermission/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..73838f7ea8aee9962adb53d5a9b39528744719e7 --- /dev/null +++ b/ability/ability_runtime/actsforresult/forresulttestnopermission/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/actsforresult/forresulttestnopermission/signature/openharmony_sx.p7b b/ability/ability_runtime/actsforresult/forresulttestnopermission/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..7051c27fc4eb4e30001a220ceacb23ca52aa43bf Binary files /dev/null and b/ability/ability_runtime/actsforresult/forresulttestnopermission/signature/openharmony_sx.p7b differ diff --git a/ability/ability_runtime/actsforresult/main/AppScope/app.json b/ability/ability_runtime/actsforresult/main/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..9ff6b1ddbbbd2c38e1df4c7a6386512c1102298e --- /dev/null +++ b/ability/ability_runtime/actsforresult/main/AppScope/app.json @@ -0,0 +1,19 @@ +{ + "app": { + "bundleName": "com.example.mainhap", + "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/actsforresult/main/AppScope/resources/base/element/string.json b/ability/ability_runtime/actsforresult/main/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..d71e5ead1ce20b4ac3384d18e6d104f1ea4d83b4 --- /dev/null +++ b/ability/ability_runtime/actsforresult/main/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "MyApplication" + } + ] +} diff --git a/ability/ability_runtime/actsforresult/main/AppScope/resources/base/media/app_icon.png b/ability/ability_runtime/actsforresult/main/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ability/ability_runtime/actsforresult/main/AppScope/resources/base/media/app_icon.png differ diff --git a/ability/ability_runtime/actsforresult/main/BUILD.gn b/ability/ability_runtime/actsforresult/main/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..b835061fe9df82068e56db6e751c691f1cc718e9 --- /dev/null +++ b/ability/ability_runtime/actsforresult/main/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("main") { + hap_profile = "entry/src/main/module.json" + js_build_mode = "debug" + deps = [ + ":main_js_assets", + ":main_resources", + ] + ets2abc = true + certificate_profile = "signature/openharmony_sx.p7b" + hap_name = "main" + subsystem_name = "ability" + part_name = "ability_runtime" +} + +ohos_app_scope("main_app_profile") { + app_profile = "AppScope/app.json" + sources = [ "AppScope/resources" ] +} + +ohos_js_assets("main_js_assets") { + source_dir = "entry/src/main/ets" +} + +ohos_resources("main_resources") { + sources = [ "entry/src/main/resources" ] + deps = [ ":main_app_profile" ] + hap_profile = "entry/src/main/module.json" +} diff --git a/ability/ability_runtime/actsforresult/main/entry/src/main/ets/UIExtensionAbility/UIExtAbility.ts b/ability/ability_runtime/actsforresult/main/entry/src/main/ets/UIExtensionAbility/UIExtAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..ad9528e6f2a98401e9caf015932a1a38b86429c5 --- /dev/null +++ b/ability/ability_runtime/actsforresult/main/entry/src/main/ets/UIExtensionAbility/UIExtAbility.ts @@ -0,0 +1,252 @@ +/* + * 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 UIExtensionAbility from '@ohos.app.ability.UIExtensionAbility'; +import wantConstant from '@ohos.app.ability.wantConstant'; +import commonEvent from '@ohos.commonEventManager'; +// import Logger from '../model/Logger' +import hilog from '@ohos.hilog'; +// const TAG: string = '[UIExtensionAbility]' + +export default class UiExtAbility extends UIExtensionAbility { + onCreate() { + hilog.info(0x0000, 'testTag', 'UIExtAbility onCreate want: %{public}s'); + console.info('=======>UIExtAbility onCreate======>'); + } + + onSessionCreate(want, session) { + console.log(`want: ${JSON.stringify(want)}}`); + let storage: LocalStorage = new LocalStorage({ + 'session': session + }); + session.loadContent('pages/Page', storage); + console.info('=======>UIExtAbility onSessionCreate======>'); + + if (want.action === 'AsyncCallback_0100') { + console.info('=======>UIExtAbility onSessionCreate want.action == AsyncCallback_0100======>'); + this.context.startAbilityForResult({ + action: 'AsyncCallback_0100', + bundleName: 'com.example.mainhap', + abilityName: 'CalledAbility', + parameters: { + [wantConstant.Params.ABILITY_BACK_TO_OTHER_MISSION_STACK]: true + } + }, (error, data) => { + console.info('=======>Callback_0100 error.code ======>' + error.code); + console.info('=======>Callback_0100 data.resultCode ======>' + data.resultCode); + console.info('=======>Callback_0100 data.action ======>' + data.want.parameters.action); + let commonEventData = { + parameters: { + num: error.code, + str: data.want.parameters.action, + result: data.resultCode + } + }; + commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => { + console.debug('====>AsyncCallback_0100 publish err:' + JSON.stringify(err)); + }); + }); + } + + if (want.action === 'AsyncCallback_0300') { + console.info('=======>UIExtAbility onSessionCreate want.action == AsyncCallback_0300======>'); + this.context.startAbilityForResult({ + action: 'AsyncCallback_0300', + bundleName: 'com.example.mainhap', + abilityName: 'OtherAbility', + parameters: { + [wantConstant.Params.ABILITY_BACK_TO_OTHER_MISSION_STACK]: true + } + }, (error, data) => { + console.info('=======>Callback_0300 first from own error.code ======>' + error.code); + console.info('=======>Callback_0300 first from own data.resultCode ======>' + data.resultCode); + console.info('=======>Callback_0300 first from own data.action ======>' + data.want.parameters.action); + let commonEventData = { + parameters: { + num: error.code, + str: data.want.parameters.action, + result: data.resultCode + } + }; + commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => { + console.debug('====>AsyncCallback_0300 first publish err:' + JSON.stringify(err)); + }); + }); + } + + if (want.action === 'AsyncCallback_0400') { + console.info('=======>UIExtAbility onSessionCreate want.action == AsyncCallback_0400======>'); + this.context.startAbilityForResult({ + action: 'AsyncCallback_0400', + bundleName: 'com.example.forresulttestsecond', + abilityName: 'CalledAbility', + parameters: { + [wantConstant.Params.ABILITY_BACK_TO_OTHER_MISSION_STACK]: true + } + }, (error, data) => { + console.info('=======>Callback_0400 first from own error.code ======>' + error.code); + console.info('=======>Callback_0400 first from own data.resultCode ======>' + data.resultCode); + console.info('=======>Callback_0400 first from own data.action ======>' + data.want.parameters.action); + let commonEventData = { + parameters: { + num: error.code, + str: data.want.parameters.action, + result: data.resultCode + } + }; + commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => { + console.debug('====>AsyncCallback_0400 first publish err:' + JSON.stringify(err)); + }); + }); + } + + if (want.action === 'AsyncCallback_0500') { + console.info('=======>UIExtAbility onSessionCreate want.action == AsyncCallback_0500======>'); + this.context.startAbilityForResult({ + action: 'AsyncCallback_0500', + bundleName: 'xxx.xxxxxxx.xxx', + abilityName: 'CalledAbility', + parameters: { + [wantConstant.Params.ABILITY_BACK_TO_OTHER_MISSION_STACK]: true + } + }, (error, data) => { + console.info('=======>Callback_0500 first from own error.code ======>' + error.code); + let commonEventData = { + parameters: { + num: error.code + } + }; + commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => { + console.debug('====>AsyncCallback_0500 first publish err:' + JSON.stringify(err)); + }); + }); + } + + if (want.action === 'Promise_0100') { + console.info('=======>UIExtAbility onSessionCreate want.action == Promise_0100======>'); + this.context.startAbilityForResult({ + action: 'Promise_0100', + bundleName: 'com.example.mainhap', + abilityName: 'CalledAbility', + parameters: { + [wantConstant.Params.ABILITY_BACK_TO_OTHER_MISSION_STACK]: true + } + }).then((data) => { + console.info('=======>Promise_0100 data.resultCode ======>' + data.resultCode); + console.info('=======>Promise_0100 data.action ======>' + data.want.parameters.action); + let commonEventData = { + parameters: { + str: data.want.parameters.action, + result: data.resultCode + } + }; + commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => { + console.debug('====>Promise_0100 publish err:' + JSON.stringify(err)); + }); + }).catch((error) => { + console.info('=======>Promise_0100 error.code ======>' + error.code); + }); + } + + if (want.action === 'Promise_0300') { + console.info('=======>UIExtAbility onSessionCreate want.action == Promise_0300======>'); + this.context.startAbilityForResult({ + action: 'Promise_0300', + bundleName: 'com.example.mainhap', + abilityName: 'OtherAbility', + parameters: { + [wantConstant.Params.ABILITY_BACK_TO_OTHER_MISSION_STACK]: true + } + }).then((data) => { + console.info('=======>Promise_0300 first from own data.resultCode ======>' + data.resultCode); + console.info('=======>Promise_0300 first from own data.action ======>' + data.want.parameters.action); + let commonEventData = { + parameters: { + str: data.want.parameters.action, + result: data.resultCode + } + }; + commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => { + console.debug('====>Promise_0300 first publish err:' + JSON.stringify(err)); + }); + }).catch((error) => { + console.info('=======>Promise_0300 first from own error.code ======>' + error.code); + }); + } + + if (want.action === 'Promise_0400') { + console.info('=======>UIExtAbility onSessionCreate want.action == Promise_0400======>'); + this.context.startAbilityForResult({ + action: 'Promise_0400', + bundleName: 'com.example.forresulttestsecond', + abilityName: 'CalledAbility', + parameters: { + [wantConstant.Params.ABILITY_BACK_TO_OTHER_MISSION_STACK]: true + } + }).then((data) => { + console.info('=======>Promise_0400 first from own data.resultCode ======>' + data.resultCode); + console.info('=======>Promise_0400 first from own data.action ======>' + data.want.parameters.action); + let commonEventData = { + parameters: { + str: data.want.parameters.action, + result: data.resultCode + } + }; + commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => { + console.debug('====>Promise_0400 first publish err:' + JSON.stringify(err)); + }); + }).catch((error) => { + console.info('=======>Promise_0400 first from own error.code ======>' + error.code); + }); + } + + if (want.action === 'Promise_0500') { + console.info('=======>UIExtAbility onSessionCreate want.action == Promise_0500======>'); + this.context.startAbilityForResult({ + action: 'Promise_0500', + bundleName: 'xxx.xxxxxxx.xxx', + abilityName: 'CalledAbility', + parameters: { + [wantConstant.Params.ABILITY_BACK_TO_OTHER_MISSION_STACK]: true + } + }).then((data) => { + console.info('=======>Callback_0500 first from own data.resultCode ======>' + data.resultCode); + console.info('=======>Callback_0500 first from own data.action ======>' + data.want.parameters.action); + }).catch((error) => { + console.info('=======>Callback_0500 first from own error.code ======>' + error.code); + let commonEventData = { + parameters: { + num: error.code + } + }; + commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => { + console.debug('====>AsyncCallback_0500 first publish err:' + JSON.stringify(err)); + }); + }); + } + } + + 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/actsforresult/main/entry/src/main/ets/calledability/CalledAbility.ts b/ability/ability_runtime/actsforresult/main/entry/src/main/ets/calledability/CalledAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..48b739a1d89d2fd74279454a0e5091b21e07807e --- /dev/null +++ b/ability/ability_runtime/actsforresult/main/entry/src/main/ets/calledability/CalledAbility.ts @@ -0,0 +1,109 @@ +/* + * 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 =====>'); + + if (want.action === 'AsyncCallback_0100') { + this.context.terminateSelfWithResult({ + resultCode: 0, + want: { + parameters: { + action: 'ACTION' + } + } + }, (err) => { + console.log('=====> AsyncCallback_0100 CalledAbilityCallBack terminateSelfWithResult =====>' + err.code); + }); + } + + if (want.action === 'Promise_0100') { + this.context.terminateSelfWithResult({ + resultCode: 0, + want: { + parameters: { + action: 'ACTION' + } + } + }, (err) => { + console.log('=====> Promise_0100 CalledAbilityCallBack terminateSelfWithResult =====>' + err.code); + }); + } + + if (want.action === 'AsyncCallback_0200') { + this.context.terminateSelfWithResult({ + resultCode: 0, + want: { + parameters: { + action: 'ACTION' + } + } + }, (err) => { + console.log('=====> AsyncCallback_0200 CalledAbilityCallBack terminateSelfWithResult =====>' + err.code); + }); + } + + if (want.action === 'Promise_0200') { + this.context.terminateSelfWithResult({ + resultCode: 0, + want: { + parameters: { + action: 'ACTION' + } + } + }, (err) => { + console.log('=====> Promise_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/actsforresult/main/entry/src/main/ets/entryability/EntryAbility.ts b/ability/ability_runtime/actsforresult/main/entry/src/main/ets/entryability/EntryAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..1331815cf106f1a197cd462434bad519edfce334 --- /dev/null +++ b/ability/ability_runtime/actsforresult/main/entry/src/main/ets/entryability/EntryAbility.ts @@ -0,0 +1,145 @@ +/* + * 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) { + 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 === 'AsyncCallback_0100') { + console.info("====>EntryAbility want.action == 'AsyncCallback_0100':"); + AppStorage.SetOrCreate('want', { + action: 'AsyncCallback_0100', + bundleName: 'com.example.mainhap', + abilityName: 'UIExtAbility' + }); + } else if (want.action === 'AsyncCallback_0300') { + console.info("====>EntryAbility want.action == 'AsyncCallback_0300':"); + AppStorage.SetOrCreate('want', { + action: 'AsyncCallback_0300', + bundleName: 'com.example.mainhap', + abilityName: 'UIExtAbility' + }); + } else if (want.action === 'AsyncCallback_0400') { + console.info("====>EntryAbility want.action == 'AsyncCallback_0400':"); + AppStorage.SetOrCreate('want', { + action: 'AsyncCallback_0400', + bundleName: 'com.example.mainhap', + abilityName: 'UIExtAbility' + }); + } else if (want.action === 'AsyncCallback_0500') { + console.info("====>EntryAbility want.action == 'AsyncCallback_0500':"); + AppStorage.SetOrCreate('want', { + action: 'AsyncCallback_0500', + bundleName: 'com.example.mainhap', + abilityName: 'UIExtAbility' + }); + } + + if (want.action === 'Promise_0100') { + console.info("====>EntryAbility want.action == 'Promise_0100':"); + AppStorage.SetOrCreate('want', { + action: 'Promise_0100', + bundleName: 'com.example.mainhap', + abilityName: 'UIExtAbility' + }); + } else if (want.action === 'Promise_0300') { + console.info("====>EntryAbility want.action == 'Promise_0300':"); + AppStorage.SetOrCreate('want', { + action: 'Promise_0300', + bundleName: 'com.example.mainhap', + abilityName: 'UIExtAbility' + }); + } else if (want.action === 'Promise_0400') { + console.info("====>EntryAbility want.action == 'Promise_0400':"); + AppStorage.SetOrCreate('want', { + action: 'Promise_0400', + bundleName: 'com.example.mainhap', + abilityName: 'UIExtAbility' + }); + } else if (want.action === 'Promise_0500') { + console.info("====>EntryAbility want.action == 'Promise_0500':"); + AppStorage.SetOrCreate('want', { + action: 'Promise_0500', + bundleName: 'com.example.mainhap', + abilityName: 'UIExtAbility' + }); + } + } + + 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'); + globalThis.StartAbilityForResult = () => { + this.context.startAbilityForResult({ + bundleName: 'com.example.mainhap', + abilityName: 'CalledAbility', + //moduleName: 'entry' + }, (error, data) => { + console.log('=======>startAbilityForResult error.code ======>' + error.code); + console.log('=======>startAbilityForResult data.resultCode ======>' + data.resultCode); + console.log('=======>startAbilityForResult data.action ======>' + data.want.parameters.action); + }); + }; + + globalThis.startUIExtension = () => { + this.context.startAbility({ + bundleName: 'com.example.mainhap', + abilityName: 'UIExtAbility', + }, (err) => { + console.info('====>startAbility err:' + JSON.stringify(err)); + }); + }; + } + + onBackground() { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/ability/ability_runtime/actsforresult/main/entry/src/main/ets/otherability/OtherAbility.ts b/ability/ability_runtime/actsforresult/main/entry/src/main/ets/otherability/OtherAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..e8f3616fcb39201b217e7fde3cf9e612195003d9 --- /dev/null +++ b/ability/ability_runtime/actsforresult/main/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/actsforresult/main/entry/src/main/ets/pages/Index.ets b/ability/ability_runtime/actsforresult/main/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..11418454850e7b7b09c5bd8120e0eb4612fef44d --- /dev/null +++ b/ability/ability_runtime/actsforresult/main/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,78 @@ +/* + * 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 = 'First application' + @StorageLink('want') want: Want = { + action: "AsyncCallback_0100", + bundleName: 'com.example.mainhap', + abilityName: 'UIExtAbility' + } + 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}) + Button('StartAbilityForResult') + .fontSize(30) + .fontWeight(FontWeight.Bold) + .onClick(() => { + globalThis.StartAbilityForResult() + }) + .margin({ + top: 5 + }) + Button('StartUI') + .fontSize(30) + .fontWeight(FontWeight.Bold) + .onClick(() => { + globalThis.startUIExtension() + }) + .margin({ + top: 5 + }) + Button('StartCalledAbilitybyUIExtension') + .fontSize(30) + .fontWeight(FontWeight.Bold) + .onClick(() => { + console.info('=======>button======>'); + globalThis.StartAbilityForResult_AsyncCallback_0100() + }) + .margin({ + top: 5 + }) + Button('terminal') + .fontSize(30) + .fontWeight(FontWeight.Bold) + .onClick(() => { + globalThis.terminal() + }) + .margin({ + top: 5 + }) + } + .width('100%') + } + .height('100%') + } +} \ No newline at end of file diff --git a/ability/ability_runtime/actsforresult/main/entry/src/main/ets/pages/IndexTwo.ets b/ability/ability_runtime/actsforresult/main/entry/src/main/ets/pages/IndexTwo.ets new file mode 100644 index 0000000000000000000000000000000000000000..7efec842267037a9cbca70fb27f9e1861e8c033c --- /dev/null +++ b/ability/ability_runtime/actsforresult/main/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/actsforresult/main/entry/src/main/ets/pages/Page.ets b/ability/ability_runtime/actsforresult/main/entry/src/main/ets/pages/Page.ets new file mode 100644 index 0000000000000000000000000000000000000000..7627bf2f3070f641948fb592d123b2a4d8567091 --- /dev/null +++ b/ability/ability_runtime/actsforresult/main/entry/src/main/ets/pages/Page.ets @@ -0,0 +1,38 @@ +/* + * 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'; + +let storage = LocalStorage.GetShared() + +@Entry(storage) +@Component +struct Page { + @State message: string = 'UIExtAbility' + + private session: UIExtensionContentSession = storage.get('session'); + + 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/actsforresult/main/entry/src/main/ets/pages/PageTwo.ets b/ability/ability_runtime/actsforresult/main/entry/src/main/ets/pages/PageTwo.ets new file mode 100644 index 0000000000000000000000000000000000000000..25043f944787f4eaef2628df7c444b2aa8238eb3 --- /dev/null +++ b/ability/ability_runtime/actsforresult/main/entry/src/main/ets/pages/PageTwo.ets @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +@Entry +@Component +struct PageTwo { + @State message: string = 'Hello World' + + 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 + }) + Button('TerminatePromise0100') + .fontSize(30) + .fontWeight(FontWeight.Bold) + .onClick(() => { + globalThis.StartAbilityForResult_Promise() + }) + .margin({ + top: 5 + }) + } + .width('100%') + } + .height('100%') + } +} \ No newline at end of file diff --git a/ability/ability_runtime/actsforresult/main/entry/src/main/module.json b/ability/ability_runtime/actsforresult/main/entry/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..d0fc61e021ef5d9f2cdad4ea9115e55eacbbfbeb --- /dev/null +++ b/ability/ability_runtime/actsforresult/main/entry/src/main/module.json @@ -0,0 +1,73 @@ +{ + "module": { + "name": "entry", + "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": "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": "ui", + "visible": true, + "srcEntrance": "./ets/UIExtensionAbility/UIExtAbility.ts" + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.START_ABILITIES_FROM_BACKGROUND" + } + ] + } +} \ No newline at end of file diff --git a/ability/ability_runtime/actsforresult/main/entry/src/main/resources/base/element/color.json b/ability/ability_runtime/actsforresult/main/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33 --- /dev/null +++ b/ability/ability_runtime/actsforresult/main/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/actsforresult/main/entry/src/main/resources/base/element/string.json b/ability/ability_runtime/actsforresult/main/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..c27bb840373b2dd01bebd64a52879e477220748b --- /dev/null +++ b/ability/ability_runtime/actsforresult/main/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/actsforresult/main/entry/src/main/resources/base/media/icon.png b/ability/ability_runtime/actsforresult/main/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ability/ability_runtime/actsforresult/main/entry/src/main/resources/base/media/icon.png differ diff --git a/ability/ability_runtime/actsforresult/main/entry/src/main/resources/base/profile/main_pages.json b/ability/ability_runtime/actsforresult/main/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..e8fe8532c995e30033c53551b9fcb9d6cd7629d8 --- /dev/null +++ b/ability/ability_runtime/actsforresult/main/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,7 @@ +{ + "src": [ + "pages/Index", + "pages/Page", + "pages/PageTwo" + ] +} \ No newline at end of file diff --git a/ability/ability_runtime/actsforresult/main/entry/src/main/resources/en_US/element/string.json b/ability/ability_runtime/actsforresult/main/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..c27bb840373b2dd01bebd64a52879e477220748b --- /dev/null +++ b/ability/ability_runtime/actsforresult/main/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/actsforresult/main/entry/src/main/resources/zh_CN/element/string.json b/ability/ability_runtime/actsforresult/main/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..73838f7ea8aee9962adb53d5a9b39528744719e7 --- /dev/null +++ b/ability/ability_runtime/actsforresult/main/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/actsforresult/main/signature/openharmony_sx.p7b b/ability/ability_runtime/actsforresult/main/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..4edeeb9a19094e2e10903ccd7ceebc421357aa06 Binary files /dev/null and b/ability/ability_runtime/actsforresult/main/signature/openharmony_sx.p7b differ diff --git a/ability/ability_runtime/actsforresult/maintest/AppScope/app.json b/ability/ability_runtime/actsforresult/maintest/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..9ff6b1ddbbbd2c38e1df4c7a6386512c1102298e --- /dev/null +++ b/ability/ability_runtime/actsforresult/maintest/AppScope/app.json @@ -0,0 +1,19 @@ +{ + "app": { + "bundleName": "com.example.mainhap", + "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/actsforresult/maintest/AppScope/resources/base/element/string.json b/ability/ability_runtime/actsforresult/maintest/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..d71e5ead1ce20b4ac3384d18e6d104f1ea4d83b4 --- /dev/null +++ b/ability/ability_runtime/actsforresult/maintest/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "MyApplication" + } + ] +} diff --git a/ability/ability_runtime/actsforresult/maintest/AppScope/resources/base/media/app_icon.png b/ability/ability_runtime/actsforresult/maintest/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ability/ability_runtime/actsforresult/maintest/AppScope/resources/base/media/app_icon.png differ diff --git a/ability/ability_runtime/actsforresult/maintest/BUILD.gn b/ability/ability_runtime/actsforresult/maintest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..0747dfcbb76b9bd2415b0b631a50794557ac32e8 --- /dev/null +++ b/ability/ability_runtime/actsforresult/maintest/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("maintest") { + hap_profile = "entry/src/main/module.json" + js_build_mode = "debug" + deps = [ + ":maintest_js_assets", + ":maintest_resources", + ] + ets2abc = true + certificate_profile = "signature/openharmony_sx.p7b" + hap_name = "maintest" + subsystem_name = "ability" + part_name = "ability_runtime" +} + +ohos_app_scope("maintest_app_profile") { + app_profile = "AppScope/app.json" + sources = [ "AppScope/resources" ] +} + +ohos_js_assets("maintest_js_assets") { + source_dir = "entry/src/main/ets" +} + +ohos_resources("maintest_resources") { + sources = [ "entry/src/main/resources" ] + deps = [ ":maintest_app_profile" ] + hap_profile = "entry/src/main/module.json" +} diff --git a/ability/ability_runtime/actsforresult/maintest/Test.json b/ability/ability_runtime/actsforresult/maintest/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..27299f3d211e97944c178d3b12346a6c868cc0e9 --- /dev/null +++ b/ability/ability_runtime/actsforresult/maintest/Test.json @@ -0,0 +1,38 @@ +{ + "description": "Configuration for aceceshi Tests", + "driver": { + "type": "OHJSUnitTest", + "test-timeout": "600000", + "bundle-name": "com.example.mainhap", + "module-name": "entry_test", + "shell-timeout": "600000", + "testcase-timeout": 25000 + }, + "kits": [ + { + "test-file-name": [ + "forresulttest.hap", + "forresulttestnopermission.hap", + "main.hap", + "maintest.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/actsforresult/maintest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/ability/ability_runtime/actsforresult/maintest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..288289c4842ae069a1b5f9ac68af8a586033f448 --- /dev/null +++ b/ability/ability_runtime/actsforresult/maintest/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() + let testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility'; + let lMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + }; + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) + let cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName; + let 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/actsforresult/maintest/entry/src/main/ets/test/Ability.test.ets b/ability/ability_runtime/actsforresult/maintest/entry/src/main/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..92ec7ec4728bf1029674757a3dd14af0b80b7392 --- /dev/null +++ b/ability/ability_runtime/actsforresult/maintest/entry/src/main/ets/test/Ability.test.ets @@ -0,0 +1,603 @@ +/* + * 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 { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' +import commonEvent from '@ohos.commonEventManager' +import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; +import { Driver } from '@ohos.UiTest'; + +let abilityDelegator = abilityDelegatorRegistry.getAbilityDelegator() +var ACTS_CallFunction = { + events: ['ACTS_CALL_EVENT', 'ACTS_CALL_EVENT_ANOTHER'] +}; + +export default function abilityTest() { + describe('ActsAbilityTest', function () { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(function () { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(function () { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + // setTimeout(() => { + // console.info(`====>beforeEach setTimeout'`) + // }, 2000) + }) + afterEach(function () { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(function () { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + + it('ACTS_UIExtensionAbility_StartAbilityForResult_AsyncCallback_0100',0, async function (done) { + var subscriber + commonEvent.createSubscriber(ACTS_CallFunction).then(async (data) => { + console.info(`====>AsyncCallback_0100 createSubscriber ${data}`) + subscriber = data + commonEvent.subscribe(data, subscribeCallBack) + globalThis.context.startAbility({ + bundleName: 'com.example.mainhap', + abilityName: 'EntryAbility', + action: 'AsyncCallback_0100' + },(err) => { + console.info('====>startAbility err:' + JSON.stringify(err)); + }) + }) + + function subscribeCallBack(err, data) { + if(data.event == 'ACTS_CALL_EVENT') { + console.info(`====>AsyncCallback_0100 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(`====>AsyncCallback_0100 unSubscribeCallback 'ACTS_CALL_EVENT'`) + globalThis.terminate('AsyncCallback_0100') + done() + } + }) + + it('ACTS_UIExtensionAbility_StartAbilityForResult_AsyncCallback_0200',0, async function (done) { + await Driver.create().delayMs(2000) + var subscriber + commonEvent.createSubscriber(ACTS_CallFunction).then(async (data) => { + console.info(`====>AsyncCallback_0200 createSubscriber ${data}`) + subscriber = data + commonEvent.subscribe(data, subscribeCallBack) + globalThis.context.startAbility({ + bundleName: 'com.example.forresulttestsecond', + abilityName: 'EntryAbility', + action: 'AsyncCallback_0200' + },(err) => { + console.info('====>startAbility err:' + JSON.stringify(err)); + }) + }) + + function subscribeCallBack(err, data) { + if(data.event == 'ACTS_CALL_EVENT') { + console.info(`====>AsyncCallback_0200 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(`====>AsyncCallback_0200 unSubscribeCallback 'ACTS_CALL_EVENT'`) + setTimeout(() => { + abilityDelegator.executeShellCommand('aa force-stop com.example.forresulttestsecond').then(result =>{ + console.info('====>AsyncCallback_0200 unSubscribeCallback pkill ok' + JSON.stringify(result)); + done() + }).catch(err => { + console.info('====>AsyncCallback_0200 unSubscribeCallback pkill ng' + JSON.stringify(err)); + done() + }) + }, 2000) + } + }) + + it('ACTS_UIExtensionAbility_StartAbilityForResult_AsyncCallback_0300',0, async function (done) { + await Driver.create().delayMs(2000) + var subscriber + commonEvent.createSubscriber(ACTS_CallFunction).then(async (data) => { + console.info(`====>AsyncCallback_0300 createSubscriber ${data}`) + subscriber = data + commonEvent.subscribe(data, subscribeCallBack) + globalThis.context.startAbility({ + bundleName: 'com.example.mainhap', + abilityName: 'EntryAbility', + action: 'AsyncCallback_0300' + },(err) => { + console.info('====>start Own Ability err:' + JSON.stringify(err)); + }) + setTimeout(() => { + globalThis.context.startAbility({ + bundleName: 'com.example.forresulttestsecond', + abilityName: 'EntryAbility', + action: 'AsyncCallback_0300' + },(err) => { + console.info('====>start Another Ability err:' + JSON.stringify(err)); + }) + }, 2500); + }) + + function subscribeCallBack(err, data) { + if(data.event == 'ACTS_CALL_EVENT') { + console.info(`====>AsyncCallback_0300 subscribeCallBack 'ACTS_CALL_EVENT' ${data}`) + expect(data.parameters.result).assertEqual(-1); + } + if(data.event == 'ACTS_CALL_EVENT_ANOTHER') { + console.info(`====>AsyncCallback_0300 subscribeCallBack 'ACTS_CALL_EVENT_ANOTHER' ${data}`) + expect(data.parameters.str).assertEqual('ACTION'); + expect(data.parameters.result).assertEqual(0); + commonEvent.unsubscribe(subscriber, unSubscribeCallback) + } + } + + function unSubscribeCallback() { + console.info(`====>AsyncCallback_0300 unSubscribeCallback 'ACTS_CALL_EVENT'`) + setTimeout(() => { + globalThis.terminate('AsyncCallback_0300') + abilityDelegator.executeShellCommand('aa force-stop com.example.forresulttestsecond').then((result) =>{ + console.info('====>AsyncCallback_0300 unSubscribeCallback pkill ok' + JSON.stringify(result)); + done() + }).catch((err) => { + console.info('====>AsyncCallback_0300 unSubscribeCallback pkill ng' + JSON.stringify(err)); + done() + }) + }, 1000) + } + }) + + it('ACTS_UIExtensionAbility_StartAbilityForResult_AsyncCallback_0400',0, async function (done) { + await Driver.create().delayMs(2000) + var subscriber + commonEvent.createSubscriber(ACTS_CallFunction).then(async (data) => { + console.info(`====>AsyncCallback_0400 createSubscriber ${data}`) + subscriber = data + commonEvent.subscribe(data, subscribeCallBack) + globalThis.context.startAbility({ + bundleName: 'com.example.mainhap', + abilityName: 'EntryAbility', + action: 'AsyncCallback_0400' + },(err) => { + console.info('====>start Own Ability err:' + JSON.stringify(err)); + }) + + setTimeout(() => { + abilityDelegator.executeShellCommand('aa force-stop com.example.forresulttestsecond').then(result =>{ + console.info('====>AsyncCallback_0400 pkill ok' + JSON.stringify(result)); + }).catch(err => { + console.info('====>AsyncCallback_0400 pkill ng' + JSON.stringify(err)); + }) + }, 2000) + }) + + function subscribeCallBack(err, data) { + console.info(`====>AsyncCallback_0400 subscribeCallBack all ${data.event}`) + if(data.event == 'ACTS_CALL_EVENT') { + console.info(`====>AsyncCallback_0400 subscribeCallBack 'ACTS_CALL_EVENT' ${data}`) + expect(data.parameters.result).assertEqual(-1); + commonEvent.unsubscribe(subscriber, unSubscribeCallback) + } + } + + function unSubscribeCallback() { + console.info(`====>AsyncCallback_0400 unSubscribeCallback 'ACTS_CALL_EVENT'`) + + setTimeout(() => { + globalThis.terminate('AsyncCallback_0400') + done() + }, 1000) + } + }) + + it('ACTS_UIExtensionAbility_StartAbilityForResult_AsyncCallback_0500',0, async function (done) { + await Driver.create().delayMs(2000) + var subscriber + commonEvent.createSubscriber(ACTS_CallFunction).then(async (data) => { + console.info(`====>AsyncCallback_0500 createSubscriber ${data}`) + subscriber = data + commonEvent.subscribe(data, subscribeCallBack) + globalThis.context.startAbility({ + bundleName: 'com.example.mainhap', + abilityName: 'EntryAbility', + action: 'AsyncCallback_0500' + },(err) => { + console.info('====>start Own Ability err:' + JSON.stringify(err)); + }) + }) + + function subscribeCallBack(err, data) { + console.info(`====>AsyncCallback_0500 subscribeCallBack all ${data.event}`) + if(data.event == 'ACTS_CALL_EVENT') { + console.info(`====>AsyncCallback_0500 subscribeCallBack 'ACTS_CALL_EVENT' ${data}`) + expect(data.parameters.num).assertEqual(16000001); + commonEvent.unsubscribe(subscriber, unSubscribeCallback) + } + } + + function unSubscribeCallback() { + console.info(`====>AsyncCallback_0500 unSubscribeCallback 'ACTS_CALL_EVENT'`) + setTimeout(() => { + globalThis.terminate('AsyncCallback_0500') + done() + }, 2000) + } + }) + + it('ACTS_UIExtensionAbility_StartAbilityForResult_AsyncCallback_0600',0, async function (done) { + await Driver.create().delayMs(2000) + var subscriber + commonEvent.createSubscriber(ACTS_CallFunction).then(async (data) => { + console.info(`====>AsyncCallback_0600 createSubscriber ${data}`) + subscriber = data + commonEvent.subscribe(data, subscribeCallBack) + globalThis.context.startAbility({ + bundleName: 'com.example.forresulttestthrid', + abilityName: 'EntryAbility', + action: 'AsyncCallback_0600' + },(err) => { + console.info('====>start Own Ability err:' + JSON.stringify(err)); + }) + }) + + function subscribeCallBack(err, data) { + console.info(`====>AsyncCallback_0600 subscribeCallBack all ${data.event}`) + if(data.event == 'ACTS_CALL_EVENT') { + console.info(`====>AsyncCallback_0600 subscribeCallBack 'ACTS_CALL_EVENT' ${data}`) + console.info(`====>AsyncCallback_0600 subscribeCallBack ${data.parameters.num}`) + expect(data.parameters.num).assertEqual(16000004); + commonEvent.unsubscribe(subscriber, unSubscribeCallback) + } + } + + function unSubscribeCallback() { + console.info(`====>AsyncCallback_0600 unSubscribeCallback 'ACTS_CALL_EVENT'`) + setTimeout(() => { + abilityDelegator.executeShellCommand('aa force-stop com.example.forresulttestthrid').then(result =>{ + console.info('====>AsyncCallback_0600 unSubscribeCallback pkill ok' + JSON.stringify(result)); + done() + }).catch(err => { + console.info('====>AsyncCallback_0600 unSubscribeCallback pkill ng' + JSON.stringify(err)); + done() + }) + }, 1000) + } + }) + + + it('ACTS_UIExtensionAbility_StartAbilityForResult_AsyncCallback_0700',0, async function (done) { + await Driver.create().delayMs(2000) + var subscriber + commonEvent.createSubscriber(ACTS_CallFunction).then(async (data) => { + console.info(`====>AsyncCallback_0700 createSubscriber ${data}`) + subscriber = data + commonEvent.subscribe(data, subscribeCallBack) + globalThis.context.startAbility({ + bundleName: 'com.example.forresulttestthrid', + abilityName: 'EntryAbility', + action: 'AsyncCallback_0700' + },(err) => { + console.info('====>start Own Ability err:' + JSON.stringify(err)); + }) + }) + + function subscribeCallBack(err, data) { + console.info(`====>AsyncCallback_0700 subscribeCallBack all ${data.event}`) + if(data.event == 'ACTS_CALL_EVENT') { + console.info(`====>AsyncCallback_0700 subscribeCallBack 'ACTS_CALL_EVENT' ${data}`) + expect(data.parameters.num).assertEqual(201); + commonEvent.unsubscribe(subscriber, unSubscribeCallback) + } + } + + function unSubscribeCallback() { + console.info(`====>AsyncCallback_0700 unSubscribeCallback 'ACTS_CALL_EVENT'`) + + setTimeout(() => { + abilityDelegator.executeShellCommand('aa force-stop com.example.forresulttestthrid').then(result =>{ + console.info('====>AsyncCallback_0700 unSubscribeCallback pkill ok' + JSON.stringify(result)); + done() + }).catch(err => { + console.info('====>AsyncCallback_0700 unSubscribeCallback pkill ng' + JSON.stringify(err)); + done() + }) + }, 2000) + } + }) + + it('ACTS_UIExtensionAbility_StartAbilityForResult_Promise_0100',0, async function (done) { + await Driver.create().delayMs(2000) + var subscriber + commonEvent.createSubscriber(ACTS_CallFunction).then(async (data) => { + console.info(`====>Promise_0100 createSubscriber ${data}`) + subscriber = data + commonEvent.subscribe(data, subscribeCallBack) + globalThis.context.startAbility({ + bundleName: 'com.example.mainhap', + abilityName: 'EntryAbility', + action: 'Promise_0100' + },(err) => { + console.info('====>startAbility err:' + JSON.stringify(err)); + }) + }) + + function subscribeCallBack(err, data) { + if(data.event == 'ACTS_CALL_EVENT') { + console.info(`====>Promise_0100 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(`====>Promise_0100 unSubscribeCallback 'ACTS_CALL_EVENT'`) + globalThis.terminate('Promise_0100') + done() + } + }) + + it('ACTS_UIExtensionAbility_StartAbilityForResult_Promise_0200',0, async function (done) { + var subscriber + commonEvent.createSubscriber(ACTS_CallFunction).then(async (data) => { + console.info(`====>Promise_0200 createSubscriber ${data}`) + subscriber = data + commonEvent.subscribe(data, subscribeCallBack) + globalThis.context.startAbility({ + bundleName: 'com.example.forresulttestsecond', + abilityName: 'EntryAbility', + action: 'Promise_0200' + },(err) => { + console.info('====>startAbility err:' + JSON.stringify(err)); + }) + }) + + function subscribeCallBack(err, data) { + if(data.event == 'ACTS_CALL_EVENT') { + console.info(`====>Promise_0200 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(`====>Promise_0200 unSubscribeCallback 'ACTS_CALL_EVENT'`) + abilityDelegator.executeShellCommand('aa force-stop com.example.forresulttestsecond').then(result =>{ + console.info('====>Promise_0200 unSubscribeCallback pkill ok' + JSON.stringify(result)); + done() + }) + } + }) + + it('ACTS_UIExtensionAbility_StartAbilityForResult_Promise_0300',0, async function (done) { + await Driver.create().delayMs(2000) + var subscriber + await commonEvent.createSubscriber(ACTS_CallFunction).then(async (data) => { + console.info(`====>Promise_0300 createSubscriber ${data}`) + subscriber = data + commonEvent.subscribe(data, subscribeCallBack) + globalThis.context.startAbility({ + bundleName: 'com.example.mainhap', + abilityName: 'EntryAbility', + action: 'Promise_0300' + },(err) => { + console.info('====>start Own Ability err:' + JSON.stringify(err)); + }) + setTimeout(() => { + globalThis.context.startAbility({ + bundleName: 'com.example.forresulttestsecond', + abilityName: 'EntryAbility', + action: 'Promise_0300' + },(err) => { + console.info('====>start Another Ability err:' + JSON.stringify(err)); + }) + }, 2000); + }) + + function subscribeCallBack(err, data) { + if(data.event == 'ACTS_CALL_EVENT') { + console.info(`====>Promise_0300 subscribeCallBack 'ACTS_CALL_EVENT' ${data}`) + expect(data.parameters.result).assertEqual(-1); + } + if(data.event == 'ACTS_CALL_EVENT_ANOTHER') { + console.info(`====>Promise_0300 subscribeCallBack 'ACTS_CALL_EVENT_ANOTHER' ${data}`) + expect(data.parameters.str).assertEqual('ACTION'); + expect(data.parameters.result).assertEqual(0); + } + globalThis.terminate('Promise_0300') + abilityDelegator.executeShellCommand('aa force-stop com.example.forresulttestsecond').then(result =>{ + console.info('====>Promise_0300 unSubscribeCallback pkill ok' + JSON.stringify(result)); + commonEvent.unsubscribe(subscriber, unSubscribeCallback) + }).catch(err => { + console.info('====>Promise_0300 unSubscribeCallback pkill ng' + JSON.stringify(err)); + commonEvent.unsubscribe(subscriber, unSubscribeCallback) + }) + } + + function unSubscribeCallback() { + console.info(`====>Promise_0300 unSubscribeCallback 'ACTS_CALL_EVENT'`) + done() + } + }) + + it('ACTS_UIExtensionAbility_StartAbilityForResult_Promise_0400',0, async function (done) { + await Driver.create().delayMs(2000) + var subscriber + commonEvent.createSubscriber(ACTS_CallFunction).then(async (data) => { + console.info(`====>Promise_0400 createSubscriber ${data}`) + subscriber = data + commonEvent.subscribe(data, subscribeCallBack) + globalThis.context.startAbility({ + bundleName: 'com.example.mainhap', + abilityName: 'EntryAbility', + action: 'Promise_0400' + },(err) => { + console.info('====>start Own Ability err:' + JSON.stringify(err)); + }) + + setTimeout(() => { + abilityDelegator.executeShellCommand('aa force-stop com.example.forresulttestsecond').then(result =>{ + console.info('====>Promise_0400 pkill ok' + JSON.stringify(result)); + }).catch(err => { + console.info('====>Promise_0400 pkill ng' + JSON.stringify(err)); + }) + }, 2000) + }) + + function subscribeCallBack(err, data) { + console.info(`====>Promise_0400 subscribeCallBack all ${data.event}`) + if(data.event == 'ACTS_CALL_EVENT') { + console.info(`====>Promise_0400 subscribeCallBack 'ACTS_CALL_EVENT' ${data}`) + expect(data.parameters.result).assertEqual(-1); + commonEvent.unsubscribe(subscriber, unSubscribeCallback) + } + } + + function unSubscribeCallback() { + console.info(`====>Promise_0400 unSubscribeCallback 'ACTS_CALL_EVENT'`) + setTimeout(() => { + globalThis.terminate('Promise_0400') + done() + }, 1000) + } + }) + + it('ACTS_UIExtensionAbility_StartAbilityForResult_Promise_0500',0, async function (done) { + await Driver.create().delayMs(2000) + var subscriber + commonEvent.createSubscriber(ACTS_CallFunction).then(async (data) => { + console.info(`====>Promise_0500 createSubscriber ${data}`) + subscriber = data + commonEvent.subscribe(data, subscribeCallBack) + globalThis.context.startAbility({ + bundleName: 'com.example.mainhap', + abilityName: 'EntryAbility', + action: 'Promise_0500' + },(err) => { + console.info('====>start Own Ability err:' + JSON.stringify(err)); + }) + }) + + function subscribeCallBack(err, data) { + console.info(`====>Promise_0500 subscribeCallBack all ${data.event}`) + if(data.event == 'ACTS_CALL_EVENT') { + console.info(`====>Promise_0500 subscribeCallBack 'ACTS_CALL_EVENT' ${data}`) + expect(data.parameters.num).assertEqual(16000001); + commonEvent.unsubscribe(subscriber, unSubscribeCallback) + } + } + + function unSubscribeCallback() { + console.info(`====>Promise_0500 unSubscribeCallback 'ACTS_CALL_EVENT'`) + globalThis.terminate('Promise_0500') + setTimeout(() => { + done() + }, 1000) + } + }) + + it('ACTS_UIExtensionAbility_StartAbilityForResult_Promise_0600',0, async function (done) { + await Driver.create().delayMs(2000) + var subscriber + commonEvent.createSubscriber(ACTS_CallFunction).then(async (data) => { + console.info(`====>Promise_0600 createSubscriber ${data}`) + subscriber = data + commonEvent.subscribe(data, subscribeCallBack) + globalThis.context.startAbility({ + bundleName: 'com.example.forresulttestthrid', + abilityName: 'EntryAbility', + action: 'Promise_0600' + },(err) => { + console.info('====>start Own Ability err:' + JSON.stringify(err)); + }) + }) + + function subscribeCallBack(err, data) { + console.info(`====>Promise_0600 subscribeCallBack all ${data.event}`) + if(data.event == 'ACTS_CALL_EVENT') { + console.info(`====>Promise_0600 subscribeCallBack 'ACTS_CALL_EVENT' ${data}`) + console.info(`====>Promise_0600 subscribeCallBack ${data.parameters.num}`) + expect(data.parameters.num).assertEqual(16000004); + commonEvent.unsubscribe(subscriber, unSubscribeCallback) + } + } + + function unSubscribeCallback() { + console.info(`====>Promise_0600 unSubscribeCallback 'ACTS_CALL_EVENT'`) + setTimeout(() => { + abilityDelegator.executeShellCommand('aa force-stop com.example.forresulttestthrid').then(result =>{ + console.info('====>AsyncCallback_0600 unSubscribeCallback pkill ok' + JSON.stringify(result)); + done() + }).catch(err => { + console.info('====>AsyncCallback_0600 unSubscribeCallback pkill ng' + JSON.stringify(err)); + done() + }) + }, 2000) + } + }) + + it('ACTS_UIExtensionAbility_StartAbilityForResult_Promise_0700',0, async function (done) { + await Driver.create().delayMs(2000) + var subscriber + commonEvent.createSubscriber(ACTS_CallFunction).then(async (data) => { + console.info(`====>Promise_0700 createSubscriber ${data}`) + subscriber = data + commonEvent.subscribe(data, subscribeCallBack) + globalThis.context.startAbility({ + bundleName: 'com.example.forresulttestthrid', + abilityName: 'EntryAbility', + action: 'Promise_0700' + },(err) => { + console.info('====>start Own Ability err:' + JSON.stringify(err)); + }) + }) + + function subscribeCallBack(err, data) { + console.info(`====>Promise_0700 subscribeCallBack all ${data.event}`) + if(data.event == 'ACTS_CALL_EVENT') { + console.info(`====>Promise_0700 subscribeCallBack 'ACTS_CALL_EVENT' ${data}`) + expect(data.parameters.num).assertEqual(201); + commonEvent.unsubscribe(subscriber, unSubscribeCallback) + } + } + + function unSubscribeCallback() { + console.info(`====>Promise_0700 unSubscribeCallback 'ACTS_CALL_EVENT'`) + setTimeout(() => { + abilityDelegator.executeShellCommand('aa force-stop com.example.forresulttestthrid').then(result =>{ + console.info('====>AsyncCallback_0700 unSubscribeCallback pkill ok' + JSON.stringify(result)); + done() + }).catch(err => { + console.info('====>AsyncCallback_0700 unSubscribeCallback pkill ng' + JSON.stringify(err)); + done() + }) + }, 2000) + } + }) + }) +} \ No newline at end of file diff --git a/ability/ability_runtime/actsforresult/maintest/entry/src/main/ets/test/List.test.ets b/ability/ability_runtime/actsforresult/maintest/entry/src/main/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..cb2e22661cde4c6c3e986a6718061d089e25fcd5 --- /dev/null +++ b/ability/ability_runtime/actsforresult/maintest/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/actsforresult/maintest/entry/src/main/ets/testability/TestAbility.ets b/ability/ability_runtime/actsforresult/maintest/entry/src/main/ets/testability/TestAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..023a7ed1014fc1a2b4b029b8d467b8a885405c25 --- /dev/null +++ b/ability/ability_runtime/actsforresult/maintest/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/actsforresult/maintest/entry/src/main/ets/testability/pages/Index.ets b/ability/ability_runtime/actsforresult/maintest/entry/src/main/ets/testability/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..0f2b6deeea936c3fb160ebb5d75b511554408287 --- /dev/null +++ b/ability/ability_runtime/actsforresult/maintest/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/actsforresult/maintest/entry/src/main/module.json b/ability/ability_runtime/actsforresult/maintest/entry/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..83894d37b71428d6a6a0c5041faf88568d249b16 --- /dev/null +++ b/ability/ability_runtime/actsforresult/maintest/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/actsforresult/maintest/entry/src/main/resources/base/element/color.json b/ability/ability_runtime/actsforresult/maintest/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ability/ability_runtime/actsforresult/maintest/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/actsforresult/maintest/entry/src/main/resources/base/element/string.json b/ability/ability_runtime/actsforresult/maintest/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..65d8fa5a7cf54aa3943dcd0214f58d1771bc1f6c --- /dev/null +++ b/ability/ability_runtime/actsforresult/maintest/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/actsforresult/maintest/entry/src/main/resources/base/media/icon.png b/ability/ability_runtime/actsforresult/maintest/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ability/ability_runtime/actsforresult/maintest/entry/src/main/resources/base/media/icon.png differ diff --git a/ability/ability_runtime/actsforresult/maintest/entry/src/main/resources/base/profile/test_pages.json b/ability/ability_runtime/actsforresult/maintest/entry/src/main/resources/base/profile/test_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..b7e7343cacb32ce982a45e76daad86e435e054fe --- /dev/null +++ b/ability/ability_runtime/actsforresult/maintest/entry/src/main/resources/base/profile/test_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "testability/pages/Index" + ] +} diff --git a/ability/ability_runtime/actsforresult/maintest/signature/openharmony_sx.p7b b/ability/ability_runtime/actsforresult/maintest/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..4edeeb9a19094e2e10903ccd7ceebc421357aa06 Binary files /dev/null and b/ability/ability_runtime/actsforresult/maintest/signature/openharmony_sx.p7b differ