diff --git a/OAT.xml b/OAT.xml index 8e93980e9a11714d923b1d13a42de0abee4f6155..e76ee8a0dc618898f66164e2223c168d5e5a84a4 100644 --- a/OAT.xml +++ b/OAT.xml @@ -131,6 +131,10 @@ Note:If the text contains special characters, please escape them according to th + + + + @@ -179,7 +183,7 @@ Note:If the text contains special characters, please escape them according to th - + @@ -1214,6 +1218,10 @@ Note:If the text contains special characters, please escape them according to th + + + + @@ -2209,7 +2217,11 @@ Note:If the text contains special characters, please escape them according to th - + + + + + @@ -2282,6 +2294,10 @@ Note:If the text contains special characters, please escape them according to th + + + + diff --git a/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/.gitignore b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/.gitignore @@ -0,0 +1,12 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +/.appanalyzer \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/AppScope/app.json5 b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..32442f7dac4dbbe3943412fecc0901bed8e29add --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/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.samples.ipc_client", + "vendor": "samples", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/AppScope/resources/base/element/string.json b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..aa40aa601bc13c125f8c9fc3fe1682d1426e7830 --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "IPC_APP1" + } + ] +} diff --git a/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/AppScope/resources/base/media/app_icon.png b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/AppScope/resources/base/media/app_icon.png differ diff --git a/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/build-profile.json5 b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5f5e6438fd485bf60aa18e0cced046d7e9642a22 --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/build-profile.json5 @@ -0,0 +1,62 @@ +/* + * 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", + "compatibleSdkVersion": "5.0.1(13)", + "runtimeOS": "HarmonyOS", + "buildOption": { + "externalNativeOptions": { + "abiFilters": [ + "arm64-v8a", + "x86_64" + ] + }, + "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/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/.gitignore b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/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/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/build-profile.json5 b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9cee8f80d5227fe2874e981b798542b6fb3b9405 --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/build-profile.json5 @@ -0,0 +1,49 @@ +/* + * 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": { + "externalNativeOptions": { + "abiFilters": [ + "arm64-v8a", + "x86_64" + ] + } + }, + "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/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/hvigorfile.ts b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/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. */ +} diff --git a/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/obfuscation-rules.txt b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/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/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/oh-package.json5 b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/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/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/src/main/ets/client/cnn/IPC_Client.ets b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/src/main/ets/client/cnn/IPC_Client.ets new file mode 100644 index 0000000000000000000000000000000000000000..49109629a7f5c69fd6469c20ed5fb7246698d854 --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/src/main/ets/client/cnn/IPC_Client.ets @@ -0,0 +1,180 @@ +/* + * 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 rpc from '@ohos.rpc'; +import Want from '@ohos.app.ability.Want'; +import common from '@ohos.app.ability.common'; +import hilog from '@ohos.hilog' +import { BusinessError } from '@kit.BasicServicesKit'; +import { obtainResult } from '../../pages/Index' + +const TAG = 'ClientIpc_App1' +const DOMAIN = 0x0000; + +let proxy: rpc.IRemoteObject | undefined +let connectid: number | undefined +let want: Want = { + bundleName: 'com.samples.ipc_service', + abilityName: 'IpcServiceExtAbility', +} + +// Parcelable对象 +class MyParcelable implements rpc.Parcelable { + public num: number = 0; + public str: string = ''; + + constructor(num: number, str: string) { + this.num = num; + this.str = str; + } + + marshalling(messageSequence: rpc.MessageSequence): boolean { + messageSequence.writeInt(this.num); + messageSequence.writeString(this.str); + return true; + } + + unmarshalling(messageSequence: rpc.MessageSequence): boolean { + this.num = messageSequence.readInt(); + this.str = messageSequence.readString(); + return true; + } +} + +export class ClientIpc { + static bindAbi(context: + common.UIAbilityContext, callback: () => void) { + connectIpc(context, callback); + } + + static unBindAbi(context: common.UIAbilityContext) { + disConnectIpc(context); + } + + // 处理Parcelable数据,调用sendData发送至服务端 + static sendParcelable(str: string) { + if (proxy == undefined) { + hilog.info(DOMAIN, TAG, 'undefined proxy'); + return; + } + let option = new rpc.MessageOption(); + let data = rpc.MessageSequence.create(); + let reply = rpc.MessageSequence.create(); + + // 取决于MyParcelable类如何定义,或需要序列化时准备传递什么数据类型,本示例中MyParcelable是以number和string为例,且服务端接收string + let parcelable = new MyParcelable(1, str); + try { + // 进行校验 + data.writeInterfaceToken(proxy.getDescriptor()); + // 写入Parcelable + data.writeParcelable(parcelable); + } catch (error) { + let e: BusinessError = error as BusinessError; + hilog.info(DOMAIN, TAG, 'ipc write parcelable fail, errorCode ' + e.code + 'errorMessage:' + e.message); + } + + sendData(proxy, 1001, data, reply, option); + } + + // 处理arraybuffer数据,调用sendData发送至服务端 + static sendArrayBuffer(str: string) { + if (proxy == undefined) { + hilog.info(DOMAIN, TAG, 'undefined proxy'); + return; + } + let option = new rpc.MessageOption(); + let data = rpc.MessageSequence.create(); + let reply = rpc.MessageSequence.create(); + + // 将str转为ArrayBuffer + let buffer = new ArrayBuffer(str.length); + let uint8View = new Uint8Array(buffer); + for (let i = 0; i < str.length; i++) { + uint8View[i] = str.charCodeAt(i); + } + try { + // 进行校验 + data.writeInterfaceToken(proxy.getDescriptor()); + // 写入ArrayBuffer + data.writeArrayBuffer(buffer, rpc.TypeCode.UINT8_ARRAY); + } catch (error) { + let e: BusinessError = error as BusinessError; + hilog.info(DOMAIN, TAG, 'ipc write parcelable fail, errorCode ' + e.code + 'errorMessage:' + e.message); + } + + sendData(proxy, 1002, data, reply, option); + } +} + +// 连接服务端 +function connectIpc(context: common.UIAbilityContext, callback: () => void) { + let connect: common.ConnectOptions = { + onConnect: (elementName, remoteProxy) => { + hilog.info(DOMAIN, TAG, 'IpcClient:onConnect.callend(server),elementName:' + + JSON.stringify(elementName)); + proxy = remoteProxy; + obtainResult.result = 'success'; + callback(); + }, + onDisconnect: (elementName) => { + hilog.info(DOMAIN, TAG, 'IpcClient onDisconnect:' + elementName); + }, + onFailed: (code: number) => { + obtainResult.result = 'error ' + code; + hilog.info(DOMAIN, TAG, 'IpcClient onFailed,code:' + code); + callback(); + }, + } + + connectid = context.connectServiceExtensionAbility(want, connect); + hilog.info(DOMAIN, TAG, 'IpcClient connectid:' + connectid); +} + +function disConnectIpc(context: common.UIAbilityContext) { + if (connectid != undefined) { + context.disconnectServiceExtensionAbility(connectid); + } +} + +// 发送信息,arraybuffer和parcelable均调用此处发送至服务端 +function sendData(proxy: rpc.IRemoteObject, code: number, data: rpc.MessageSequence, reply: rpc.MessageSequence, + options: rpc.MessageOption) { + if (proxy == undefined) { + hilog.info(DOMAIN, TAG, 'undefined proxy'); + return; + } + // 用连接服务成功后返回的对象proxy,进行消息发送 + proxy.sendMessageRequest(code, data, reply, options) + .then((result: rpc.RequestResult) => { + if (result.errCode === 0) { + hilog.info(DOMAIN, TAG, 'sendMessageRequest got result'); + try { + let rsp = result.reply.readString(); + hilog.info(DOMAIN, TAG, 'IpcClient result.' + rsp); + } catch (error) { + let e: BusinessError = error as BusinessError; + hilog.error(DOMAIN, TAG, 'rpc read exception fail, error is ' + e); + } + } else { + hilog.error(DOMAIN, TAG, 'RPCTest: sendMessageRequest failed, errCode: ' + result.errCode); + } + }).catch((e: Error) => { + hilog.error(DOMAIN, TAG, 'RPCTest: sendMessageRequest got exception: ' + e); + }).finally(() => { + hilog.info(DOMAIN, TAG, 'RPCTest: sendMessageRequest ends, reclaim parcel'); + data.reclaim(); + reply.reclaim(); + }); +} diff --git a/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/src/main/ets/entryability/EntryAbility.ets b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..1d534b702ae864a9f148d92f01c499779a8db283 --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,60 @@ +/* + * 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 { + AppStorage.setOrCreate('ipc_context', this.context); + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + 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/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/src/main/ets/pages/Index.ets b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..ba7d1361ff976ffd22a6d1cc26411fb1c6d5a082 --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,120 @@ +/* + * 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 { common } from '@kit.AbilityKit'; +import { PromptAction } from '@kit.ArkUI'; +import { ClientIpc } from '../client/cnn/IPC_Client'; + +interface ObtainProxyResults { + result: string; +} + +export const obtainResult: ObtainProxyResults = { + // 用Result存放代理结果 + result: '', +}; + +@Entry +@Component +struct Index { + @State message: string = 'IPC-Client'; + @State inputParcelable: string = ''; + @State inputArrayBuffer: string = ''; + private uiContext: UIContext = this.getUIContext() + private promptAction: PromptAction = this.uiContext.getPromptAction() + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + List({ space: 30 }) { + ListItem() { + Button('获取服务端代理').onClick(() => { + test00(() => { + // 弹窗提示获取代理结果 + this.promptAction.showToast({ + message: obtainResult.result, + duration: 3000 + }); + }) + }) + .width('100%') + } + + ListItem() { + Button('发送Parcelable').onClick(() => { + test01(this.inputParcelable) + }) + .width('100%') + } + + ListItem() { + TextInput({ placeholder: '输入Parcelable传输的内容' }) + .type(InputType.Normal).onChange((text) => { + this.inputParcelable = text; + }) + .width('80%') + } + + ListItem() { + Button('发送ArrayBuffer').onClick(() => { + test02(this.inputArrayBuffer) + }) + .width('100%') + } + + ListItem() { + TextInput({ placeholder: '输入ArrayBuffer传输的内容' }) + .type(InputType.Normal).onChange((text) => { + this.inputArrayBuffer = text; + }) + .width('80%') + } + + ListItem() { + Button('IPC断开通信').onClick(() => { + test03() + }) + .width('100%') + } + } + .listDirection(Axis.Vertical) + .backgroundColor(0xDCDCDC).padding(20) + } + .width('100%') + } + .height('100%') + } +} + +function test00(callback: () => void) { + let cxt = AppStorage.get('ipc_context') as common.UIAbilityContext; + ClientIpc.bindAbi(cxt, callback); +} + +function test01(str: string) { + ClientIpc.sendParcelable(str); +} + +function test02(str: string) { + ClientIpc.sendArrayBuffer(str); +} + +function test03() { + let cxt = AppStorage.get('ipc_context') as common.UIAbilityContext + ClientIpc.unBindAbi(cxt) +} \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/src/main/module.json5 b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ad203eb9d890aae7b88fdb3239385411f8f3251c --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/src/main/module.json5 @@ -0,0 +1,55 @@ +/* + * 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", + "tablet", + "2in1" + ], + + "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": [ + "action.system.home" + ] + } + ] + } + ], + }, + +} diff --git a/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/src/main/resources/base/element/color.json b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/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/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/src/main/resources/base/element/float.json b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/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/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/src/main/resources/base/element/string.json b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/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/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/src/main/resources/base/media/background.png b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/src/main/resources/base/media/background.png differ diff --git a/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/src/main/resources/base/media/foreground.png b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/src/main/resources/base/media/foreground.png differ diff --git a/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/src/main/resources/base/media/layered_image.json b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/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/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/src/main/resources/base/media/startIcon.png b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/src/main/resources/base/media/startIcon.png differ diff --git a/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/src/main/resources/base/profile/backup_config.json b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/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/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/src/main/resources/base/profile/main_pages.json b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/src/main/resources/dark/element/color.json b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/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/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/src/mock/mock-config.json5 b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/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/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/src/ohosTest/ets/test/Ability.test.ets b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..0f8ce9a2c012f8fe36114cef65216ef0b6254f41 --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/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/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/src/ohosTest/ets/test/List.test.ets b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/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/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/src/ohosTest/module.json5 b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6b9889e8ccb62f93825d6b26fa53db8e97a974c0 --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/src/ohosTest/module.json5 @@ -0,0 +1,28 @@ +/* + * 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", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/src/test/List.test.ets b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/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/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/src/test/LocalUnit.test.ets b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/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/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/hvigor/hvigor-config.json5 b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..0bbbb33b0bd997de3ffe32ac6228075c5a4b1f0e --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/hvigor/hvigor-config.json5 @@ -0,0 +1,37 @@ +/* + * 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": "5.0.2", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | 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 */ + }, + "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/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/hvigorfile.ts b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..2a5e543f190732c159beb574dfc9fa37bc94e156 --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/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. */ +} diff --git a/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/oh-package.json5 b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Client/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3b555a4269faeadc6caab93d696e194c30862899 --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/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": "5.0.2", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.21", + "@ohos/hamock": "1.0.0" + } +} diff --git a/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/.gitignore b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/.gitignore @@ -0,0 +1,12 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +/.appanalyzer \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/AppScope/app.json5 b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d0ff6c191bc113cdad4b75c9e4370d13c3c1d27d --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/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.samples.ipc_service", + "vendor": "samples", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/AppScope/resources/base/element/string.json b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..cd0fd2e00ede62a9943573a800cf1d3797d33e09 --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "IPC_APP2" + } + ] +} diff --git a/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/AppScope/resources/base/media/app_icon.png b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/AppScope/resources/base/media/app_icon.png differ diff --git a/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/build-profile.json5 b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..2144ff2bfd7d13ccc6ef51402d0f3c775231357d --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/build-profile.json5 @@ -0,0 +1,56 @@ +/* + * 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", + "compatibleSdkVersion": "5.0.1(13)", + "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/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/.gitignore b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/build-profile.json5 b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/build-profile.json5 @@ -0,0 +1,43 @@ +/* + * 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": { + }, + "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/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/hvigorfile.ts b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/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. */ +} diff --git a/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/obfuscation-rules.txt b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/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/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/oh-package.json5 b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/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/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/main/ets/entryability/EntryAbility.ets b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..d3ee54d2beea61d38866762868bd056d3e39e3c9 --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,59 @@ +/* + * 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 { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + 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/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/main/ets/pages/Index.ets b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..0cf816b07c3e563ae82d269721a30c65ee014d90 --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,62 @@ +/* + * 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 { DataStatus, dataStatus } from '../serviceextability/IPC_Service' + +@Entry +@Component +struct Index { + @State message: string = 'IPC-Server'; + @State statusObj: DataStatus = dataStatus + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + .margin({ + top: '12vp', + bottom: '50vp' + }) + Text('显示接收到的Parcelable: ') + .width('100%') + .fontSize(24) + .textAlign(TextAlign.Start) + TextArea({ placeholder: 'Parcelable', text: this.statusObj.getParcelable }) + .width('100%') + .height('25%') + .fontSize(20) + .margin({ + top: '12vp', + bottom: '60vp' + }) + Text('显示接收到的ArrayBuffer: ') + .width('100%') + .fontSize(24) + TextArea({ placeholder: 'ArrayBuffer', text: this.statusObj.getArrayBuffer }) + .width('100%') + .height('25%') + .fontSize(20) + .margin({ + top: '12vp', + bottom: '20vp' + }) + } + .width('100%') + } + .height('100%') + } +} \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/main/ets/serviceextability/IPC_Service.ets b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/main/ets/serviceextability/IPC_Service.ets new file mode 100644 index 0000000000000000000000000000000000000000..7b51c05f2fdbd2ef744aa50a3dd7d36bb3e41cb9 --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/main/ets/serviceextability/IPC_Service.ets @@ -0,0 +1,114 @@ +/* + * 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 { rpc } from '@kit.IPCKit' +import { util } from '@kit.ArkTS'; +import hilog from '@ohos.hilog' + +const TAG = 'ServerIpc_App2' +const DOMAIN = 0x0000; + +// 状态管理,对嵌套类对象属性变化直接观测 +@Observed +export class DataStatus { + public getParcelable: string = ''; + public getArrayBuffer: string = ''; + + public updataParcelable(v: string) { + this.getParcelable = v; + } + + public updataArrayBuffer(v: string) { + this.getArrayBuffer = v; + } +} + +export const dataStatus = new DataStatus(); + +// 提供服务端能力 +export class StubServer extends rpc.RemoteObject { + public str: string | undefined + + constructor(des: string) { + super(des); + } + + onRemoteMessageRequest(code: number, data: rpc.MessageSequence, reply: rpc.MessageSequence, + options: rpc.MessageOption): boolean | Promise { + hilog.info(DOMAIN, TAG, 'Client Send code:' + code); + let descriptor = this.getDescriptor(); + // 进行校验 + if (descriptor != data.readInterfaceToken()) { + hilog.info(DOMAIN, TAG, 'VERIFICATION FAILED'); + return false; + } + + onHandleClientReq(code, data, reply); + return true; + } + + getLocalInterface(descriptor: string): rpc.IRemoteBroker { + return super.getLocalInterface(descriptor); + } +} + +// Parcelable对象 +class MyParcelable implements rpc.Parcelable { + public num: number = 0; + public str: string = ''; + + constructor(num: number, str: string) { + this.num = num; + this.str = str; + } + + marshalling(messageSequence: rpc.MessageSequence): boolean { + messageSequence.writeInt(this.num); + messageSequence.writeString(this.str); + return true; + } + + unmarshalling(messageSequence: rpc.MessageSequence): boolean { + this.num = messageSequence.readInt(); + this.str = messageSequence.readString(); + return true; + } +} + +// 处理接收到的数据 +function onHandleClientReq(code: number, data: rpc.MessageSequence, reply: rpc.MessageSequence) { + hilog.info(DOMAIN, TAG, 'onHandle Client,code:' + code); + switch (code) { + // 接收parcelable对象 + case 1001: + let parcelable = new MyParcelable(0, ''); + data.readParcelable(parcelable); + dataStatus.updataParcelable(parcelable.str); + hilog.info(DOMAIN, TAG, 'read parcelable: ' + parcelable.str); + break + // 接收arraybuffer + case 1002: + let result = data.readArrayBuffer(rpc.TypeCode.UINT8_ARRAY); + let decoder = util.TextDecoder.create('utf-8'); + let stringData = decoder.decodeToString(new Uint8Array(result)); + dataStatus.updataArrayBuffer(stringData); + hilog.info(DOMAIN, TAG, 'read arraybuffer: ' + stringData); + break; + default: + hilog.info(DOMAIN, TAG, 'onHandleClient-default,code: ' + 1001); + break; + } +} + diff --git a/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/main/ets/serviceextability/ServiceExtAbility.ets b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/main/ets/serviceextability/ServiceExtAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..91884d67b096dc18b01dbdd4f150172e15a49964 --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/main/ets/serviceextability/ServiceExtAbility.ets @@ -0,0 +1,54 @@ +/* + * 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 { rpc } from '@kit.IPCKit' +import { ExtensionAbility as ServiceExtensionAbility, Want } from '@kit.AbilityKit' +import hilog from '@ohos.hilog'; +import { StubServer } from './IPC_Service' + +const TAG = 'ServerIpc_App2' +const DOMAIN = 0x0000; +let globalStubServer: StubServer | undefined + +function getInstance(): StubServer { + if (globalStubServer == undefined) { + globalStubServer = new StubServer('serverStub_app2'); + } + return globalStubServer; +} + +export default class ServiceExtension extends ServiceExtensionAbility { + onCreate(want: Want) { + hilog.info(DOMAIN, TAG, 'ServiceExtensionAbility onCreate,want param:' + JSON.stringify(want) ?? ' '); + } + + onRequest(want: Want, startId: number) { + hilog.info(DOMAIN, TAG, + 'ServiceExtensionAbility onRequest,want param:' + JSON.stringify(want) ?? '+,startId:' + JSON.stringify(startId)); + } + + onConnect(want: Want): rpc.RemoteObject | Promise { + hilog.info(DOMAIN, TAG, 'ServiceExtensionAbility onConnect,want param:' + JSON.stringify(want) ?? ''); + return getInstance(); + } + + onDisconnect(want: Want) { + hilog.info(DOMAIN, TAG, 'ServiceExtensionAbility onDisconnect,want param::' + JSON.stringify(want)); + } + + onDestroy() { + hilog.info(DOMAIN, TAG, 'ServiceExtensionAbility onDestroy'); + } +} diff --git a/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/main/module.json5 b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e40188f49eb5606e7fbd8ca6d13becaec9a1abd0 --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/main/module.json5 @@ -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. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "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": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + //配置IpcServiceExtAbility能力 + { + "name": "IpcServiceExtAbility", + "srcEntry": "./ets/serviceextability/ServiceExtAbility.ets", + "type": "service", + "exported": true, + "description": "service" + } + ] + } +} \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/main/resources/base/element/color.json b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..54bb950ffe672f0f135c6a8d220d86770646cb35 --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFFFF" + } + ] +} \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/main/resources/base/element/float.json b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/main/resources/base/element/string.json b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/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/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/main/resources/base/media/background.png b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/main/resources/base/media/background.png differ diff --git a/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/main/resources/base/media/foreground.png b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/main/resources/base/media/foreground.png differ diff --git a/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/main/resources/base/media/layered_image.json b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/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/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/main/resources/base/media/startIcon.png b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/main/resources/base/media/startIcon.png differ diff --git a/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/main/resources/base/profile/backup_config.json b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/main/resources/base/profile/main_pages.json b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/main/resources/dark/element/color.json b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/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/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/mock/mock-config.json5 b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/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/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/ohosTest/ets/test/Ability.test.ets b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..0f8ce9a2c012f8fe36114cef65216ef0b6254f41 --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/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/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/ohosTest/ets/test/List.test.ets b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/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/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/ohosTest/module.json5 b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6b9889e8ccb62f93825d6b26fa53db8e97a974c0 --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/ohosTest/module.json5 @@ -0,0 +1,28 @@ +/* + * 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", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/test/List.test.ets b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/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/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/test/LocalUnit.test.ets b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/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/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/hvigor/hvigor-config.json5 b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..0bbbb33b0bd997de3ffe32ac6228075c5a4b1f0e --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/hvigor/hvigor-config.json5 @@ -0,0 +1,37 @@ +/* + * 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": "5.0.2", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | 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 */ + }, + "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/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/hvigorfile.ts b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..2a5e543f190732c159beb574dfc9fa37bc94e156 --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/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. */ +} diff --git a/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/oh-package.json5 b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3b555a4269faeadc6caab93d696e194c30862899 --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/IPC_Service/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": "5.0.2", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.21", + "@ohos/hamock": "1.0.0" + } +} diff --git a/code/BasicFeature/Connectivity/IPC/ObjectTransfer/README.md b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/README.md new file mode 100644 index 0000000000000000000000000000000000000000..5b60d171dc671b95a96df7793d02b9207d05e766 --- /dev/null +++ b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/README.md @@ -0,0 +1,329 @@ +# IPC通信示例 + +## 一、介绍 + +本示例展示了如何使用[@ohos.rpc](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ipc-kit/js-apis-rpc.md) 相关接口,开发一个IPC客户端与服务端通信的完整示例,并在此示例中演示如何使用Parcelable/ArrayBuffer对象传递字符串信息。 + +### 1.1、示例界面: +|客户端|服务端| +|-----------------|----------------------| +|![](image/client.png)|![](image/service.png)| + +### 1.2、使用说明: + +1. 点击“获取服务端代理”进行连接服务端,在“发送Parcelable”和“发送ArrayBuffer”底下的输入框中输入发送内容,点击对应按钮即可发送字符串信息至服务端; + +2. 在服务端的“显示接收到的Parcelable”、“显示接收到的ArrayBuffer”文本下显示从客户端发来的对应信息; + + +## 二、工程目录 +### 客户端-IPC_Client +``` +entry/src/main/ets/ +|---entryability +| |---EntryAbility.ets // 入口文件 +|---pages +| |---Index.ets // 页面布局 +|---service/cnn +| |---IPC_Client.ets // 客户端能力,连接服务端,发送Parcelable和ArrayBuffer +``` + +### 服务端-IPC_Service +``` +entry/src/main/ets/ +|---entryability +| |---EntryAbility.ets // 入口文件 +|---pages +| |---Index.ets // 页面布局 +|---serviceextability +| |---IPC_Service.ets // 服务端能力,接收、处理数据 +| |---ServiceExtAbility.ets // Service通用能力 +``` + +## 三、具体实现 + +* 本示例分为两大模块 + + ### 3.1、客户端与服务端的连接和断开模块 + + * 3.1.1、获取服务端代理:按下按钮后,通过connectIpc()中的connectServiceExtensionAbility()进行连接服务端; + ``` + let connect: common.ConnectOptions = { + //回调获取请求结果 + onConnect: (elementName, remoteProxy) => { + hilog.info(DOMAIN, TAG, 'IpcClient:onConnect.callend(server),elementName:'+ + JSON.stringify(elementName)) + proxy = remoteProxy + ObtainResult.Result = 'success' + callback() + }, + onDisconnect: (elementName) => { + hilog.info(DOMAIN, TAG, 'IpcClient onDisconnect:' + elementName) + }, + onFailed: (code: number) => { + ObtainResult.Result = 'error '+code + hilog.info(DOMAIN, TAG, 'IpcClient onFailed,code:' + code) + callback() + }, + } + + //连接至服务端扩展功能 + connectid = context.connectServiceExtensionAbility(want, connect) + hilog.info(DOMAIN, TAG, 'IpcClient connectid:' + connectid) + ``` + * 3.1.2、断开服务端代理:按下按钮后,通过disConnectIpc()disconnectServiceExtensionAbility()进行断开连接; + ``` + function disConnectIpc(context: common.UIAbilityContext) { + if (connectid != undefined) { + context.disconnectServiceExtensionAbility(connectid) + } + } + ``` + + 源码参考:[IPC_Client.ets](IPC_Client/entry/src/main/ets/client/cnn/IPC_Client.ets); + + 接口参考:[@ohos.rpc](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ipc-kit/js-apis-rpc.md); + + [IPC与RPC通信开发指南](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/ipc-rpc-development-guideline-V5) + + + ### 3.2、客户端发送数据与服务端接收数据 + + * 3.2.1、通过Parcelable对象发送数据: + + (1).在客户端的IPC_Client.ets中的sendParcelable()中通过rpc.MessageSequence.create()创建MessageSequence对象; + ``` + let data = rpc.MessageSequence.create() + ``` + (2).通过MessageSequence.writeParcelable()将封装字符串信息的Parcelable对象写入MessageSequence对象中; + ``` + //取决于MyParcelable类如何定义,或需要序列化时准备传递什么数据类型; + //本示例中MyParcelable是以number和string为例,且服务端接收string + let parcelable = new MyParcelable(1, str); + data.writeParcelable(parcelable); + ``` + (3).通过sendData()中的rpc.RemoteObject.sendMessageRequest()将包裹待发送字符串的Parcelable对象发送到服务端进程中; + ``` + //用连接服务成功后返回的对象proxy,进行消息发送 + proxy.sendMessageRequest(code, data, reply, options) + .then((result: rpc.RequestResult) => { + if (result.errCode === 0) { + hilog.info(DOMAIN, TAG, 'sendMessageRequest got result'); + try { + let rsp = result.reply.readString() + hilog.info(DOMAIN, TAG, 'IpcClient result.' + rsp); + } catch (error) { + let e: BusinessError = error as BusinessError; + hilog.error(DOMAIN, TAG, 'rpc read exception fail, error is ' + e); + } + } else { + hilog.error(DOMAIN, TAG, 'RPCTest: sendMessageRequest failed, errCode: ' + result.errCode); + } + }).catch((e: Error) => { + hilog.error(DOMAIN, TAG, 'RPCTest: sendMessageRequest got exception: ' + e); + }).finally (() => { + hilog.info(DOMAIN, TAG, 'RPCTest: sendMessageRequest ends, reclaim parcel'); + data.reclaim(); + reply.reclaim(); + }); + ``` + + * 3.2.2、通过ArrayBuffer对象发送数据: + + (1).在客户端的IPC_Client.ets中的sendArrayBuffer()中通过rpc.MessageSequence.create()创建MessageSequence对象; + ``` + let data = rpc.MessageSequence.create() + ``` + + (2).然后将待发送字符串转为ArrayBuffer,之后通过MessageSequence.writeArrayBuffer()将ArrayBuffer对象写入MessageSequence对象中; + ``` + let buffer = new ArrayBuffer(str.length); + let Uint8View = new Uint8Array(buffer); + for (let i = 0; i < str.length; i++) { + Uint8View[i] = str.charCodeAt(i); + } + //进行校验 + data.writeInterfaceToken(proxy.getDescriptor()) + //写入ArrayBuffer + data.writeArrayBuffer(buffer, rpc.TypeCode.UINT8_ARRAY); + ``` + + (3).通过sendData()中的rpc.RemoteObject.sendMessageRequest()将包裹待发送字符串的ArrayBuffer对象发送到服务端进程中; + ``` + //用连接服务成功后返回的对象proxy,进行消息发送 + proxy.sendMessageRequest(code, data, reply, options) + .then((result: rpc.RequestResult) => { + if (result.errCode === 0) { + hilog.info(DOMAIN, TAG, 'sendMessageRequest got result'); + try { + let rsp = result.reply.readString() + hilog.info(DOMAIN, TAG, 'IpcClient result.' + rsp); + } catch (error) { + let e: BusinessError = error as BusinessError; + hilog.error(DOMAIN, TAG, 'rpc read exception fail, error is ' + e); + } + } else { + hilog.error(DOMAIN, TAG, 'RPCTest: sendMessageRequest failed, errCode: ' + result.errCode); + } + }).catch((e: Error) => { + hilog.error(DOMAIN, TAG, 'RPCTest: sendMessageRequest got exception: ' + e); + }).finally (() => { + hilog.info(DOMAIN, TAG, 'RPCTest: sendMessageRequest ends, reclaim parcel'); + data.reclaim(); + reply.reclaim(); + }); + ``` + 源码参考:[IPC_Client.ets](IPC_Client/entry/src/main/ets/client/cnn/IPC_Client.ets); + + 接口参考:[@ohos.rpc](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ipc-kit/js-apis-rpc.md); + + [IPC与RPC通信开发指南](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/ipc-rpc-development-guideline-V5); + + * 3.2.3、服务端读取数据: + + (1).创建一个ServiceExtensionAbility,并在onConnect回调中返回一个StubServer对象; + ``` + let globalStubServer: StubServer | undefined + + function getInstance(): StubServer { + if (globalStubServer == undefined) { + globalStubServer = new StubServer('serverStub_App2') + } + return globalStubServer + } + + export default class ServiceExtension extends ServiceExtensionAbility { + onCreate(want: Want) { + hilog.info(DOMAIN, TAG, 'ServiceExtensionAbility onCreate,want param:' + JSON.stringify(want) ?? ' ') + } + + onRequest(want: Want, startId: number) { + hilog.info(DOMAIN, TAG, + 'ServiceExtensionAbility onRequest,want param:' + JSON.stringify(want) ?? "+,startId:" + JSON.stringify(startId)) + } + + onConnect(want: Want): rpc.RemoteObject | Promise { + hilog.info(DOMAIN, TAG, 'ServiceExtensionAbility onConnect,want param:' + JSON.stringify(want) ?? "") + return getInstance() + } + + onDisconnect(want: Want) { + hilog.info(DOMAIN, TAG, 'ServiceExtensionAbility onDisconnect,want param::' + JSON.stringify(want)) + } + + onDestroy() { + hilog.info(DOMAIN, TAG, 'ServiceExtensionAbility onDestroy') + } + } + ``` + + (2).处理MessageRequest请求的接口封装在StubServer里面,在这里接收传递来的数据; + ``` + onRemoteMessageRequest(code: number, data: rpc.MessageSequence, reply: rpc.MessageSequence, + options: rpc.MessageOption): boolean | Promise { + hilog.info(DOMAIN, TAG, 'Client Send code:' + code) + let descriptor = this.getDescriptor() + // 进行校验 + if (descriptor != data.readInterfaceToken()) { + hilog.info(DOMAIN, TAG, 'VERIFICATION FAILED'); + return false; + } + + onHandleClientReq(code, data, reply) + return true + } + ``` + + (3).然后经过onHandleClientReq()处理接收的MessageSequence信息,通过不同的code值(Parcelable:1001,ArrayBuffer:1002),分别使用rpc.RemoteObject.readParcelable()和rpc.RemoteObject.readArrayBuffer()获取传递来的对象,通过解析该对象获得客户端传递来的字符串; + ``` + function onHandleClientReq(code: number, data: rpc.MessageSequence, reply: rpc.MessageSequence) { + hilog.info(DOMAIN, TAG, 'onHandle Client,code:' + code) + switch (code) { + //接收Parcelable对象 + case 1001: + let parcelable = new MyParcelable(0, ''); + data.readParcelable(parcelable); + dataStatus.updataParcelable(parcelable.str) + hilog.info(DOMAIN, TAG, 'read parcelable: ' + parcelable.str); + break + //接收ArrayBuffer对象 + case 1002: + let result = data.readArrayBuffer(rpc.TypeCode.UINT8_ARRAY); + let decoder = util.TextDecoder.create('utf-8'); + let stringData = decoder.decodeToString(new Uint8Array(result)); + dataStatus.updataArrayBuffer(stringData) + hilog.info(DOMAIN, TAG, 'read arraybuffer: ' + stringData); + break + default: + hilog.info(DOMAIN, TAG, 'onHandleClient-default,code: ' + 1001); + break + } + } + ``` + 源码参考:[IPC_Service.ets](IPC_Service/entry/src/main/ets/serviceextability/IPC_Service.ets); + + 接口参考:[@ohos.rpc](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ipc-kit/js-apis-rpc.md); + + [IPC与RPC通信开发指南](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/ipc-rpc-development-guideline-V5); + + +## 四、相关权限 + +由于Service Ability(服务端所在应用)只能被系统应用调用,所以IPC通信机制在单框架上不对普通应用开放,故服务端需要申请系统应用权限。 +(服务端需提供ohos-sdk-full) + +4.1、配置权限:在服务端entry下的module中配置如下权限:[module.json5](IPC_Service/entry/src/main/module.json5),参考第38-45行。 + ``` + "extensionAbilities": [ + //配置IpcServiceExtAbility能力 + { + "name": "IpcServiceExtAbility", + "srcEntry": "./ets/serviceextability/ServiceExtAbility.ets", + "type": "service", + "exported": true, + "description": "service" + } + ] + ``` + +4.2、将“4.1.配置权限”中添加的权限注释起来,然后运行工程,在设备上推送服务端hap。 + +4.3、将服务端需要的系统应用权限注册到设备: + + 4.3.1、 获取签名指纹,及获取install_list_capability.json文件 + + ![](image/fingerprint.png) + + 4.3.2、 在拉取到本地的install_list_capability.json文件中添加如下权限信息: + + + { + "bundleName": "应用包名", + "app_signature": ["4.3.1获取到的签名指纹"], + //添加系统应用权限 + "allowAppUsePrivilegeExtension": true + }, + +![](image/permission.png) + + 4.3.3、 将添加权限后的install_list_capability.json文件推送至设备原路径,并重启设备 + + ``` + 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 + ``` + + +4.4、将“4.1.配置权限”中添加的权限取消注释,然后运行工程,此时的hap具有IpcServiceExtAbility。 + +## 五、依赖 + +不涉及。 + +## 六、约束与限制 + +6.1、本示例仅支持在标准系统上运行。 + +6.2、本示例服务端要求使用ohos-sdk-full,推荐使用最新版本。[ohos-sdk-full下载链接](https://ci.openharmony.cn/workbench/cicd/dailybuild/dailylist) \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/IPC/ObjectTransfer/image/client.png b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/image/client.png new file mode 100644 index 0000000000000000000000000000000000000000..cd83e22a11627912aab634dd0acc897d3e5d3688 Binary files /dev/null and b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/image/client.png differ diff --git a/code/BasicFeature/Connectivity/IPC/ObjectTransfer/image/fingerprint.png b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/image/fingerprint.png new file mode 100644 index 0000000000000000000000000000000000000000..d90e46c037d5ddfb427b746a69f3774c0a9eeffe Binary files /dev/null and b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/image/fingerprint.png differ diff --git a/code/BasicFeature/Connectivity/IPC/ObjectTransfer/image/permission.png b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/image/permission.png new file mode 100644 index 0000000000000000000000000000000000000000..bf77e33ee1e65a2e588338f8030189e458f33ade Binary files /dev/null and b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/image/permission.png differ diff --git a/code/BasicFeature/Connectivity/IPC/ObjectTransfer/image/service.png b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/image/service.png new file mode 100644 index 0000000000000000000000000000000000000000..0cae7c7921d8de0229cabea95a6de10f7e156210 Binary files /dev/null and b/code/BasicFeature/Connectivity/IPC/ObjectTransfer/image/service.png differ