diff --git a/IPC/IPC_sendMessage/IPC_Client/AppScope/app.json5 b/IPC/IPC_sendMessage/IPC_Client/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d7070fa40e0c0f999a6f37fdeda443e08e6144ce --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Client/AppScope/app.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "app": { + "bundleName": "com.example.ipc_client", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/IPC/IPC_sendMessage/IPC_Client/AppScope/resources/base/element/string.json b/IPC/IPC_sendMessage/IPC_Client/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..db518a909ef6b4107e97d3cc3ed170c74a097168 --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Client/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "IPC_Client" + } + ] +} diff --git a/IPC/IPC_sendMessage/IPC_Client/AppScope/resources/base/media/background.png b/IPC/IPC_sendMessage/IPC_Client/AppScope/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/IPC/IPC_sendMessage/IPC_Client/AppScope/resources/base/media/background.png differ diff --git a/IPC/IPC_sendMessage/IPC_Client/AppScope/resources/base/media/foreground.png b/IPC/IPC_sendMessage/IPC_Client/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..eb9427585b36d14b12477435b6419d1f07b3e0bb Binary files /dev/null and b/IPC/IPC_sendMessage/IPC_Client/AppScope/resources/base/media/foreground.png differ diff --git a/IPC/IPC_sendMessage/IPC_Client/AppScope/resources/base/media/layered_image.json b/IPC/IPC_sendMessage/IPC_Client/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Client/AppScope/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/IPC/IPC_sendMessage/IPC_Client/README.md b/IPC/IPC_sendMessage/IPC_Client/README.md new file mode 100644 index 0000000000000000000000000000000000000000..b77a8c5a677af5c3ece5f4fe90c5b5ff05e6590c --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Client/README.md @@ -0,0 +1,290 @@ +# IPC通信示例 + +## 介绍 + +本示例展示了如何使用[@ohos.rpc](https://gitcode.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ipc-kit/js-apis-rpc.md) 相关接口,开发一个IPC客户端与服务端通信的完整示例。在此示例中仅演示如何传递字符串信息,若有除此之外接口的诉求,请自行参考接口文档中的示例代码。 + +## 效果预览 + +|客户端|服务端| +|-------------------------|----------------------| +|![](image/IPC_Client.png)|![](image/IPC_Stub.png)| + +使用说明: + +1. 点击 connectAbility 按钮进行连接服务端,获取到服务端的代理对象proxy,并在此时注册死亡监听,当服务端所在进程死亡时,会触发此监听,提示服务端已死亡,并断开连接服务端; +2. 点击 sendRequest_string 按钮传递字符串信息至服务端,服务端会收到这次传递的字符串('hello world'),并返回字符串('hello rpc')到客户端,代表此次通信结束; +3. 点击 disconnectAbility 按钮断开连接服务端。 + +## 工程目录 + +1. 客户端-IPC_Client + +``` +entry/src/main/ets/ +|---entryability +| |---EntryAbility.ets +|---entrybackupability +| |---EntryBackupAbility.ets +|---pages +| |---Index.ets // 页面布局、客户端实现 +``` + +2. 服务端-IPC_Service + +``` +entry/src/main/ets/ +|---entryability +| |---EntryAbility.ets +|---entrybackupability +| |---EntryBackupAbility.ets +|---pages +| |---Index.ets +|---serviceeextability +| |---ServiceExtAbility.ets // 服务端实现 +``` + +以上工程目录中未进行说明的部分,是默认工程目录结构,并未进行修改。 + +## 具体实现 + +1. 创建ServiceExtensionAbility,实现服务端 + + ```ets + // 定义服务端 + class Stub extends rpc.RemoteObject { + constructor(descriptor: string) { + super(descriptor); + } + onRemoteMessageRequest(code: number, data: rpc.MessageSequence, reply: rpc.MessageSequence, option: rpc.MessageOption): boolean | Promise { + // 服务端Stub根据不同的请求code分别执行对应的处理流程 + if (code == 1) { + let str = data.readString(); + hilog.info(0x0000, 'testTag', 'IPCStub: stub receive str : ' + str); + // 服务端使用reply回传请求处理的结果给客户端 + reply.writeString('hello rpc'); + return true; + } else { + hilog.info(0x0000, 'testTag', 'IPCStub: stub unknown code: ' + code); + return false; + } + } + } + + // 定义后台服务 + export default class ServiceAbility extends ServiceExtensionAbility { + // ...... + + onConnect(want: Want): rpc.RemoteObject { + hilog.info(0x0000, 'testTag', 'IPCStub: onConnect'); + // 返回Stub对象,客户端获取后便可以与ServiceExtensionAbility进行通信 + return new Stub('IPCStubTest'); + } + + // ...... + } + ``` + +2. 客户端连接服务 + + ```ets + function connectAbility(context:common.UIAbilityContext) { + hilog.info(0x00000, 'testTag', 'IPCClient: begin to connect Ability'); + + let connect: common.ConnectOptions = { + onConnect: (elementName, remoteProxy) => { + hilog.info(0x00000, 'testTag', 'IPCClient: onConnect. elementName is :' + JSON.stringify(elementName)); + proxy = remoteProxy; + // 客户端注册死亡监听 + try { + proxy.registerDeathRecipient(deathRecipient, 0); + hilog.info(0x00000, 'testTag', 'IPCClient: registerDeathRecipient success'); + }catch (err) { + let code = (err as BusinessError).code; + let message = (err as BusinessError).message; + hilog.error(0x0000, 'testTag', 'IPCClient: registerDeathRecipient failed, code is ' + code + ', message is ' + message); + } + }, + onDisconnect: (elementName) => { + hilog.info(0x0000, 'testTag', 'IPCClient: onDisconnect. elementName is :' + JSON.stringify(elementName)); + // 客户端移除死亡监听 + try { + proxy?.unregisterDeathRecipient(deathRecipient, 0); + hilog.info(0x00000, 'testTag', 'IPCClient: unregisterDeathRecipient success'); + }catch (err) { + let code = (err as BusinessError).code; + let message = (err as BusinessError).message; + hilog.error(0x0000, 'testTag', 'IPCClient: unregisterDeathRecipient failed, code is ' + code + ', message is ' + message); + } + proxy = undefined; + }, + onFailed: (code: number) => { + hilog.info(0x0000, 'testTag', 'IPCClient: onFailed. code is :' + code); + }, + } + + try { + connectId = context.connectServiceExtensionAbility(want, connect); + }catch (err) { + let code = (err as BusinessError).code; + let message = (err as BusinessError).message; + hilog.error(0x0000, 'testTag', 'IPCClient: connectAbility failed, code is ' + code + ', message is ' + message); + } + } + ``` + +3. 客户端发送字符串给服务端 + + ```ets + function sendString() { + hilog.info(0x00000, 'testTag', 'IPCClient: begin to send String'); + let option = new rpc.MessageOption(); + let data = rpc.MessageSequence.create(); + let reply = rpc.MessageSequence.create(); + // 在data里写入参数,以传递字符串为例 + data.writeString('hello world'); + if (proxy != undefined) { + proxy.sendMessageRequest(1, data, reply, option) + .then((result: rpc.RequestResult) => { + if (result.errCode != 0) { + hilog.error(0x0000, 'testTag', 'IPCClient: sendMessageRequest failed, errCode: ' + result.errCode); + return; + } + // 从result.reply里读取结果 + let str = result.reply.readString(); + hilog.info(0x0000, 'testTag', 'IPCClient: sendMessageRequest receive str: ' + str); + }) + .catch((e: Error) => { + hilog.error(0x0000, 'testTag', 'IPCClient: sendMessageRequest failed, error is ' + JSON.stringify(e)); + }) + .finally(() => { + data.reclaim(); + reply.reclaim(); + }) + } + } + ``` + +4. 客户端断开连接服务 + + ```ets + function disconnectAbility(context: common.UIAbilityContext) { + hilog.info(0x00000, 'testTag', 'IPCClient: begin to disconnect Ability'); + if (connectId != undefined) { + try { + context.disconnectServiceExtensionAbility(connectId); + }catch (err) { + let code = (err as BusinessError).code; + let message = (err as BusinessError).message; + hilog.error(0x0000, 'testTag', 'IPCClient: disconnectAbility failed, code is ' + code + ', message is ' + message); + } + } + } + ``` + +## 相关权限 + +不涉及 + +## 依赖 + +本示例中按键之间存在依赖关系,具体依赖如下: + +1. 服务端需保持在后台运行状态下,客户端才可以进行连接服务的操作('connectAbility'); +2. 在连接服务成功的情况下,客户端才可进行发送信息的操作('sendRequest_string'); +3. 在建立连接的情况下,客户端才可进行断连的操作('disconnectAbility')。 + + +## 约束与限制 + +1. 本示例仅支持标准系统上运行,支持设备:RK3568。 + +2. 本示例推荐使用DevEco Studio 5.0.2 Beta1 (Build Version: 5.0.7.100 构建 2025年1月16日)及以上版本编译运行。 + +3. 本示例需要使用@ohos.app.ability.ServiceExtensionAbility,该模块仅对系统应用开放,业务使用时,需自行替换当前工程中的SDK为FULL SDK。使用Full SDK时需要手动从镜像站点获取,并在DevEcoStudio中替换,具体操作可参考[替换指南](https://gitcode.com/openharmony/docs/blob/master/zh-cn/application-dev/faqs/full-sdk-switch-guide.md) 。 + +4. 本示例使用了ServiceExtensionAbility,需要在module.json5中进行相应的配置。如下: + +在服务端entry下的module.json5中配置如下字段:[module.json5](../IPC_Stub/entry/src/main/module.json5),参考第48-54行。 + + ``` + "extensionAbilities": [ + { + "name": "ServiceAbility", + "srcEntry": "./ets/serviceextability/ServiceExtAbility.ets", + "type": "service", + "exported": true, + "description": "service" + } + ] + ``` + +## 下载 + +如需单独下载本工程及服务端,执行如下命令: + + ``` + git init + git config core.sparsecheckout true + echo IPC/IPC_sendMessage/ > .git/info/sparse-checkout + git remote add origin https://gitcode.com/harmonyos_samples/guide-snippets.git + git pull origin master + ``` + +## 安装问题(9568344) + +因上述应用的module.json5中extensionAbilities字段中type属性为service,普通的安装方法会报错,需要按照以下方式进行安装: + +1. 注释module.json5中extensionAbilities字段 + +![](image/comment.png) + +2. 获取app_signature + + ``` + hdc shell bm dump -n | findstr finger + ``` + +![](image/app_signature.png) + +3. 添加白名单 + +将rk设备的install_list_capability.json配置文件拉取到本地 + + ``` + hdc shell mount -o rw,remount / + hdc file recv /system/etc/app/install_list_capability.json ---rk的方式 + ``` + +![](image/recv_install_list_capability.png) + +在拉下来的json文件中添加不能安装成功的应用,格式如下: + + ``` + { + "install_list": [ + { + ...... + }, + { + "bundleName": "应用包名", + "app_signature" : ["上面获取的app_signature"], + "allowAppUsePrivilegeExtension": true + } + ] + } + ``` + +![](image/configure.png) + +4. 将修改后的白名单推送到设备上进行替换并重启 + + ``` + hdc shell mount -o rw,remount / + hdc file send install_list_capability.json /system/etc/app/install_list_capability.json + hdc shell chmod 777 /system/etc/app/install_list_capability.json + hdc shell reboot + ``` + +5. 取消module.json5中extensionAbilities的相关注释,重新安装hap包 + \ No newline at end of file diff --git a/IPC/IPC_sendMessage/IPC_Client/build-profile.json5 b/IPC/IPC_sendMessage/IPC_Client/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..615f9b9326f3549d18494fa69ab6f14456415f3e --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Client/build-profile.json5 @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "app": { + "signingConfigs": [ + { + "name": "default", + "type": "HarmonyOS", + "material": { + "certpath": "C:\\Users\\Administrator\\.ohos\\config\\default_IPC_Client_sP0z0N78HFU16JBps1vFXtLU59GptJMmH1SSpp-CIuI=.cer", + "keyAlias": "debugKey", + "keyPassword": "0000001B0BBFE6050B6E794C0BC2A752EF8760B380AAB8DD6B852A78DABDEC9DD7987193378D4216650106", + "profile": "C:\\Users\\Administrator\\.ohos\\config\\default_IPC_Client_sP0z0N78HFU16JBps1vFXtLU59GptJMmH1SSpp-CIuI=.p7b", + "signAlg": "SHA256withECDSA", + "storeFile": "C:\\Users\\Administrator\\.ohos\\config\\default_IPC_Client_sP0z0N78HFU16JBps1vFXtLU59GptJMmH1SSpp-CIuI=.p12", + "storePassword": "0000001B4FB90C6E6DA65B6EEEA69006990A396DA428D16ABED5A659EC16337491A7DBF618B8BAD3D1784B" + } + } + ], + "products": [ + { + "name": "default", + "signingConfig": "default", + "targetSdkVersion": "6.0.0(20)", + "compatibleSdkVersion": "6.0.0(20)", + "runtimeOS": "HarmonyOS", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/IPC/IPC_sendMessage/IPC_Client/entry/.gitignore b/IPC/IPC_sendMessage/IPC_Client/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Client/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/IPC/IPC_sendMessage/IPC_Client/entry/build-profile.json5 b/IPC/IPC_sendMessage/IPC_Client/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7961c5611ea6da0aba83dbb6b484f28ac3788a7 --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Client/entry/build-profile.json5 @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "resOptions": { + "copyCodeResource": { + "enable": false + } + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/IPC/IPC_sendMessage/IPC_Client/entry/hvigorfile.ts b/IPC/IPC_sendMessage/IPC_Client/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..10f881f112b08550ed5c8a3ceb7d0148be2a0b6e --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Client/entry/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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 { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins: [] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file diff --git a/IPC/IPC_sendMessage/IPC_Client/entry/obfuscation-rules.txt b/IPC/IPC_sendMessage/IPC_Client/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Client/entry/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/IPC/IPC_sendMessage/IPC_Client/entry/oh-package.json5 b/IPC/IPC_sendMessage/IPC_Client/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..114cb176e4a4d08801ddb6ddf39ef3d0df76dc2f --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Client/entry/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/IPC/IPC_sendMessage/IPC_Client/entry/src/main/ets/entryability/EntryAbility.ets b/IPC/IPC_sendMessage/IPC_Client/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..5592b0500ad9887e46faa0d87b1302003aeb200b --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Client/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2025 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 { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +const DOMAIN = 0x0000; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + try { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + } catch (err) { + hilog.error(DOMAIN, 'testTag', 'Failed to set colorMode. Cause: %{public}s', JSON.stringify(err)); + } + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/IPC/IPC_sendMessage/IPC_Client/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/IPC/IPC_sendMessage/IPC_Client/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b37e4b57cd7849ab462574297ff70345c2132ab2 --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Client/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025 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 '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +const DOMAIN = 0x0000; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(DOMAIN, 'testTag', 'onBackup ok'); + await Promise.resolve(); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(DOMAIN, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + await Promise.resolve(); + } +} \ No newline at end of file diff --git a/IPC/IPC_sendMessage/IPC_Client/entry/src/main/ets/pages/Index.ets b/IPC/IPC_sendMessage/IPC_Client/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..237a8b20a5a737f6fd26cc98c9c995ff510efd3d --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Client/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,172 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start front-end_dependencies] +import { BusinessError } from '@kit.BasicServicesKit'; +import { Want, common } from '@kit.AbilityKit'; +import { rpc } from '@kit.IPCKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +let proxy: rpc.IRemoteObject | undefined; +let connectId: number | undefined; + +// 死亡通知 +class MyDeathRecipient implements rpc.DeathRecipient{ + onRemoteDied() { + hilog.info(0x0000, 'testTag', 'IPCClient: server is died'); + } +} +let deathRecipient = new MyDeathRecipient(); +// [End front-end_dependencies] + +@Entry +@Component +struct ButtonCase1 { + + // [Start define_context] + private context = this.getUIContext().getHostContext() as common.UIAbilityContext; + // [End define_context] + pathStack: NavPathStack = new NavPathStack(); + + build() { + Navigation(this.pathStack) { + List({ space: 30 }) { + + ListItem() { + Button('connectAbility').onClick(() => { + connectAbility(this.context); + }) + .width('100%') + } + + ListItem() { + Button('sendRequest_string').onClick(() => { + sendString(); + }) + .width('100%') + } + + ListItem() { + Button('disconnectAbility').onClick(() => { + disconnectAbility(this.context); + }) + .width('100%') + } + } + .listDirection(Axis.Vertical) + .backgroundColor(0xDCDCDC).padding(20) + } + .mode(NavigationMode.Stack) + } +} + +// [Start funcation_implement] +// [Start connect_ability] +// 连接服务 +function connectAbility(context:common.UIAbilityContext) { + hilog.info(0x00000, 'testTag', 'IPCClient: begin to connect Ability'); + let want: Want = { + bundleName: 'com.example.ipc_stub', + abilityName: 'ServiceAbility', + }; + let connect: common.ConnectOptions = { + onConnect: (elementName, remoteProxy) => { + hilog.info(0x00000, 'testTag', 'IPCClient: onConnect. elementName is :' + JSON.stringify(elementName)); + proxy = remoteProxy; + // 客户端注册死亡监听 + try { + proxy.registerDeathRecipient(deathRecipient, 0); + hilog.info(0x00000, 'testTag', 'IPCClient: registerDeathRecipient success'); + }catch (err) { + let code = (err as BusinessError).code; + let message = (err as BusinessError).message; + hilog.error(0x0000, 'testTag', 'IPCClient: register failed, code is ' + code + ', message is ' + message); + } + }, + onDisconnect: (elementName) => { + hilog.info(0x0000, 'testTag', 'IPCClient: onDisconnect. elementName is ' + JSON.stringify(elementName)); + // 客户端移除死亡监听 + try { + proxy?.unregisterDeathRecipient(deathRecipient, 0); + hilog.info(0x00000, 'testTag', 'IPCClient: unregisterDeathRecipient success'); + }catch (err) { + let code = (err as BusinessError).code; + let message = (err as BusinessError).message; + hilog.error(0x0000, 'testTag', 'IPCClient: unregister failed, code is ' + code + ', message is ' + message); + } + proxy = undefined; + }, + onFailed: (code: number) => { + hilog.info(0x0000, 'testTag', 'IPCClient: onFailed. code is ' + code); + }, + } + + try { + connectId = context.connectServiceExtensionAbility(want, connect); + }catch (err) { + let code = (err as BusinessError).code; + let message = (err as BusinessError).message; + hilog.error(0x0000, 'testTag', 'IPCClient: connectAbility failed, code is ' + code + ', message is ' + message); + } +} +// [End connect_ability] + +// 发送消息 +function sendString() { + hilog.info(0x00000, 'testTag', 'IPCClient: begin to send String'); + let option = new rpc.MessageOption(); + let data = rpc.MessageSequence.create(); + let reply = rpc.MessageSequence.create(); + // 在data里写入参数,以传递字符串为例 + data.writeString('hello world'); + if (proxy != undefined) { + proxy.sendMessageRequest(1, data, reply, option) + .then((result: rpc.RequestResult) => { + if (result.errCode != 0) { + hilog.error(0x0000, 'testTag', 'IPCClient: sendMessageRequest failed, errCode: ' + result.errCode); + return; + } + // 从result.reply里读取结果 + let str = result.reply.readString(); + hilog.info(0x0000, 'testTag', 'IPCClient: sendMessageRequest receive str is ' + str); + }) + .catch((e: Error) => { + hilog.error(0x0000, 'testTag', 'IPCClient: sendMessageRequest failed, error is ' + JSON.stringify(e)); + }) + .finally(() => { + data.reclaim(); + reply.reclaim(); + }) + } +} + +// 断开连接 +function disconnectAbility(context: common.UIAbilityContext) { + hilog.info(0x00000, 'testTag', 'IPCClient: begin to disconnect Ability'); + if (connectId != undefined) { + try { + context.disconnectServiceExtensionAbility(connectId); + }catch (err) { + let code = (err as BusinessError).code; + let message = (err as BusinessError).message; + hilog.error(0x0000, 'testTag', 'IPCClient: disconnect failed, code is ' + code + ', message is ' + message); + } + } +} +// [End funcation_implement] + + + + diff --git a/IPC/IPC_sendMessage/IPC_Client/entry/src/main/module.json5 b/IPC/IPC_sendMessage/IPC_Client/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..1b8734610280347ee7b402e384e52bb51fd3ca1e --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Client/entry/src/main/module.json5 @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "ohos.want.action.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ], + } + ] + } +} \ No newline at end of file diff --git a/IPC/IPC_sendMessage/IPC_Client/entry/src/main/resources/base/element/color.json b/IPC/IPC_sendMessage/IPC_Client/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Client/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/IPC/IPC_sendMessage/IPC_Client/entry/src/main/resources/base/element/float.json b/IPC/IPC_sendMessage/IPC_Client/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Client/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/IPC/IPC_sendMessage/IPC_Client/entry/src/main/resources/base/element/string.json b/IPC/IPC_sendMessage/IPC_Client/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Client/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/IPC/IPC_sendMessage/IPC_Client/entry/src/main/resources/base/media/background.png b/IPC/IPC_sendMessage/IPC_Client/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/IPC/IPC_sendMessage/IPC_Client/entry/src/main/resources/base/media/background.png differ diff --git a/IPC/IPC_sendMessage/IPC_Client/entry/src/main/resources/base/media/foreground.png b/IPC/IPC_sendMessage/IPC_Client/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/IPC/IPC_sendMessage/IPC_Client/entry/src/main/resources/base/media/foreground.png differ diff --git a/IPC/IPC_sendMessage/IPC_Client/entry/src/main/resources/base/media/layered_image.json b/IPC/IPC_sendMessage/IPC_Client/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Client/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/IPC/IPC_sendMessage/IPC_Client/entry/src/main/resources/base/media/startIcon.png b/IPC/IPC_sendMessage/IPC_Client/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/IPC/IPC_sendMessage/IPC_Client/entry/src/main/resources/base/media/startIcon.png differ diff --git a/IPC/IPC_sendMessage/IPC_Client/entry/src/main/resources/base/profile/backup_config.json b/IPC/IPC_sendMessage/IPC_Client/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Client/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/IPC/IPC_sendMessage/IPC_Client/entry/src/main/resources/base/profile/main_pages.json b/IPC/IPC_sendMessage/IPC_Client/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Client/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/IPC/IPC_sendMessage/IPC_Client/entry/src/main/resources/dark/element/color.json b/IPC/IPC_sendMessage/IPC_Client/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Client/entry/src/main/resources/dark/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] +} \ No newline at end of file diff --git a/IPC/IPC_sendMessage/IPC_Client/entry/src/mock/mock-config.json5 b/IPC/IPC_sendMessage/IPC_Client/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..cc676b366f202be456aae961ff5ee09b2f6713ca --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Client/entry/src/mock/mock-config.json5 @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2025 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. + */ + +{ +} \ No newline at end of file diff --git a/IPC/IPC_sendMessage/IPC_Client/entry/src/ohosTest/ets/test/Ability.test.ets b/IPC/IPC_sendMessage/IPC_Client/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..3c81579a25ae2430d5c8050c62a1fc14a7b0cf62 --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Client/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2025 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 '@kit.PerformanceAnalysisKit'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // 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(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // 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(() => { + // 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('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }) + }) +} \ No newline at end of file diff --git a/IPC/IPC_sendMessage/IPC_Client/entry/src/ohosTest/ets/test/List.test.ets b/IPC/IPC_sendMessage/IPC_Client/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..cefb5e406030b28a58d7835468d0fe131e352cc0 --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Client/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 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/IPC/IPC_sendMessage/IPC_Client/entry/src/ohosTest/module.json5 b/IPC/IPC_sendMessage/IPC_Client/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..afa53deb78d0559dda429a32d662b9c27397aebe --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Client/entry/src/ohosTest/module.json5 @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/IPC/IPC_sendMessage/IPC_Client/entry/src/test/List.test.ets b/IPC/IPC_sendMessage/IPC_Client/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..74ba3a099410b447742c4a6ecac5c511bb63e5e7 --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Client/entry/src/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 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 localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/IPC/IPC_sendMessage/IPC_Client/entry/src/test/LocalUnit.test.ets b/IPC/IPC_sendMessage/IPC_Client/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..b367c75db8ae9ad0864a7c14f9bf2ce8c2b5e021 --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Client/entry/src/test/LocalUnit.test.ets @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // 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(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // 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(() => { + // 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('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/IPC/IPC_sendMessage/IPC_Client/hvigor/hvigor-config.json5 b/IPC/IPC_sendMessage/IPC_Client/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f157d908f1551938f1c699f7b7468f44088ab7db --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Client/hvigor/hvigor-config.json5 @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "modelVersion": "6.0.0", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | "ultrafine" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + // "optimizationStrategy": "memory" /* Define the optimization strategy. Value: [ "memory" | "performance" ]. Default: "memory" */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/IPC/IPC_sendMessage/IPC_Client/hvigorfile.ts b/IPC/IPC_sendMessage/IPC_Client/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..de06c780c9687a49f0161e161816f18af7354ff0 --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Client/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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 { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins: [] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file diff --git a/IPC/IPC_sendMessage/IPC_Client/image/IPC_Client.png b/IPC/IPC_sendMessage/IPC_Client/image/IPC_Client.png new file mode 100644 index 0000000000000000000000000000000000000000..f980e40c596d3ed9938c57dd953ed9ea74ed23f8 Binary files /dev/null and b/IPC/IPC_sendMessage/IPC_Client/image/IPC_Client.png differ diff --git a/IPC/IPC_sendMessage/IPC_Client/image/IPC_Stub.png b/IPC/IPC_sendMessage/IPC_Client/image/IPC_Stub.png new file mode 100644 index 0000000000000000000000000000000000000000..41a612d7fa318c8174f78b4422a516693abaf571 Binary files /dev/null and b/IPC/IPC_sendMessage/IPC_Client/image/IPC_Stub.png differ diff --git a/IPC/IPC_sendMessage/IPC_Client/image/app_signature.png b/IPC/IPC_sendMessage/IPC_Client/image/app_signature.png new file mode 100644 index 0000000000000000000000000000000000000000..7356412b59341dae630666f9619df800288cbf44 Binary files /dev/null and b/IPC/IPC_sendMessage/IPC_Client/image/app_signature.png differ diff --git a/IPC/IPC_sendMessage/IPC_Client/image/comment.png b/IPC/IPC_sendMessage/IPC_Client/image/comment.png new file mode 100644 index 0000000000000000000000000000000000000000..eb663adfedd7cdde03418946be92b67addf57cb5 Binary files /dev/null and b/IPC/IPC_sendMessage/IPC_Client/image/comment.png differ diff --git a/IPC/IPC_sendMessage/IPC_Client/image/configure.png b/IPC/IPC_sendMessage/IPC_Client/image/configure.png new file mode 100644 index 0000000000000000000000000000000000000000..75d7e5ae7aa3c625d47ca0c0a56f4a26d52b058d Binary files /dev/null and b/IPC/IPC_sendMessage/IPC_Client/image/configure.png differ diff --git a/IPC/IPC_sendMessage/IPC_Client/image/recv_install_list_capability.png b/IPC/IPC_sendMessage/IPC_Client/image/recv_install_list_capability.png new file mode 100644 index 0000000000000000000000000000000000000000..8fae5e9b11da33f1be60f055425aa6985833ed2b Binary files /dev/null and b/IPC/IPC_sendMessage/IPC_Client/image/recv_install_list_capability.png differ diff --git a/IPC/IPC_sendMessage/IPC_Client/image/result.png b/IPC/IPC_sendMessage/IPC_Client/image/result.png new file mode 100644 index 0000000000000000000000000000000000000000..f67e1ad296262d3f8678367804a34a5700fb2be0 Binary files /dev/null and b/IPC/IPC_sendMessage/IPC_Client/image/result.png differ diff --git a/IPC/IPC_sendMessage/IPC_Client/oh-package.json5 b/IPC/IPC_sendMessage/IPC_Client/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..19e26ca33e54ca6961482424ce0dfffc20c37f42 --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Client/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "modelVersion": "6.0.0", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.24", + "@ohos/hamock": "1.0.0" + } +} diff --git a/IPC/IPC_sendMessage/IPC_Client/ohosTest.md b/IPC/IPC_sendMessage/IPC_Client/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..44c821789b9ea21505af9bf43b208b8dc292a97e --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Client/ohosTest.md @@ -0,0 +1,12 @@ +# IPC_Client 测试用例归档 + +## 用例表 + +|测试功能|预置条件| 输入 |预期输出|测试结果| +|----------|-----------|----------|----------------|----------------| +|拉起应用|安装sample| 无 |成功拉起应用|Pass| +|检测首页UI|进入首页| 无 |首页UI显示正常|Pass| +|连接服务| connecAbility 按钮显示正常| 点击 connecAbility 按钮 |因服务端在后台运行,连接服务成功,日志中打印“IPCClient: onConnect. elementName is xxxx”符合预期|Pass| +|发送字符串信息| sendRequest_String 按钮显示正常| 点击 sendRequest_String 按钮 |成功发送消息,并接收服务端返回的字符串,志中打印“IPCClient: sendMessageRequest receive str is hello rpc”符合预期|Pass| +|断开连接| disconnecAbility 按钮显示正常| 点击 disconnecAbility 按钮 |成功断开服务,日志中打印“IPCClient: onDisconnect. elementName is”符合预期|Pass| +|死亡回调| 服务端应用手动kill或进行退出后台| 手动清理服务端所在后台应用 |服务端死亡,日志中打印“IPCClient: server is died”符合预期|Pass| diff --git a/IPC/IPC_sendMessage/IPC_Stub/AppScope/app.json5 b/IPC/IPC_sendMessage/IPC_Stub/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..81852ce69f9775b87c9a8682c86a73beedecd87b --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Stub/AppScope/app.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "app": { + "bundleName": "com.example.ipc_stub", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/IPC/IPC_sendMessage/IPC_Stub/AppScope/resources/base/element/string.json b/IPC/IPC_sendMessage/IPC_Stub/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..2c9fea669aa8e9d4f4ca9cb77c4d9362fc020015 --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Stub/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "IPC_Stub" + } + ] +} diff --git a/IPC/IPC_sendMessage/IPC_Stub/AppScope/resources/base/media/background.png b/IPC/IPC_sendMessage/IPC_Stub/AppScope/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/IPC/IPC_sendMessage/IPC_Stub/AppScope/resources/base/media/background.png differ diff --git a/IPC/IPC_sendMessage/IPC_Stub/AppScope/resources/base/media/foreground.png b/IPC/IPC_sendMessage/IPC_Stub/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..eb9427585b36d14b12477435b6419d1f07b3e0bb Binary files /dev/null and b/IPC/IPC_sendMessage/IPC_Stub/AppScope/resources/base/media/foreground.png differ diff --git a/IPC/IPC_sendMessage/IPC_Stub/AppScope/resources/base/media/layered_image.json b/IPC/IPC_sendMessage/IPC_Stub/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Stub/AppScope/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/IPC/IPC_sendMessage/IPC_Stub/build-profile.json5 b/IPC/IPC_sendMessage/IPC_Stub/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9a4d633ae54300e05aaa732e47eb35cd4e480462 --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Stub/build-profile.json5 @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "app": { + "signingConfigs": [ + { + "name": "default", + "type": "HarmonyOS", + "material": { + "certpath": "C:\\Users\\Administrator\\.ohos\\config\\default_IPC_Stub_Q6xfe8dj_Z11iMCwAzLQYFsl1rrcn2oGaArHg7mrAgk=.cer", + "keyAlias": "debugKey", + "keyPassword": "0000001BCF513BD9F4DA3905C1065CA258FA90BCB3F8EA59B2F914343177742C1EE97F933A0C733BF31860", + "profile": "C:\\Users\\Administrator\\.ohos\\config\\default_IPC_Stub_Q6xfe8dj_Z11iMCwAzLQYFsl1rrcn2oGaArHg7mrAgk=.p7b", + "signAlg": "SHA256withECDSA", + "storeFile": "C:\\Users\\Administrator\\.ohos\\config\\default_IPC_Stub_Q6xfe8dj_Z11iMCwAzLQYFsl1rrcn2oGaArHg7mrAgk=.p12", + "storePassword": "0000001B1A21E4F22A80A63394646AA0B4E7B8EE51B1DE1AD59522D02AAC28AD58837472A14621F9B2B511" + } + } + ], + "products": [ + { + "name": "default", + "signingConfig": "default", + "targetSdkVersion": "6.0.0(20)", + "compatibleSdkVersion": "6.0.0(20)", + "runtimeOS": "HarmonyOS", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/IPC/IPC_sendMessage/IPC_Stub/entry/.gitignore b/IPC/IPC_sendMessage/IPC_Stub/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Stub/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/IPC/IPC_sendMessage/IPC_Stub/entry/build-profile.json5 b/IPC/IPC_sendMessage/IPC_Stub/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7961c5611ea6da0aba83dbb6b484f28ac3788a7 --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Stub/entry/build-profile.json5 @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "resOptions": { + "copyCodeResource": { + "enable": false + } + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/IPC/IPC_sendMessage/IPC_Stub/entry/hvigorfile.ts b/IPC/IPC_sendMessage/IPC_Stub/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..10f881f112b08550ed5c8a3ceb7d0148be2a0b6e --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Stub/entry/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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 { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins: [] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file diff --git a/IPC/IPC_sendMessage/IPC_Stub/entry/obfuscation-rules.txt b/IPC/IPC_sendMessage/IPC_Stub/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Stub/entry/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/IPC/IPC_sendMessage/IPC_Stub/entry/oh-package.json5 b/IPC/IPC_sendMessage/IPC_Stub/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..114cb176e4a4d08801ddb6ddf39ef3d0df76dc2f --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Stub/entry/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/IPC/IPC_sendMessage/IPC_Stub/entry/src/main/ets/ServiceExtAbility/ServiceExtAbility.ets b/IPC/IPC_sendMessage/IPC_Stub/entry/src/main/ets/ServiceExtAbility/ServiceExtAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..21d1908512f245168fc238d48f846a717c04d810 --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Stub/entry/src/main/ets/ServiceExtAbility/ServiceExtAbility.ets @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start service_impl] +import { ServiceExtensionAbility, Want } from '@kit.AbilityKit'; +import { rpc } from '@kit.IPCKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +// 定义服务端 +class Stub extends rpc.RemoteObject { + constructor(descriptor: string) { + super(descriptor); + } + onRemoteMessageRequest(code: number, data: rpc.MessageSequence, reply: rpc.MessageSequence, + option: rpc.MessageOption): boolean | Promise { + // 服务端Stub根据不同的请求code分别执行对应的处理流程 + if (code == 1) { + let str = data.readString(); + hilog.info(0x0000, 'testTag', 'IPCStub: stub receive str : ' + str); + // 服务端使用reply回传请求处理的结果给客户端 + reply.writeString('hello rpc'); + return true; + } else { + hilog.info(0x0000, 'testTag', 'IPCStub: stub unknown code: ' + code); + return false; + } + } +} + +// 定义后台服务 +export default class ServiceAbility extends ServiceExtensionAbility { + onCreate(want: Want): void { + hilog.info(0x0000, 'testTag', 'IPCStub: onCreate'); + } + + onRequest(want: Want, startId: number): void { + hilog.info(0x0000, 'testTag', 'IPCStub: onRequest'); + } + + onConnect(want: Want): rpc.RemoteObject { + hilog.info(0x0000, 'testTag', 'IPCStub: onConnect'); + // 返回Stub对象,客户端获取后便可以与ServiceExtensionAbility进行通信 + return new Stub('IPCStubTest'); + } + + onDisconnect(want: Want): void { + hilog.info(0x0000, 'testTag', 'IPCStub: onDisconnect'); + } + + onDestroy(): void { + hilog.info(0x0000, 'testTag', 'IPCStub: onDestroy'); + } +} +// [End service_impl] \ No newline at end of file diff --git a/IPC/IPC_sendMessage/IPC_Stub/entry/src/main/ets/entryability/EntryAbility.ets b/IPC/IPC_sendMessage/IPC_Stub/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..5592b0500ad9887e46faa0d87b1302003aeb200b --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Stub/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2025 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 { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +const DOMAIN = 0x0000; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + try { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + } catch (err) { + hilog.error(DOMAIN, 'testTag', 'Failed to set colorMode. Cause: %{public}s', JSON.stringify(err)); + } + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/IPC/IPC_sendMessage/IPC_Stub/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/IPC/IPC_sendMessage/IPC_Stub/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b37e4b57cd7849ab462574297ff70345c2132ab2 --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Stub/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025 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 '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +const DOMAIN = 0x0000; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(DOMAIN, 'testTag', 'onBackup ok'); + await Promise.resolve(); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(DOMAIN, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + await Promise.resolve(); + } +} \ No newline at end of file diff --git a/IPC/IPC_sendMessage/IPC_Stub/entry/src/main/ets/pages/Index.ets b/IPC/IPC_sendMessage/IPC_Stub/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..86a26e62780c740a4e2912e0eea7df06cc3d150f --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Stub/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + RelativeContainer() { + Text(this.message) + .id('HelloWorld') + .fontSize($r('app.float.page_text_font_size')) + .fontWeight(FontWeight.Bold) + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + .onClick(() => { + this.message = 'Welcome'; + }) + } + .height('100%') + .width('100%') + + } +} \ No newline at end of file diff --git a/IPC/IPC_sendMessage/IPC_Stub/entry/src/main/module.json5 b/IPC/IPC_sendMessage/IPC_Stub/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..465fdd063692ea22760f8e190ccd25bbf0a30e49 --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Stub/entry/src/main/module.json5 @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "ohos.want.action.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ] + }, + { + "name": "ServiceAbility", + "srcEntry": "./ets/ServiceExtAbility/ServiceExtAbility.ets", + "type": "service", + "exported": true, // 可被其他三方应用拉起,若设为false,需在客户端配置ohos.permission.START_INVISIBLE_ABILITY + "description": "service" + } + ] + } +} \ No newline at end of file diff --git a/IPC/IPC_sendMessage/IPC_Stub/entry/src/main/resources/base/element/color.json b/IPC/IPC_sendMessage/IPC_Stub/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Stub/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/IPC/IPC_sendMessage/IPC_Stub/entry/src/main/resources/base/element/float.json b/IPC/IPC_sendMessage/IPC_Stub/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Stub/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/IPC/IPC_sendMessage/IPC_Stub/entry/src/main/resources/base/element/string.json b/IPC/IPC_sendMessage/IPC_Stub/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Stub/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/IPC/IPC_sendMessage/IPC_Stub/entry/src/main/resources/base/media/background.png b/IPC/IPC_sendMessage/IPC_Stub/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/IPC/IPC_sendMessage/IPC_Stub/entry/src/main/resources/base/media/background.png differ diff --git a/IPC/IPC_sendMessage/IPC_Stub/entry/src/main/resources/base/media/foreground.png b/IPC/IPC_sendMessage/IPC_Stub/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/IPC/IPC_sendMessage/IPC_Stub/entry/src/main/resources/base/media/foreground.png differ diff --git a/IPC/IPC_sendMessage/IPC_Stub/entry/src/main/resources/base/media/layered_image.json b/IPC/IPC_sendMessage/IPC_Stub/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Stub/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/IPC/IPC_sendMessage/IPC_Stub/entry/src/main/resources/base/media/startIcon.png b/IPC/IPC_sendMessage/IPC_Stub/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/IPC/IPC_sendMessage/IPC_Stub/entry/src/main/resources/base/media/startIcon.png differ diff --git a/IPC/IPC_sendMessage/IPC_Stub/entry/src/main/resources/base/profile/backup_config.json b/IPC/IPC_sendMessage/IPC_Stub/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Stub/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/IPC/IPC_sendMessage/IPC_Stub/entry/src/main/resources/base/profile/main_pages.json b/IPC/IPC_sendMessage/IPC_Stub/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Stub/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/IPC/IPC_sendMessage/IPC_Stub/entry/src/main/resources/dark/element/color.json b/IPC/IPC_sendMessage/IPC_Stub/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Stub/entry/src/main/resources/dark/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] +} \ No newline at end of file diff --git a/IPC/IPC_sendMessage/IPC_Stub/entry/src/mock/mock-config.json5 b/IPC/IPC_sendMessage/IPC_Stub/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..cc676b366f202be456aae961ff5ee09b2f6713ca --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Stub/entry/src/mock/mock-config.json5 @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2025 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. + */ + +{ +} \ No newline at end of file diff --git a/IPC/IPC_sendMessage/IPC_Stub/entry/src/ohosTest/ets/test/Ability.test.ets b/IPC/IPC_sendMessage/IPC_Stub/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..3c81579a25ae2430d5c8050c62a1fc14a7b0cf62 --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Stub/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2025 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 '@kit.PerformanceAnalysisKit'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // 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(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // 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(() => { + // 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('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }) + }) +} \ No newline at end of file diff --git a/IPC/IPC_sendMessage/IPC_Stub/entry/src/ohosTest/ets/test/List.test.ets b/IPC/IPC_sendMessage/IPC_Stub/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..cefb5e406030b28a58d7835468d0fe131e352cc0 --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Stub/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 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/IPC/IPC_sendMessage/IPC_Stub/entry/src/ohosTest/module.json5 b/IPC/IPC_sendMessage/IPC_Stub/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..afa53deb78d0559dda429a32d662b9c27397aebe --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Stub/entry/src/ohosTest/module.json5 @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/IPC/IPC_sendMessage/IPC_Stub/entry/src/test/List.test.ets b/IPC/IPC_sendMessage/IPC_Stub/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..74ba3a099410b447742c4a6ecac5c511bb63e5e7 --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Stub/entry/src/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 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 localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/IPC/IPC_sendMessage/IPC_Stub/entry/src/test/LocalUnit.test.ets b/IPC/IPC_sendMessage/IPC_Stub/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..b367c75db8ae9ad0864a7c14f9bf2ce8c2b5e021 --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Stub/entry/src/test/LocalUnit.test.ets @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // 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(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // 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(() => { + // 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('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/IPC/IPC_sendMessage/IPC_Stub/hvigor/hvigor-config.json5 b/IPC/IPC_sendMessage/IPC_Stub/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7a7ab8914d8db6ab89758e185df5855dffe88d04 --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Stub/hvigor/hvigor-config.json5 @@ -0,0 +1,23 @@ +{ + "modelVersion": "6.0.0", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | "ultrafine" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + // "optimizationStrategy": "memory" /* Define the optimization strategy. Value: [ "memory" | "performance" ]. Default: "memory" */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/IPC/IPC_sendMessage/IPC_Stub/hvigorfile.ts b/IPC/IPC_sendMessage/IPC_Stub/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..de06c780c9687a49f0161e161816f18af7354ff0 --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Stub/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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 { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins: [] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file diff --git a/IPC/IPC_sendMessage/IPC_Stub/oh-package.json5 b/IPC/IPC_sendMessage/IPC_Stub/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..19e26ca33e54ca6961482424ce0dfffc20c37f42 --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Stub/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "modelVersion": "6.0.0", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.24", + "@ohos/hamock": "1.0.0" + } +} diff --git a/IPC/IPC_sendMessage/IPC_Stub/ohosTest.md b/IPC/IPC_sendMessage/IPC_Stub/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..569dc447a591addfb4e10e40d5c71a4e7d0e38de --- /dev/null +++ b/IPC/IPC_sendMessage/IPC_Stub/ohosTest.md @@ -0,0 +1,9 @@ +# IPC_Stub 测试用例归档 + +## 用例表 + +|测试功能|预置条件| 输入 |预期输出|测试结果| +|----------|-----------|----------|----------------|----------------| +|拉起应用|安装sample| 无 |成功拉起应用|Pass| +|检测首页UI|进入首页| 无 |首页UI显示正常|Pass| +|收到服务端信息| 客户端成功连接服务,并发送请求| 无 |日志中打印“IPCStub: stub receive str : hello world”符合预期|Pass| diff --git a/IPC/RPC_sendMessage/RPC_Client/AppScope/app.json5 b/IPC/RPC_sendMessage/RPC_Client/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7da7b69ede62cce27d47fcd0952380b5523fd12c --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Client/AppScope/app.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "app": { + "bundleName": "com.example.rpc_client", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/IPC/RPC_sendMessage/RPC_Client/AppScope/resources/base/element/string.json b/IPC/RPC_sendMessage/RPC_Client/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..8f71b479833e24010178c42d9ea90e435e264da9 --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Client/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "RPC_Client" + } + ] +} diff --git a/IPC/RPC_sendMessage/RPC_Client/AppScope/resources/base/media/background.png b/IPC/RPC_sendMessage/RPC_Client/AppScope/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/IPC/RPC_sendMessage/RPC_Client/AppScope/resources/base/media/background.png differ diff --git a/IPC/RPC_sendMessage/RPC_Client/AppScope/resources/base/media/foreground.png b/IPC/RPC_sendMessage/RPC_Client/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..eb9427585b36d14b12477435b6419d1f07b3e0bb Binary files /dev/null and b/IPC/RPC_sendMessage/RPC_Client/AppScope/resources/base/media/foreground.png differ diff --git a/IPC/RPC_sendMessage/RPC_Client/AppScope/resources/base/media/layered_image.json b/IPC/RPC_sendMessage/RPC_Client/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Client/AppScope/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/IPC/RPC_sendMessage/RPC_Client/README.md b/IPC/RPC_sendMessage/RPC_Client/README.md new file mode 100644 index 0000000000000000000000000000000000000000..53ada361b4c76a08a348dd6a47bb79eb2f3e276c --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Client/README.md @@ -0,0 +1,352 @@ +# IPC通信示例 + +## 介绍 + +本示例展示了如何使用[@ohos.rpc](https://gitcode.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ipc-kit/js-apis-rpc.md) 相关接口,开发一个IPC客户端与服务端通信的完整示例。在此示例中仅演示如何传递字符串信息,若有传递除此之外接口的诉求,请自行参考接口文档中的示例代码。 + +## 效果预览 + +|客户端|服务端| +|-----------------|----------------------| +|![](image/RPC_Client.png)|![](image/RPC_Stub.png)| +|![](image/getPermission.png)| | + + +使用说明: + +1. 点击 getPermission 按钮进行获取允许多设备协同的权限; +2. 点击 getDeviceId 按钮获取对端的设备信息; +3. 点击 connectAbility 按钮进行连接服务端,获取到服务端的代理对象proxy,并在此时注册死亡监听,当服务端所在进程死亡时,会触发此监听,提示服务端已死亡,并断开连接服务端; +2. 点击 sendRequest_string 按钮传递字符串信息至服务端,服务端会收到这次传递的字符串('hello world'),并返回字符串('hello rpc')到客户端,代表此次通信结束; +3. 点击 disconnectAbility 按钮断开连接服务端。 + +以上操作建立在双方设备组网的情况下进行。 + +## 工程目录 + +1. 客户端-IPC_Client + +``` +entry/src/main/ets/ +|---entryability +| |---EntryAbility.ets +|---entrybackupability +| |---EntryBackupAbility.ets +|---pages +| |---Index.ets // 页面布局、客户端实现 +``` + +2. 服务端-IPC_Service + +``` +entry/src/main/ets/ +|---entryability +| |---EntryAbility.ets +|---entrybackupability +| |---EntryBackupAbility.ets +|---pages +| |---Index.ets +|---ServiceExtAbility +| |---ServiceExtAbility.ets // 服务端实现 +``` + +以上工程目录中未进行说明的部分,是默认工程目录结构,并未进行修改。 + +## 具体实现 + +1. 创建ServiceExtensionAbility,实现服务端 + + ```ets + // 定义服务端 + class Stub extends rpc.RemoteObject { + constructor(descriptor: string) { + super(descriptor); + } + onRemoteMessageRequest(code: number, data: rpc.MessageSequence, reply: rpc.MessageSequence, option: rpc.MessageOption): boolean | Promise { + // 服务端Stub根据不同的请求code分别执行对应的处理流程 + if (code == 1) { + let str = data.readString(); + hilog.info(0x0000, 'testTag', 'RPC_Stub: stub receive str is ' + str); + // 服务端使用reply回传请求处理的结果给客户端 + reply.writeString('hello rpc'); + return true; + } else { + hilog.info(0x0000, 'testTag', 'RPC_Stub: stub unknown code, code is ' + code); + return false; + } + } + } + + // 定义后台服务 + export default class ServiceAbility extends ServiceExtensionAbility { + ...... + + onConnect(want: Want): rpc.RemoteObject { + hilog.info(0x0000, 'testTag', 'RPC_Stub: onConnect'); + // 返回Stub对象,客户端获取后便可以与ServiceExtensionAbility进行通信 + return new Stub('RPCStubTest'); + } + + ...... + } + ``` + +2. 获取允许多设备协同的权限(客户端服务端需要进行此操作) + + ```ets + function getPermission(context:common.UIAbilityContext) { + hilog.info(0x00000, 'testTag', 'RpcClient: begin to requestPermissions'); + try { + let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager(); + atManager.requestPermissionsFromUser(context, ['ohos.permission.DISTRIBUTED_DATASYNC'], (err: BusinessError, data: PermissionRequestResult) => { + if (err) { + hilog.error(0x0000, 'testTag', 'RpcClient: registerDeathRecipient failed, code is ' + err.code + ', message is ' + err.message); + } else { + hilog.info(0x0000, 'testTag','RpcClient: requestPermissionsFromUser success, result is ' + JSON.stringify(data)); + hilog.info(0x0000, 'testTag','RpcClient: requestPermissionsFromUser data permissions is ' + data.permissions); + hilog.info(0x0000, 'testTag','RpcClient: requestPermissionsFromUser data authResults is ' + data.authResults); + hilog.info(0x0000, 'testTag','RpcClient: requestPermissionsFromUser data dialogShownResults is ' + data.dialogShownResults); + } + }); + }catch (err) { + let code = (err as BusinessError).code; + let message = (err as BusinessError).message; + hilog.error(0x0000, 'testTag', 'RpcClient: getPermission failed, code is ' + code + ', message is ' + message); + } + } + ``` + +3. 客户端获取对端设备信息 + + ```ets + function getDeviceId(){ + hilog.info(0x00000, 'testTag', 'RpcClient: begin to getDeviceId'); + try { + dmInstance = distributedDeviceManager.createDeviceManager('com.example.rpc_client'); + hilog.info(0x0000, 'testTag', 'RpcClient: createDeviceManager success'); + deviceList = dmInstance.getAvailableDeviceListSync(); + hilog.info(0x0000, 'testTag', 'RpcClient: deviceList is' + JSON.stringify(deviceList)); + if (deviceList.length !== 0) { + deviceId = deviceList[0].networkId; + hilog.info(0x0000, 'testTag', 'RpcClient: networkId is ' + deviceId); + } + }catch (err) { + let code = (err as BusinessError).code; + let message = (err as BusinessError).message; + hilog.error(0x0000, 'testTag', 'RpcClient: getDeviceId failed, code is ' + code + ', message is ' + message); + } + } + ``` + +4. 客户端连接服务 + + ```ets + function connectAbility(context:common.UIAbilityContext) { + hilog.info(0x00000, 'testTag', 'RpcClient: begin to connect Ability'); + let want: Want = { + bundleName: 'com.example.rpc_stub', + abilityName: 'ServiceAbility', + deviceId: deviceId, + } + + let connect: common.ConnectOptions = { + onConnect: (elementName, remoteProxy) => { + hilog.info(0x00000, 'testTag', 'RpcClient: onConnect. elementName is :' + JSON.stringify(elementName)); + proxy = remoteProxy; + // 客户端注册死亡监听 + try { + proxy.registerDeathRecipient(deathRecipient, 0); + hilog.info(0x00000, 'testTag', 'RpcClient: registerDeathRecipient success'); + }catch (err) { + let code = (err as BusinessError).code; + let message = (err as BusinessError).message; + hilog.error(0x0000, 'testTag', 'RpcClient: registerDeathRecipient failed, code is ' + code + ', message is ' + message); + } + }, + onDisconnect: (elementName) => { + hilog.info(0x0000, 'testTag', 'RpcClient: onDisconnect. elementName is ' + JSON.stringify(elementName)); + // 客户端移除死亡监听 + try { + proxy?.unregisterDeathRecipient(deathRecipient, 0); + hilog.info(0x00000, 'testTag', 'RpcClient: unregisterDeathRecipient success'); + }catch (err) { + let code = (err as BusinessError).code; + let message = (err as BusinessError).message; + hilog.error(0x0000, 'testTag', 'RpcClient: unregisterDeathRecipient failed, code is ' + code + ', message is ' + message); + } + proxy = undefined; + }, + onFailed: (code: number) => { + hilog.info(0x0000, 'testTag', 'RpcClient: onFailed. code is :' + code); + }, + } + + try { + connectId = context.connectServiceExtensionAbility(want, connect); + }catch (err) { + let code = (err as BusinessError).code; + let message = (err as BusinessError).message; + hilog.error(0x0000, 'testTag', 'RpcClient: connectService failed, code is ' + code + ', message is ' + message); + } + } + ``` + +5. 客户端发送字符串给服务端 + + ```ets + function sendString() { + hilog.info(0x00000, 'testTag', 'RpcClient: begin to send string'); + let option = new rpc.MessageOption(); + let data = rpc.MessageSequence.create(); + let reply = rpc.MessageSequence.create(); + // 在data里写入参数,以传递字符串为例 + data.writeString('hello world'); + + if (proxy != undefined) { + proxy.sendMessageRequest(1, data, reply, option) + .then((result: rpc.RequestResult) => { + if (result.errCode != 0) { + hilog.error(0x0000, 'testTag', 'RpcClient: sendMessageRequest failed, errCode: ' + result.errCode); + return; + } + // 从result.reply里读取结果 + let str = result.reply.readString(); + hilog.info(0x0000, 'testTag', 'RpcClient: sendMessageRequest receiver, str: ' + str); + }) + .catch((e: Error) => { + hilog.error(0x0000, 'testTag', `RpcClient: sendMessageRequest failed, error is ` + JSON.stringify(e)); + }) + .finally(() => { + data.reclaim(); + reply.reclaim(); + }) + } + } + ``` + +6. 客户端断开连接服务 + + ```ets + function disconnectAbility(context: common.UIAbilityContext) { + hilog.info(0x00000, 'testTag', 'RpcClient: begin to disconnect Ability'); + if (connectId != undefined) { + try { + context.disconnectServiceExtensionAbility(connectId); + }catch (err) { + let code = (err as BusinessError).code; + let message = (err as BusinessError).message; + hilog.error(0x0000, 'testTag', 'pcClient: disconnectService failed, code is ' + code + ', message is ' + message); + } + } + } + ``` + +## 相关权限 + +ohos.permission.GET_BUNDLE_INFO + +ohos.permission.DISTRIBUTED_DATASYNC + +## 依赖 + +本示例中按键之间存在依赖关系,具体依赖如下: + +1. 客户端和服务端需先进行获取权限的操作('getPermission'); +2. 客户端获取权限后需先进行获取设备ID的操作('getDeviceId'); +3. 在获取对应设备ID后,客户端才可以进行连接服务的操作('connectAbility'); +2. 在连接服务成功的情况下,客户端才可进行发送信息的操作('sendRequest_string'); +3. 在双方建立连接的情况下,客户端才可进行断连的操作('disconnectAbility')。 + +## 约束与限制 + +1. 本示例仅支持标准系统上运行,支持设备:RK3568。 + +2. 本示例推荐使用DevEco Studio 5.0.2 Beta1 (Build Version: 5.0.7.100 构建 2025年1月16日)及以上版本编译运行。 + +3. 本示例需要使用@ohos.app.ability.ServiceExtensionAbility,该模块仅对系统应用开放,业务使用时,需自行替换当前工程中的SDK为FULL SDK。使用Full SDK时需要手动从镜像站点获取,并在DevEcoStudio中替换,具体操作可参考[替换指南](https://gitcode.com/openharmony/docs/blob/master/zh-cn/application-dev/faqs/full-sdk-switch-guide.md) 。 + +4. 本示例使用了ServiceExtensionAbility,需要在module.json5中进行相应的配置。如下: + +在服务端entry下的module.json5中配置如下字段:[module.json5](../IPC_Stub/entry/src/main/module.json5),参考第48-54行。 + + ``` + "extensionAbilities": [ + { + "name": "ServiceAbility", + "srcEntry": "./ets/serviceextability/ServiceExtAbility.ets", + "type": "service", + "exported": true, + "description": "service" + } + ] + ``` + +## 下载 + +如需单独下载本工程及服务端,执行如下命令: + + ``` + git init + git config core.sparsecheckout true + echo IPC/RPC_sendMessage/ > .git/info/sparse-checkout + git remote add origin https://gitcode.com/harmonyos_samples/guide-snippets.git + git pull origin master + ``` + +## 安装问题(9568344) + +因上述应用的module.json5中extensionAbilities字段中type属性为service,普通的安装方法会报错,需要按照以下方式进行安装: + +1. 注释module.json5中extensionAbilities字段 + +![](image/comment.png) + +2. 获取app_signature + + ``` + hdc shell bm dump -n | findstr finger + ``` + +![](image/app_signature.png) + +3. 添加白名单 + +将rk设备的install_list_capability.json配置文件拉取到本地 + + ``` + hdc shell mount -o rw,remount / + hdc file recv /system/etc/app/install_list_capability.json ---rk的方式 + ``` + +![](image/recv_install_list_capability.png) + +在拉下来的json文件中添加不能安装成功的应用,格式如下: + + ``` + { + "install_list": [ + { + ...... + }, + { + "bundleName": "应用包名", + "app_signature" : ["上面获取的app_signature"], + "allowAppUsePrivilegeExtension": true + } + ] + } + ``` + +![](image/configure.png) + +4. 将修改后的白名单推送到设备上进行替换并重启 + + ``` + hdc shell mount -o rw,remount / + hdc file send install_list_capability.json /system/etc/app/install_list_capability.json + hdc shell chmod 777 /system/etc/app/install_list_capability.json + hdc shell reboot + ``` + +5. 取消module.json5中extensionAbilities的相关注释,重新安装hap包 + \ No newline at end of file diff --git a/IPC/RPC_sendMessage/RPC_Client/build-profile.json5 b/IPC/RPC_sendMessage/RPC_Client/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3a9308d6887003dce617a8011c0c3bd2f1c25bf3 --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Client/build-profile.json5 @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "app": { + "signingConfigs": [ + ], + "products": [ + { + "name": "default", + "signingConfig": "default", + "targetSdkVersion": "6.0.0(20)", + "compatibleSdkVersion": "6.0.0(20)", + "runtimeOS": "HarmonyOS", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/IPC/RPC_sendMessage/RPC_Client/entry/.gitignore b/IPC/RPC_sendMessage/RPC_Client/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Client/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/IPC/RPC_sendMessage/RPC_Client/entry/build-profile.json5 b/IPC/RPC_sendMessage/RPC_Client/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7961c5611ea6da0aba83dbb6b484f28ac3788a7 --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Client/entry/build-profile.json5 @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "resOptions": { + "copyCodeResource": { + "enable": false + } + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/IPC/RPC_sendMessage/RPC_Client/entry/hvigorfile.ts b/IPC/RPC_sendMessage/RPC_Client/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..10f881f112b08550ed5c8a3ceb7d0148be2a0b6e --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Client/entry/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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 { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins: [] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file diff --git a/IPC/RPC_sendMessage/RPC_Client/entry/obfuscation-rules.txt b/IPC/RPC_sendMessage/RPC_Client/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Client/entry/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/IPC/RPC_sendMessage/RPC_Client/entry/oh-package.json5 b/IPC/RPC_sendMessage/RPC_Client/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..114cb176e4a4d08801ddb6ddf39ef3d0df76dc2f --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Client/entry/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/IPC/RPC_sendMessage/RPC_Client/entry/src/main/ets/entryability/EntryAbility.ets b/IPC/RPC_sendMessage/RPC_Client/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..5592b0500ad9887e46faa0d87b1302003aeb200b --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Client/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2025 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 { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +const DOMAIN = 0x0000; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + try { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + } catch (err) { + hilog.error(DOMAIN, 'testTag', 'Failed to set colorMode. Cause: %{public}s', JSON.stringify(err)); + } + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/IPC/RPC_sendMessage/RPC_Client/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/IPC/RPC_sendMessage/RPC_Client/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b37e4b57cd7849ab462574297ff70345c2132ab2 --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Client/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025 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 '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +const DOMAIN = 0x0000; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(DOMAIN, 'testTag', 'onBackup ok'); + await Promise.resolve(); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(DOMAIN, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + await Promise.resolve(); + } +} \ No newline at end of file diff --git a/IPC/RPC_sendMessage/RPC_Client/entry/src/main/ets/pages/Index.ets b/IPC/RPC_sendMessage/RPC_Client/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..7ebed986e235117bd7f100e943debcd4a1df190d --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Client/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,236 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start rpc_front-end_dependencies] +import { BusinessError } from '@kit.BasicServicesKit'; +import rpc from '@ohos.rpc'; +import hilog from '@ohos.hilog'; +import { distributedDeviceManager } from '@kit.DistributedServiceKit'; +import { abilityAccessCtrl, PermissionRequestResult, common, Want} from '@kit.AbilityKit'; +import { JSON } from '@kit.ArkTS'; + +let proxy: rpc.IRemoteObject | undefined +let connectId: number | undefined +let dmInstance: distributedDeviceManager.DeviceManager +let deviceList: Array | undefined; +let deviceId: string| undefined; + +// 死亡通知 +class MyDeathRecipient implements rpc.DeathRecipient{ + onRemoteDied() { + hilog.info(0x0000, 'testTag', 'server is died'); + } +}; +let deathRecipient = new MyDeathRecipient(); +// [End rpc_front-end_dependencies] + +@Entry +@Component +struct ButtonCase1 { + // [Start rpc_define_context] + private context = this.getUIContext().getHostContext() as common.UIAbilityContext; + pathStack: NavPathStack = new NavPathStack(); + // [End rpc_define_context] + + build() { + + Navigation(this.pathStack) { + List({ space: 20 }) { + + ListItem() { + Button('getPermission').onClick(() => { + getPermission(this.context); + }) + .width('100%') + } + + ListItem() { + Button('getDeviceId').onClick(() => { + getDeviceId(); + }) + .width('100%') + } + + ListItem() { + Button('connectAbility').onClick(() => { + connectAbility(this.context); + }) + .width('100%') + } + + ListItem() { + Button('sendRequest_String').onClick(() => { + sendString(); + }) + .width('100%') + } + + ListItem() { + Button('disconnectAbility').onClick(() => { + disconnectAbility(this.context); + }) + .width('100%') + } + } + .listDirection(Axis.Vertical) + .backgroundColor(0xDCDCDC).padding(20) + } + + .mode(NavigationMode.Stack) + } +} + +// [Start rpc_funcation_implement] +// [Start rpc_connect] +// 获取权限 +function getPermission(context:common.UIAbilityContext) { + hilog.info(0x00000, 'testTag', 'RpcClient: begin to requestPermissions'); + try { + let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager(); + atManager.requestPermissionsFromUser(context, ['ohos.permission.DISTRIBUTED_DATASYNC'], + (err: BusinessError, data: PermissionRequestResult) => { + if (err) { + hilog.error(0x0000, 'testTag', 'RpcClient: requestPermissions failed, code is ' + + err.code + ', message is ' + err.message); + } else { + hilog.info(0x0000, 'testTag','RpcClient: requestPermissions success, result is ' + JSON.stringify(data)); + hilog.info(0x0000, 'testTag','RpcClient: data permissions is ' + data.permissions); + hilog.info(0x0000, 'testTag','RpcClient: data authResults is ' + data.authResults); + hilog.info(0x0000, 'testTag','RpcClient: data dialogShownResults is ' + data.dialogShownResults); + } + }); + }catch (err) { + let code = (err as BusinessError).code; + let message = (err as BusinessError).message; + hilog.error(0x0000, 'testTag', 'RpcClient: getPermission failed, code is ' + code + ', message is ' + message); + } +} + +// 获取对端设备信息 +function getDeviceId(){ + hilog.info(0x00000, 'testTag', 'RpcClient: begin to getDeviceId'); + try { + dmInstance = distributedDeviceManager.createDeviceManager('com.example.rpc_client'); + hilog.info(0x0000, 'testTag', 'RpcClient: createDeviceManager success'); + deviceList = dmInstance.getAvailableDeviceListSync(); + hilog.info(0x0000, 'testTag', 'RpcClient: deviceList is' + JSON.stringify(deviceList)); + if (deviceList.length !== 0) { + deviceId = deviceList[0].networkId; + hilog.info(0x0000, 'testTag', 'RpcClient: networkId is ' + deviceId); + } + }catch (err) { + let code = (err as BusinessError).code; + let message = (err as BusinessError).message; + hilog.error(0x0000, 'testTag', 'RpcClient: getDeviceId failed, code is ' + code + ', message is ' + message); + } +} + +// 连接服务 +function connectAbility(context:common.UIAbilityContext) { + hilog.info(0x00000, 'testTag', 'RpcClient: begin to connect Ability'); + let want: Want = { + bundleName: 'com.example.rpc_stub', + abilityName: 'ServiceAbility', + deviceId: deviceId, + } + + let connect: common.ConnectOptions = { + onConnect: (elementName, remoteProxy) => { + hilog.info(0x00000, 'testTag', 'RpcClient: onConnect. elementName is :' + JSON.stringify(elementName)); + proxy = remoteProxy; + // 客户端注册死亡监听 + try { + proxy.registerDeathRecipient(deathRecipient, 0); + hilog.info(0x00000, 'testTag', 'RpcClient: registerDeathRecipient success'); + }catch (err) { + let code = (err as BusinessError).code; + let message = (err as BusinessError).message; + hilog.error(0x0000, 'testTag', 'RpcClient: register failed, code is ' + code + ', message is ' + message); + } + }, + onDisconnect: (elementName) => { + hilog.info(0x0000, 'testTag', 'RpcClient: onDisconnect. elementName is ' + JSON.stringify(elementName)); + // 客户端移除死亡监听 + try { + proxy?.unregisterDeathRecipient(deathRecipient, 0); + hilog.info(0x00000, 'testTag', 'RpcClient: unregisterDeathRecipient success'); + }catch (err) { + let code = (err as BusinessError).code; + let message = (err as BusinessError).message; + hilog.error(0x0000, 'testTag', 'RpcClient: unregister failed, code is ' + code + ', message is ' + message); + } + proxy = undefined; + }, + onFailed: (code: number) => { + hilog.info(0x0000, 'testTag', 'RpcClient: onFailed. code is :' + code); + }, + } + + try { + connectId = context.connectServiceExtensionAbility(want, connect); + }catch (err) { + let code = (err as BusinessError).code; + let message = (err as BusinessError).message; + hilog.error(0x0000, 'testTag', 'RpcClient: connectService failed, code is ' + code + ', message is ' + message); + } +} +// [End rpc_connect] + +// 断开连接 +function disconnectAbility(context: common.UIAbilityContext) { + hilog.info(0x00000, 'testTag', 'RpcClient: begin to disconnect Ability'); + if (connectId != undefined) { + try { + context.disconnectServiceExtensionAbility(connectId); + }catch (err) { + let code = (err as BusinessError).code; + let message = (err as BusinessError).message; + hilog.error(0x0000, 'testTag', 'pcClient: disconnectService failed, code is ' + code + ', message is ' + message); + } + } +} + +// 发送消息 +function sendString() { + hilog.info(0x00000, 'testTag', 'RpcClient: begin to send string'); + let option = new rpc.MessageOption(); + let data = rpc.MessageSequence.create(); + let reply = rpc.MessageSequence.create(); + // 在data里写入参数,以传递字符串为例 + data.writeString('hello world'); + + if (proxy != undefined) { + proxy.sendMessageRequest(1, data, reply, option) + .then((result: rpc.RequestResult) => { + if (result.errCode != 0) { + hilog.error(0x0000, 'testTag', 'RpcClient: sendMessageRequest failed, errCode: ' + result.errCode); + return; + } + // 从result.reply里读取结果 + let str = result.reply.readString(); + hilog.info(0x0000, 'testTag', 'RpcClient: sendMessageRequest receiver, str: ' + str); + }) + .catch((e: Error) => { + hilog.error(0x0000, 'testTag', 'pcClient: sendMessageRequest failed, error is ' + JSON.stringify(e)); + }) + .finally(() => { + data.reclaim(); + reply.reclaim(); + }) + } +} +// [End rpc_funcation_implement] + + diff --git a/IPC/RPC_sendMessage/RPC_Client/entry/src/main/module.json5 b/IPC/RPC_sendMessage/RPC_Client/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..dc4dffcd860891a328a9929b89a82cd7b630bd2b --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Client/entry/src/main/module.json5 @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "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.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "ohos.want.action.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ], + } + ], + "requestPermissions": [ + { // 允许查询应用的基本信息 + "name": "ohos.permission.GET_BUNDLE_INFO" + }, + { // 允许不同设备间的数据交换的权限,必须要加"reason""usedScene" + "name": "ohos.permission.DISTRIBUTED_DATASYNC", + "reason": "$string:app_name", + "usedScene": { + "abilities": [ + "EntryAbility" + ], + "when": "always" + } + } + ] + } +} \ No newline at end of file diff --git a/IPC/RPC_sendMessage/RPC_Client/entry/src/main/resources/base/element/color.json b/IPC/RPC_sendMessage/RPC_Client/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Client/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/IPC/RPC_sendMessage/RPC_Client/entry/src/main/resources/base/element/float.json b/IPC/RPC_sendMessage/RPC_Client/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Client/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/IPC/RPC_sendMessage/RPC_Client/entry/src/main/resources/base/element/string.json b/IPC/RPC_sendMessage/RPC_Client/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Client/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/IPC/RPC_sendMessage/RPC_Client/entry/src/main/resources/base/media/background.png b/IPC/RPC_sendMessage/RPC_Client/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/IPC/RPC_sendMessage/RPC_Client/entry/src/main/resources/base/media/background.png differ diff --git a/IPC/RPC_sendMessage/RPC_Client/entry/src/main/resources/base/media/foreground.png b/IPC/RPC_sendMessage/RPC_Client/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/IPC/RPC_sendMessage/RPC_Client/entry/src/main/resources/base/media/foreground.png differ diff --git a/IPC/RPC_sendMessage/RPC_Client/entry/src/main/resources/base/media/layered_image.json b/IPC/RPC_sendMessage/RPC_Client/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Client/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/IPC/RPC_sendMessage/RPC_Client/entry/src/main/resources/base/media/startIcon.png b/IPC/RPC_sendMessage/RPC_Client/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/IPC/RPC_sendMessage/RPC_Client/entry/src/main/resources/base/media/startIcon.png differ diff --git a/IPC/RPC_sendMessage/RPC_Client/entry/src/main/resources/base/profile/backup_config.json b/IPC/RPC_sendMessage/RPC_Client/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Client/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/IPC/RPC_sendMessage/RPC_Client/entry/src/main/resources/base/profile/main_pages.json b/IPC/RPC_sendMessage/RPC_Client/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Client/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/IPC/RPC_sendMessage/RPC_Client/entry/src/main/resources/dark/element/color.json b/IPC/RPC_sendMessage/RPC_Client/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Client/entry/src/main/resources/dark/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] +} \ No newline at end of file diff --git a/IPC/RPC_sendMessage/RPC_Client/entry/src/mock/mock-config.json5 b/IPC/RPC_sendMessage/RPC_Client/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..cc676b366f202be456aae961ff5ee09b2f6713ca --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Client/entry/src/mock/mock-config.json5 @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2025 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. + */ + +{ +} \ No newline at end of file diff --git a/IPC/RPC_sendMessage/RPC_Client/entry/src/ohosTest/ets/test/Ability.test.ets b/IPC/RPC_sendMessage/RPC_Client/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..3c81579a25ae2430d5c8050c62a1fc14a7b0cf62 --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Client/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2025 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 '@kit.PerformanceAnalysisKit'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // 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(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // 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(() => { + // 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('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }) + }) +} \ No newline at end of file diff --git a/IPC/RPC_sendMessage/RPC_Client/entry/src/ohosTest/ets/test/List.test.ets b/IPC/RPC_sendMessage/RPC_Client/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..cefb5e406030b28a58d7835468d0fe131e352cc0 --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Client/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 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/IPC/RPC_sendMessage/RPC_Client/entry/src/ohosTest/module.json5 b/IPC/RPC_sendMessage/RPC_Client/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7e310427a2df451401b6a92b04b05e0794905dd6 --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Client/entry/src/ohosTest/module.json5 @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/IPC/RPC_sendMessage/RPC_Client/entry/src/test/List.test.ets b/IPC/RPC_sendMessage/RPC_Client/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..74ba3a099410b447742c4a6ecac5c511bb63e5e7 --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Client/entry/src/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 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 localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/IPC/RPC_sendMessage/RPC_Client/entry/src/test/LocalUnit.test.ets b/IPC/RPC_sendMessage/RPC_Client/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..b367c75db8ae9ad0864a7c14f9bf2ce8c2b5e021 --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Client/entry/src/test/LocalUnit.test.ets @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // 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(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // 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(() => { + // 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('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/IPC/RPC_sendMessage/RPC_Client/hvigor/hvigor-config.json5 b/IPC/RPC_sendMessage/RPC_Client/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f157d908f1551938f1c699f7b7468f44088ab7db --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Client/hvigor/hvigor-config.json5 @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "modelVersion": "6.0.0", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | "ultrafine" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + // "optimizationStrategy": "memory" /* Define the optimization strategy. Value: [ "memory" | "performance" ]. Default: "memory" */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/IPC/RPC_sendMessage/RPC_Client/hvigorfile.ts b/IPC/RPC_sendMessage/RPC_Client/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..de06c780c9687a49f0161e161816f18af7354ff0 --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Client/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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 { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins: [] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file diff --git a/IPC/RPC_sendMessage/RPC_Client/image/RPC_Client.png b/IPC/RPC_sendMessage/RPC_Client/image/RPC_Client.png new file mode 100644 index 0000000000000000000000000000000000000000..8b3fcfbb41b2a61fbd6b1d55049df481a1fd9cff Binary files /dev/null and b/IPC/RPC_sendMessage/RPC_Client/image/RPC_Client.png differ diff --git a/IPC/RPC_sendMessage/RPC_Client/image/RPC_Stub.png b/IPC/RPC_sendMessage/RPC_Client/image/RPC_Stub.png new file mode 100644 index 0000000000000000000000000000000000000000..f6fa87e8b1b542cf8c9d14e4f1dfbb2cc3990283 Binary files /dev/null and b/IPC/RPC_sendMessage/RPC_Client/image/RPC_Stub.png differ diff --git a/IPC/RPC_sendMessage/RPC_Client/image/app_signature.png b/IPC/RPC_sendMessage/RPC_Client/image/app_signature.png new file mode 100644 index 0000000000000000000000000000000000000000..f22253a055d964704d8278bfa6675df97ef47b08 Binary files /dev/null and b/IPC/RPC_sendMessage/RPC_Client/image/app_signature.png differ diff --git a/IPC/RPC_sendMessage/RPC_Client/image/comment.png b/IPC/RPC_sendMessage/RPC_Client/image/comment.png new file mode 100644 index 0000000000000000000000000000000000000000..eb663adfedd7cdde03418946be92b67addf57cb5 Binary files /dev/null and b/IPC/RPC_sendMessage/RPC_Client/image/comment.png differ diff --git a/IPC/RPC_sendMessage/RPC_Client/image/configure.png b/IPC/RPC_sendMessage/RPC_Client/image/configure.png new file mode 100644 index 0000000000000000000000000000000000000000..d09d87abb4c581f0f043b8fc7f6982059f3118ce Binary files /dev/null and b/IPC/RPC_sendMessage/RPC_Client/image/configure.png differ diff --git a/IPC/RPC_sendMessage/RPC_Client/image/getPermission.png b/IPC/RPC_sendMessage/RPC_Client/image/getPermission.png new file mode 100644 index 0000000000000000000000000000000000000000..d9489c9601187b7665089cda1979bc7acd7145f2 Binary files /dev/null and b/IPC/RPC_sendMessage/RPC_Client/image/getPermission.png differ diff --git a/IPC/RPC_sendMessage/RPC_Client/image/recv_install_list_capability.png b/IPC/RPC_sendMessage/RPC_Client/image/recv_install_list_capability.png new file mode 100644 index 0000000000000000000000000000000000000000..8fae5e9b11da33f1be60f055425aa6985833ed2b Binary files /dev/null and b/IPC/RPC_sendMessage/RPC_Client/image/recv_install_list_capability.png differ diff --git a/IPC/RPC_sendMessage/RPC_Client/oh-package.json5 b/IPC/RPC_sendMessage/RPC_Client/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..19e26ca33e54ca6961482424ce0dfffc20c37f42 --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Client/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "modelVersion": "6.0.0", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.24", + "@ohos/hamock": "1.0.0" + } +} diff --git a/IPC/RPC_sendMessage/RPC_Client/ohosTest.md b/IPC/RPC_sendMessage/RPC_Client/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..9abf1d0540a41d2d9aa23e30a17241ee89db8ac6 --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Client/ohosTest.md @@ -0,0 +1,14 @@ +# RPC_Client 测试用例归档 + +## 用例表 + +|测试功能|预置条件| 输入 |预期输出|测试结果| +|----------|-----------|----------|----------------|----------------| +|拉起应用|安装sample| 无 |成功拉起应用|Pass| +|检测首页UI|进入首页| 无 |首页UI显示正常|Pass| +|获取权限| getPermission 按钮显示正常| 点击 getPermission 按钮 |允许多设备协同弹窗正常弹出,点击允许按钮后,日志中打印“RpcClient: requestPermissionsFromUser success, result is xxxx”,符合预期|Pass| +|获取对端设备信息| getDeviceId 按钮显示正常| 点击 getDeviceId 按钮 |成功获取对端设备信息,日志中打印“RpcClient: deviceList is xxxx”,符合预期|Pass| +|连接服务| connecAbility 按钮显示正常| 点击 connecAbility 按钮 |因服务端在后台运行,连接服务成功,日志中打印“RpcClient: onConnect. elementName is xxxx”相关日志,符合预期|Pass| +|发送字符串信息| sendRequest_String 按钮显示正常| 点击 sendRequest_String 按钮 |成功发送消息,并接收服务端返回的字符串,日志中打印“RpcClient: sendMessageRequest receive str is hello rpc”,符合预期|Pass| +|断开连接| disconnecAbility 按钮显示正常| 点击 disconnecAbility 按钮 |成功断开服务,日志中打印“RpcClient: onDisconnect. elementName is xxx”,符合预期|Pass| +|死亡回调| 服务端应用手动kill或进行退出后台| 手动清理服务端所在后台应用 |服务端死亡,日志中打印“RpcClient: server is died”,符合预期|Pass| diff --git a/IPC/RPC_sendMessage/RPC_Stub/AppScope/app.json5 b/IPC/RPC_sendMessage/RPC_Stub/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e9dacdea84a7915a6419b4cfcd3cbe82771429c7 --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Stub/AppScope/app.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "app": { + "bundleName": "com.example.rpc_stub", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/IPC/RPC_sendMessage/RPC_Stub/AppScope/resources/base/element/string.json b/IPC/RPC_sendMessage/RPC_Stub/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..68118cc828bf536fb21daf277da0e4e00f1d5a19 --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Stub/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "RPC_Stub" + } + ] +} diff --git a/IPC/RPC_sendMessage/RPC_Stub/AppScope/resources/base/media/background.png b/IPC/RPC_sendMessage/RPC_Stub/AppScope/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/IPC/RPC_sendMessage/RPC_Stub/AppScope/resources/base/media/background.png differ diff --git a/IPC/RPC_sendMessage/RPC_Stub/AppScope/resources/base/media/foreground.png b/IPC/RPC_sendMessage/RPC_Stub/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..eb9427585b36d14b12477435b6419d1f07b3e0bb Binary files /dev/null and b/IPC/RPC_sendMessage/RPC_Stub/AppScope/resources/base/media/foreground.png differ diff --git a/IPC/RPC_sendMessage/RPC_Stub/AppScope/resources/base/media/layered_image.json b/IPC/RPC_sendMessage/RPC_Stub/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Stub/AppScope/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/IPC/RPC_sendMessage/RPC_Stub/build-profile.json5 b/IPC/RPC_sendMessage/RPC_Stub/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9f1589f39ac02d5911acd04accf01be11031c80b --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Stub/build-profile.json5 @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compileSdkVersion": 20, + "targetSdkVersion": 20, + "compatibleSdkVersion": 20, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/IPC/RPC_sendMessage/RPC_Stub/entry/.gitignore b/IPC/RPC_sendMessage/RPC_Stub/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Stub/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/IPC/RPC_sendMessage/RPC_Stub/entry/build-profile.json5 b/IPC/RPC_sendMessage/RPC_Stub/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7961c5611ea6da0aba83dbb6b484f28ac3788a7 --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Stub/entry/build-profile.json5 @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "resOptions": { + "copyCodeResource": { + "enable": false + } + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/IPC/RPC_sendMessage/RPC_Stub/entry/hvigorfile.ts b/IPC/RPC_sendMessage/RPC_Stub/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..10f881f112b08550ed5c8a3ceb7d0148be2a0b6e --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Stub/entry/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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 { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins: [] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file diff --git a/IPC/RPC_sendMessage/RPC_Stub/entry/obfuscation-rules.txt b/IPC/RPC_sendMessage/RPC_Stub/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Stub/entry/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/IPC/RPC_sendMessage/RPC_Stub/entry/oh-package.json5 b/IPC/RPC_sendMessage/RPC_Stub/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..114cb176e4a4d08801ddb6ddf39ef3d0df76dc2f --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Stub/entry/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/IPC/RPC_sendMessage/RPC_Stub/entry/src/main/ets/ServiceExtAbility/ServiceExtAbility.ets b/IPC/RPC_sendMessage/RPC_Stub/entry/src/main/ets/ServiceExtAbility/ServiceExtAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..bb99d32716c9719b6600a9a703fefc2dfa7c2b85 --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Stub/entry/src/main/ets/ServiceExtAbility/ServiceExtAbility.ets @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2025 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 { ServiceExtensionAbility, Want } from '@kit.AbilityKit'; +import { rpc } from '@kit.IPCKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +// 定义服务端 +class Stub extends rpc.RemoteObject { + constructor(descriptor: string) { + super(descriptor); + } + onRemoteMessageRequest(code: number, data: rpc.MessageSequence, reply: rpc.MessageSequence, + option: rpc.MessageOption): boolean | Promise { + // 服务端Stub根据不同的请求code分别执行对应的处理流程 + if (code == 1) { + let str = data.readString(); + hilog.info(0x0000, 'testTag', 'RPC_Stub: stub receive str is ' + str); + // 服务端使用reply回传请求处理的结果给客户端 + reply.writeString('hello rpc'); + return true; + } else { + hilog.info(0x0000, 'testTag', 'RPC_Stub: stub unknown code, code is ' + code); + return false; + } + } +} + +// 定义后台服务 +export default class ServiceAbility extends ServiceExtensionAbility { + onCreate(want: Want): void { + hilog.info(0x0000, 'testTag', 'RPC_Stub: onCreate'); + } + + onRequest(want: Want, startId: number): void { + hilog.info(0x0000, 'testTag', 'RPC_Stub: onRequest'); + } + + onConnect(want: Want): rpc.RemoteObject { + hilog.info(0x0000, 'testTag', 'RPC_Stub: onConnect'); + // 返回Stub对象,客户端获取后便可以与ServiceExtensionAbility进行通信 + return new Stub('RPCStubTest'); + } + + onDisconnect(want: Want): void { + hilog.info(0x0000, 'testTag', 'RPC_Stub: onDisconnect'); + } + + onDestroy(): void { + hilog.info(0x0000, 'testTag', 'RPC_Stub: onDestroy'); + } +} \ No newline at end of file diff --git a/IPC/RPC_sendMessage/RPC_Stub/entry/src/main/ets/entryability/EntryAbility.ets b/IPC/RPC_sendMessage/RPC_Stub/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..5592b0500ad9887e46faa0d87b1302003aeb200b --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Stub/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2025 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 { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +const DOMAIN = 0x0000; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + try { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + } catch (err) { + hilog.error(DOMAIN, 'testTag', 'Failed to set colorMode. Cause: %{public}s', JSON.stringify(err)); + } + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/IPC/RPC_sendMessage/RPC_Stub/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/IPC/RPC_sendMessage/RPC_Stub/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b37e4b57cd7849ab462574297ff70345c2132ab2 --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Stub/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025 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 '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +const DOMAIN = 0x0000; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(DOMAIN, 'testTag', 'onBackup ok'); + await Promise.resolve(); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(DOMAIN, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + await Promise.resolve(); + } +} \ No newline at end of file diff --git a/IPC/RPC_sendMessage/RPC_Stub/entry/src/main/ets/pages/Index.ets b/IPC/RPC_sendMessage/RPC_Stub/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..924c78a900aa78e7ff285b64d4f4b8703ea90f3d --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Stub/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2025 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 { BusinessError } from '@kit.BasicServicesKit'; +import { abilityAccessCtrl, PermissionRequestResult, common } from '@kit.AbilityKit'; + +@Entry +@Component +struct Index { + private context = this.getUIContext().getHostContext() as common.UIAbilityContext; + @State message: string = 'Hello World'; + + build() { + RelativeContainer() { + Text(this.message) + .id('HelloWorld') + .fontSize($r('app.float.page_text_font_size')) + .fontWeight(FontWeight.Bold) + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + .onClick(() => { + this.message = 'Welcome'; + }) + + Button('getPermission') + .onClick(() => { + try { + let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager(); + atManager.requestPermissionsFromUser(this.context, ['ohos.permission.DISTRIBUTED_DATASYNC'], (err: BusinessError, data: PermissionRequestResult) => { + if (err) { + hilog.error(0x0000, 'testTag', 'RPC_Stub: requestPermissionsFromUser fail, code is ' + err.code + 'message is ' + err.message); + } else { + hilog.info(0x0000, 'testTag','RPC_Stub: requestPermissionsFromUser success, result is ' + JSON.stringify(data)); + hilog.info(0x0000, 'testTag','RPC_Stub: requestPermissionsFromUser data permissions:' + data.permissions); + hilog.info(0x0000, 'testTag','RPC_Stub: requestPermissionsFromUser data authResults:' + data.authResults); + hilog.info(0x0000, 'testTag','RPC_Stub: requestPermissionsFromUser data dialogShownResults:' + data.dialogShownResults); + } + }); + }catch (err) { + let code = (err as BusinessError).code; + let message = (err as BusinessError).message; + hilog.error(0x0000, 'testTag', 'RPC_Stub: getPermission failed, code is ' + code + 'message is ' + message); + } + }) + .width('100%') + .height(60) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/IPC/RPC_sendMessage/RPC_Stub/entry/src/main/module.json5 b/IPC/RPC_sendMessage/RPC_Stub/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..2391c576f0ed75f60b484fd12376bf2cd73bc6fd --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Stub/entry/src/main/module.json5 @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "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.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "ohos.want.action.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ], + }, + { + "name": "ServiceAbility", + "srcEntry": "./ets/ServiceExtAbility/ServiceExtAbility.ets", + "type": "service", + "exported": true, //可被其他三方应用拉起,若设为false,需在客户端配置ohos.permission.START_INVISIBLE_ABILITY + "description": "service" + } + ], + + "requestPermissions": [ + { + "name": "ohos.permission.GET_BUNDLE_INFO" + }, + // 允许不同设备间的数据交换的权限,必须要加"reason""usedScene" + { + "name": "ohos.permission.DISTRIBUTED_DATASYNC", + "reason": "$string:app_name", + "usedScene": { + "abilities": [ + "EntryAbility" + ], + "when": "always" + } + }, + ] + + } +} \ No newline at end of file diff --git a/IPC/RPC_sendMessage/RPC_Stub/entry/src/main/resources/base/element/color.json b/IPC/RPC_sendMessage/RPC_Stub/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Stub/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/IPC/RPC_sendMessage/RPC_Stub/entry/src/main/resources/base/element/float.json b/IPC/RPC_sendMessage/RPC_Stub/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Stub/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/IPC/RPC_sendMessage/RPC_Stub/entry/src/main/resources/base/element/string.json b/IPC/RPC_sendMessage/RPC_Stub/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Stub/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/IPC/RPC_sendMessage/RPC_Stub/entry/src/main/resources/base/media/background.png b/IPC/RPC_sendMessage/RPC_Stub/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/IPC/RPC_sendMessage/RPC_Stub/entry/src/main/resources/base/media/background.png differ diff --git a/IPC/RPC_sendMessage/RPC_Stub/entry/src/main/resources/base/media/foreground.png b/IPC/RPC_sendMessage/RPC_Stub/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/IPC/RPC_sendMessage/RPC_Stub/entry/src/main/resources/base/media/foreground.png differ diff --git a/IPC/RPC_sendMessage/RPC_Stub/entry/src/main/resources/base/media/layered_image.json b/IPC/RPC_sendMessage/RPC_Stub/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Stub/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/IPC/RPC_sendMessage/RPC_Stub/entry/src/main/resources/base/media/startIcon.png b/IPC/RPC_sendMessage/RPC_Stub/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/IPC/RPC_sendMessage/RPC_Stub/entry/src/main/resources/base/media/startIcon.png differ diff --git a/IPC/RPC_sendMessage/RPC_Stub/entry/src/main/resources/base/profile/backup_config.json b/IPC/RPC_sendMessage/RPC_Stub/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Stub/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/IPC/RPC_sendMessage/RPC_Stub/entry/src/main/resources/base/profile/main_pages.json b/IPC/RPC_sendMessage/RPC_Stub/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Stub/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/IPC/RPC_sendMessage/RPC_Stub/entry/src/main/resources/dark/element/color.json b/IPC/RPC_sendMessage/RPC_Stub/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Stub/entry/src/main/resources/dark/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] +} \ No newline at end of file diff --git a/IPC/RPC_sendMessage/RPC_Stub/entry/src/mock/mock-config.json5 b/IPC/RPC_sendMessage/RPC_Stub/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..cc676b366f202be456aae961ff5ee09b2f6713ca --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Stub/entry/src/mock/mock-config.json5 @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2025 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. + */ + +{ +} \ No newline at end of file diff --git a/IPC/RPC_sendMessage/RPC_Stub/entry/src/ohosTest/ets/test/Ability.test.ets b/IPC/RPC_sendMessage/RPC_Stub/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..3c81579a25ae2430d5c8050c62a1fc14a7b0cf62 --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Stub/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2025 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 '@kit.PerformanceAnalysisKit'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // 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(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // 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(() => { + // 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('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }) + }) +} \ No newline at end of file diff --git a/IPC/RPC_sendMessage/RPC_Stub/entry/src/ohosTest/ets/test/List.test.ets b/IPC/RPC_sendMessage/RPC_Stub/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..cefb5e406030b28a58d7835468d0fe131e352cc0 --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Stub/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 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/IPC/RPC_sendMessage/RPC_Stub/entry/src/ohosTest/module.json5 b/IPC/RPC_sendMessage/RPC_Stub/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7e310427a2df451401b6a92b04b05e0794905dd6 --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Stub/entry/src/ohosTest/module.json5 @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/IPC/RPC_sendMessage/RPC_Stub/entry/src/test/List.test.ets b/IPC/RPC_sendMessage/RPC_Stub/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..74ba3a099410b447742c4a6ecac5c511bb63e5e7 --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Stub/entry/src/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 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 localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/IPC/RPC_sendMessage/RPC_Stub/entry/src/test/LocalUnit.test.ets b/IPC/RPC_sendMessage/RPC_Stub/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..b367c75db8ae9ad0864a7c14f9bf2ce8c2b5e021 --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Stub/entry/src/test/LocalUnit.test.ets @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // 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(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // 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(() => { + // 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('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/IPC/RPC_sendMessage/RPC_Stub/hvigor/hvigor-config.json5 b/IPC/RPC_sendMessage/RPC_Stub/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f157d908f1551938f1c699f7b7468f44088ab7db --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Stub/hvigor/hvigor-config.json5 @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "modelVersion": "6.0.0", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | "ultrafine" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + // "optimizationStrategy": "memory" /* Define the optimization strategy. Value: [ "memory" | "performance" ]. Default: "memory" */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/IPC/RPC_sendMessage/RPC_Stub/hvigorfile.ts b/IPC/RPC_sendMessage/RPC_Stub/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..de06c780c9687a49f0161e161816f18af7354ff0 --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Stub/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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 { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins: [] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file diff --git a/IPC/RPC_sendMessage/RPC_Stub/oh-package.json5 b/IPC/RPC_sendMessage/RPC_Stub/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..19e26ca33e54ca6961482424ce0dfffc20c37f42 --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Stub/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "modelVersion": "6.0.0", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.24", + "@ohos/hamock": "1.0.0" + } +} diff --git a/IPC/RPC_sendMessage/RPC_Stub/ohosTest.md b/IPC/RPC_sendMessage/RPC_Stub/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..83fa76b93f7abb9c454c988ce36cf0e3fedf7767 --- /dev/null +++ b/IPC/RPC_sendMessage/RPC_Stub/ohosTest.md @@ -0,0 +1,10 @@ +# RPC_Stub 测试用例归档 + +## 用例表 + +|测试功能|预置条件| 输入 |预期输出|测试结果| +|----------|-----------|----------|----------------|----------------| +|拉起应用|安装sample| 无 |成功拉起应用|Pass| +|检测首页UI|进入首页| 无 |首页UI显示正常|Pass| +|获取权限| getPermission 按钮显示正常| 点击 getPermission 按钮 |允许多设备协同弹窗正常弹出,点击允许按钮后,日志中打印“RPC_Stub: requestPermissionsFromUser success, result is xxxx”,符合预期|Pass| +|收到服务端信息| 客户端成功连接服务,并发送请求| 无 |日志中打印“RPC_Stub: stub receive str is hello world”,符合预期|Pass|