From e583bbfeeeb62f4ec15d8a1bbbad8a482350f5a0 Mon Sep 17 00:00:00 2001 From: HuangXW Date: Wed, 19 Oct 2022 20:19:49 +0800 Subject: [PATCH] =?UTF-8?q?fixed=2013f2f62=20from=20https://gitee.com/H-xi?= =?UTF-8?q?nwei/xts=5Facts/pulls/6028=20FaApiTest=20serviceAbility?= =?UTF-8?q?=E5=85=B3=E8=81=94=E5=90=AF=E5=8A=A8=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I80bcf74dd5c9a2631a2bc46cd7c178200c16fc5a Signed-off-by: HuangXW --- .../faapicover/faapicoverhaptest/BUILD.gn | 8 +- .../entry/src/main/config.json | 18 +++ .../src/main/ets/ServiceAbility/service.ts | 103 ++++++++++++++++++ .../src/main/ets/ServiceAbility2/service.ts | 90 +++++++++++++++ .../src/main/ets/test/VerificationTest.ets | 8 +- .../main/resources/base/element/string.json | 8 ++ 6 files changed, 226 insertions(+), 9 deletions(-) create mode 100755 ability/ability_runtime/faapicover/faapicoverhaptest/entry/src/main/ets/ServiceAbility/service.ts create mode 100755 ability/ability_runtime/faapicover/faapicoverhaptest/entry/src/main/ets/ServiceAbility2/service.ts diff --git a/ability/ability_runtime/faapicover/faapicoverhaptest/BUILD.gn b/ability/ability_runtime/faapicover/faapicoverhaptest/BUILD.gn index 8f1238c2a..dcfca5483 100644 --- a/ability/ability_runtime/faapicover/faapicoverhaptest/BUILD.gn +++ b/ability/ability_runtime/faapicover/faapicoverhaptest/BUILD.gn @@ -18,7 +18,6 @@ ohos_js_hap_suite("ActsFaApiCoverTest") { deps = [ ":faapicoverhaptest_ets_assets", ":faapicoverhaptest_ets_resources", - ":faapicoverhaptest_ets_test_assets", ] ets2abc = true certificate_profile = "./signature/openharmony_sx.p7b" @@ -27,10 +26,9 @@ ohos_js_hap_suite("ActsFaApiCoverTest") { part_name = "ability_runtime" } ohos_js_assets("faapicoverhaptest_ets_assets") { - source_dir = "./entry/src/main/ets/MainAbility" -} -ohos_js_assets("faapicoverhaptest_ets_test_assets") { - source_dir = "./entry/src/main/ets/TestAbility" + source_dir = "entry/src/main/ets" + hap_profile = "entry/src/main/config.json" + ets2abc = true } ohos_resources("faapicoverhaptest_ets_resources") { sources = [ "./entry/src/main/resources" ] diff --git a/ability/ability_runtime/faapicover/faapicoverhaptest/entry/src/main/config.json b/ability/ability_runtime/faapicover/faapicoverhaptest/entry/src/main/config.json index 378a138d5..3942892c9 100644 --- a/ability/ability_runtime/faapicover/faapicoverhaptest/entry/src/main/config.json +++ b/ability/ability_runtime/faapicover/faapicoverhaptest/entry/src/main/config.json @@ -54,6 +54,24 @@ "type": "page", "visible": true, "launchType": "singleton" + }, + { + "srcPath": "ServiceAbility", + "name": ".ServiceAbility", + "srcLanguage": "ets", + "icon": "$media:icon", + "description": "$string:ServiceAbility_desc", + "type": "service", + "visible": true + }, + { + "srcPath": "ServiceAbility2", + "name": ".ServiceAbility2", + "srcLanguage": "ets", + "icon": "$media:icon", + "description": "$string:ServiceAbility2_desc", + "type": "service", + "visible": true } ], "distro": { diff --git a/ability/ability_runtime/faapicover/faapicoverhaptest/entry/src/main/ets/ServiceAbility/service.ts b/ability/ability_runtime/faapicover/faapicoverhaptest/entry/src/main/ets/ServiceAbility/service.ts new file mode 100755 index 000000000..7ca86911a --- /dev/null +++ b/ability/ability_runtime/faapicover/faapicoverhaptest/entry/src/main/ets/ServiceAbility/service.ts @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import rpc from "@ohos.rpc"; +import commonEvent from '@ohos.commonEvent'; +import ability_particleAbility from '@ohos.ability.particleAbility'; + +class StubTest1 extends rpc.RemoteObject { + constructor(des) { + if (typeof des === 'string') { + super(des); + } + else { + return null; + } + } + queryLocalInterface(descriptor) { + return null; + } + getInterfaceDescriptor() { + return ""; + } + sendRequest(code, data, reply, options) { + return null; + } + getCallingPid() { + return 0; + } + getCallingUid() { + return 0; + } + attachLocalInterface(localInterface, descriptor) { } + onRemoteRequest(code, data, reply, options) { + console.info(printLogS1 + "onRemoteRequest"); + if (code == 1) { + console.info(printLogS1 + "onRemoteRequest code 1"); + let op1 = data.readInt(); + let op2 = data.readInt(); + console.info(printLogS1 + "onRemoteRequest op1 = " + op1 + ", op2 = " + op2); + reply.writeInt(op1 + op2); + } + else { + console.info(printLogS1 + "onRemoteRequest code = " + code); + } + return true; + } +} + +var printLogS1 = "Fa:Auxiliary:ServiceAbility:"; +var listPushS1 = "Fa_Auxiliary_ServiceAbility_"; +export default { + onStart() { + console.info(printLogS1 + 'onStart'); + + commonEvent.publish(listPushS1 + "onStart", (err) => { + console.info(printLogS1 + listPushS1 + "onStart"); + }); + }, + onStop() { + console.info(printLogS1 + 'onStop'); + + commonEvent.publish(listPushS1 + "onStop", (err) => { + console.info(printLogS1 + listPushS1 + "onStop"); + }); + }, + onCommand(want, startId) { + console.info(printLogS1 + 'onCommand'); + + commonEvent.publish(listPushS1 + "onCommand", (err) => { + console.info(printLogS1 + listPushS1 + "onCommand"); + }); + + setTimeout(()=>{ + ability_particleAbility.terminateSelf().then((data) => { + console.info(printLogS1 + "terminateSelf data = " + JSON.stringify(data)); + }).catch((err) => { + console.info(printLogS1 + "terminateSelf err = " + JSON.stringify(err)); + }); + }, 3000) + }, + onConnect(want) { + console.info(printLogS1 + 'onConnect'); + + return new StubTest1("Test1"); + }, + onDisconnect(want) { + console.info(printLogS1 + 'onDisconnect'); + }, + onReconnect(want) { + console.info(printLogS1 + 'onReconnect'); + } +}; \ No newline at end of file diff --git a/ability/ability_runtime/faapicover/faapicoverhaptest/entry/src/main/ets/ServiceAbility2/service.ts b/ability/ability_runtime/faapicover/faapicoverhaptest/entry/src/main/ets/ServiceAbility2/service.ts new file mode 100755 index 000000000..237859c2d --- /dev/null +++ b/ability/ability_runtime/faapicover/faapicoverhaptest/entry/src/main/ets/ServiceAbility2/service.ts @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import rpc from "@ohos.rpc"; +import commonEvent from '@ohos.commonEvent'; + +class StubTest2 extends rpc.RemoteObject { + constructor(des) { + if (typeof des === 'string') { + super(des); + } + else { + return null; + } + } + queryLocalInterface(descriptor) { + return null; + } + getInterfaceDescriptor() { + return ""; + } + sendRequest(code, data, reply, options) { + return null; + } + getCallingPid() { + return 0; + } + getCallingUid() { + return 0; + } + attachLocalInterface(localInterface, descriptor) { } + onRemoteRequest(code, data, reply, options) { + console.info(printLogS1 + "onRemoteRequest"); + if (code == 1) { + console.info(printLogS1 + "onRemoteRequest code 1"); + let op1 = data.readInt(); + let op2 = data.readInt(); + console.info(printLogS1 + "onRemoteRequest op1 = " + op1 + ", op2 = " + op2); + reply.writeInt(op1 + op2); + } + else { + console.info(printLogS1 + "onRemoteRequest code = " + code); + } + return true; + } +} + +var printLogS1 = "Fa:Auxiliary:ServiceAbility2:"; +var listPushS1 = "Fa_Auxiliary_ServiceAbility2_"; +export default { + onStart() { + console.info(printLogS1 + 'onStart'); + }, + onStop() { + console.info(printLogS1 + 'onStop'); + }, + onCommand(want, startId) { + console.info(printLogS1 + 'onCommand'); + }, + onConnect(want) { + console.info(printLogS1 + 'onConnect'); + + commonEvent.publish(listPushS1 + "onConnect", (err) => { + console.info(printLogS1 + listPushS1 + "onCreate"); + }); + + return new StubTest2("Test1"); + }, + onDisconnect(want) { + console.info(printLogS1 + 'onDisconnect'); + + commonEvent.publish(listPushS1 + "onDisconnect", (err) => { + console.info(printLogS1 + listPushS1 + "onDisconnect"); + }); + }, + onReconnect(want) { + console.info(printLogS1 + 'onReconnect'); + } +}; \ No newline at end of file diff --git a/ability/ability_runtime/faapicover/faapicoverhaptest/entry/src/main/ets/test/VerificationTest.ets b/ability/ability_runtime/faapicover/faapicoverhaptest/entry/src/main/ets/test/VerificationTest.ets index efe1453e2..7c55feff7 100644 --- a/ability/ability_runtime/faapicover/faapicoverhaptest/entry/src/main/ets/test/VerificationTest.ets +++ b/ability/ability_runtime/faapicover/faapicoverhaptest/entry/src/main/ets/test/VerificationTest.ets @@ -307,8 +307,8 @@ export default function verificationTest(){ let wantNum = { want: { - bundleName: 'ohos.acts.aafwk.test.faauxiliary', - abilityName: 'ohos.acts.aafwk.test.faauxiliary.ServiceAbility' + bundleName: 'com.example.faapicoverhaptest', + abilityName: 'com.example.faapicoverhaptest.ServiceAbility' } } await ability_featureAbility.startAbility(wantNum).then((data) => { @@ -406,8 +406,8 @@ export default function verificationTest(){ } }; let wantNum = { - bundleName: 'ohos.acts.aafwk.test.faauxiliary', - abilityName: 'ohos.acts.aafwk.test.faauxiliary.ServiceAbility2' + bundleName: 'com.example.faapicoverhaptest', + abilityName: 'com.example.faapicoverhaptest.ServiceAbility2' } let num = ability_featureAbility.connectAbility(wantNum, options) } catch (err) { diff --git a/ability/ability_runtime/faapicover/faapicoverhaptest/entry/src/main/resources/base/element/string.json b/ability/ability_runtime/faapicover/faapicoverhaptest/entry/src/main/resources/base/element/string.json index 9eac6dadc..b321c60e3 100644 --- a/ability/ability_runtime/faapicover/faapicoverhaptest/entry/src/main/resources/base/element/string.json +++ b/ability/ability_runtime/faapicover/faapicoverhaptest/entry/src/main/resources/base/element/string.json @@ -19,6 +19,14 @@ { "name": "TestAbility_label", "value": "label" + }, + { + "name": "ServiceAbility_desc", + "value": "hap sample empty service" + }, + { + "name": "ServiceAbility2_desc", + "value": "hap sample empty service" } ] } \ No newline at end of file -- GitLab