diff --git a/README_zh.md b/README_zh.md index 6c1ef82febbe1ed3a247d87a8499d3f547cbaa17..05170d94986a248586f0a75681ee4f4c17404fb7 100644 --- a/README_zh.md +++ b/README_zh.md @@ -252,7 +252,7 @@ Native Notification - + Native CommonEvent diff --git a/code/BasicFeature/Native/NdkCommonEvent/AppScope/app.json5 b/code/BasicFeature/Native/NdkCommonEvent/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c2fcf15a1e41ba5a41fc5095b62818736026071c --- /dev/null +++ b/code/BasicFeature/Native/NdkCommonEvent/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.ndkcommonevent", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/BasicFeature/Native/NdkCommonEvent/AppScope/resources/base/element/string.json b/code/BasicFeature/Native/NdkCommonEvent/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..9511361c76512c7cad91bbd3c98a79f0710df514 --- /dev/null +++ b/code/BasicFeature/Native/NdkCommonEvent/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "NdkCommonEvent" + } + ] +} diff --git a/code/BasicFeature/Native/NdkCommonEvent/AppScope/resources/base/media/app_icon.png b/code/BasicFeature/Native/NdkCommonEvent/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/code/BasicFeature/Native/NdkCommonEvent/AppScope/resources/base/media/app_icon.png differ diff --git a/code/BasicFeature/Native/NdkCommonEvent/README_zh.md b/code/BasicFeature/Native/NdkCommonEvent/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..af70f1b78efb0603f8aeccb8bd063339de3aba5c --- /dev/null +++ b/code/BasicFeature/Native/NdkCommonEvent/README_zh.md @@ -0,0 +1,146 @@ +# 公共事件的订阅/退订/发布 + +### 介绍 + +本示例使用C_API的方式实现三方应用的订阅/退订/发布公共事件的功能。具体实现了以下几点功能: + +1.通过公共事件订阅设置附加信息对象,实现了公共事件设置附加信息对象(包含但不限于创建、销毁公共事件附加信息对象、设置公共事件附加信息的int类型内容等)的功能。 + +2.通过发布公共事件属性对象,实现了公共事件属性对象(包含但不限于创建、销毁公共事件属性对象、设置公共事件包名称、事件权限、结果码、结果数据、设置公共事件附加信息等)的功能。 + +3.通过发布公共事件,实现了发布自定义公共事件、发布带有指定属性的自定义公共事件等功能。 + +4.通过发布带有指定属性的自定义公共事件,实现了查询当前公共事件是否为有序公共事件、用于订阅者结束对当前有序公共事件的处理、获取当前有序公共事件是否处于中止状态、获取当前有序公共事件是否处于中止状态、中止当前的有序公共事件、取消当前有序公共事件的中止状态、获取有序公共事件代码、获取有序公共事件的数据、设置有序公共事件的代码、设置有序公共事件的数据等功能。 + +| 主页面 | Parameters开发页面 | PublishInfo开发页面 | Publish开发页面 | Ordered开发页面 | +| :------------------------------------: | :------------------------------------: | :------------------------------------: | :------------------------------------: | :------------------------------------: | +| | | | | | + +### 使用说明 + +1. 安装编译生成的Hap包,并打开应用,可选择“Parameters Sample”、“PublishInfo Sample”、“Publish Sample”、“OrderedCommonEvent Sample”的几个选项。 +2. 点击页面中的"Parameters Sample"按钮, + - 依次点击"CreateParameters","DestroyParameters"按钮,页面将调用OH_CommonEvent_CreateParameters()和OH_CommonEvent_DestroyParameters()接口,页面弹窗显示CreateParameters Result: success和DestroyParameters Result: success结果。 + - 点击"SetIntToParameters"、"SetIntArrayToParameters"按钮,页面将调用OH_CommonEvent_SetIntToParameters()和OH_CommonEvent_SetIntArrayToParameters()接口,页面弹窗显示SetIntToParameters Result: success和SetIntArrayToParameters Result: success结果。 + - 点击"SetLongToParameters"、"SetLongArrayToParameters"按钮,页面将调用OH_CommonEvent_SetLongToParameters()和OH_CommonEvent_SetLongArrayToParameters()接口,页面弹窗显示SetLongToParameters Result: success和SetLongArrayToParameters Result: success结果。 + - 点击"SetDoubleToParameters"、"SetDoubleArrayToParameters"按钮,页面将调用OH_CommonEvent_SetDoubleToParameters()和OH_CommonEvent_SetDoubleArrayToParameters()接口,页面弹窗显示SetDoubleToParameters Result: success和SetDoubleArrayToParameters Result: success结果。 + - 点击"SetBoolToParameters"、"SetBoolArrayToParameters"按钮,页面将调用OH_CommonEvent_SetBoolToParameters()和OH_CommonEvent_SetBoolArrayToParameters()接口,页面弹窗显示SetBoolToParameters Result: success和SetBoolArrayToParameters Result: success结果。 + - 点击"SetCharToParameters"、"SetCharArrayToParameters"按钮,页面将调用OH_CommonEvent_SetCharToParameters()和OH_CommonEvent_SetCharArrayToParameters()接口,页面弹窗显示SetCharToParameters Result: success和SetCharArrayToParameters Result: success结果。 +3. 返回至应用菜单页面,点击页面中的"PublishInfo Sample"按钮, + - 依次点击"CreatePublishInfo"、"DestroyPublishInfo"按钮,页面将调用OH_CommonEvent_CreatePublishInfo()和OH_CommonEvent_DestroyPublishInfo()接口,页面弹窗显示CreatePublishInfo Result: success和DestroyPublishInfo Result: success结果。 + - 点击"SetPublishInfoBundleName"按钮,页面将调用OH_CommonEvent_SetPublishInfoBundleName()接口,页面弹窗显示SetPublishInfoBundleName Result: success结果。 + - 点击"SetPublishInfoPermissions"按钮,页面将调用OH_CommonEvent_SetPublishInfoPermissions()接口,页面弹窗显示SetPublishInfoPermissions Result: success结果。 + - 点击"SetPublishInfoCode"按钮,页面将调用OH_CommonEvent_SetPublishInfoCode()接口,页面弹窗显示SetPublishInfoCode Result: success结果。 + - 点击"SetPublishInfoData"按钮,页面将调用OH_CommonEvent_SetPublishInfoData()接口,页面弹窗显示SetPublishInfoData Result: success结果。 + - 点击"SetPublishInfoParameters"按钮,页面将调用OH_CommonEvent_SetPublishInfoParameters()接口,页面弹窗显示SetPublishInfoParameters Result: success结果。 +4. 返回至应用菜单页面,点击页面中的"Publish Sample"按钮, + - 点击"Publish"按钮,页面将调用OH_CommonEvent_Publish()接口,页面弹窗显示Publish Result: success结果。 + - 点击"PublishWithInfo"按钮,页面将调用OH_CommonEvent_PublishWithInfo()接口,页面弹窗显示PublishWithInfo Result: success结果。 +5. 返回至应用菜单页面,点击页面中的"OrderedCommonEvent Sample"按钮, + - 点击"IsOrderedCommonEvent"按钮,页面将调用OH_CommonEvent_IsOrderedCommonEvent()接口,页面弹窗显示IsOrderedCommonEvent Result: success结果。 + - 点击"FinishCommonEvent"按钮,页面将调用OH_CommonEvent_FinishCommonEvent()接口,页面弹窗显示FinishCommonEvent Result: success结果。 + - 点击"GetAbortCommonEvent"按钮,页面将调用OH_CommonEvent_GetAbortCommonEvent()接口,页面弹窗显示GetAbortCommonEvent Result: success结果。 + - 点击"AbortCommonEvent"按钮,页面将调用OH_CommonEvent_AbortCommonEvent()接口,页面弹窗显示AbortCommonEvent Result: success结果。 + - 点击"ClearAbortCommonEvent"按钮,页面将调用OH_CommonEvent_ClearAbortCommonEvent()接口,页面弹窗显示ClearAbortCommonEvent Result: success结果。 + - 点击"GetCodeFromSubscriber"按钮,页面将调用OH_CommonEvent_GetCodeFromSubscriber()接口,页面弹窗显示GetCodeFromSubscriber Result: success结果。 + - 点击"GetDataFromSubscriber"按钮,页面将调用OH_CommonEvent_GetDataFromSubscriber()接口,页面弹窗显示GetDataFromSubscriber Result: success结果。 + - 点击"SetCodeToSubscriber"按钮,页面将调用OH_CommonEvent_SetCodeToSubscriber()接口,页面弹窗显示SetCodeToSubscriber Result: success结果。 + - 点击"SetDataToSubscriber"按钮,页面将调用OH_CommonEvent_SetDataToSubscriber()接口,页面弹窗显示SetDataToSubscriber Result: success结果。 + +### 工程目录 + +```TEXT +entry/src/main/ +|---main +| |---cpp +| | |---types +| | | |---libentry +| | | | |---index.d.ts // 接口导出 +| | | | |---common.h // 共通头文件 +| | | | |---napi_init.cpp // 映射napi接口初始化 +| | | | |---orderedcommonevent.cpp // 调用orderedcommonevent接口 +| | | | |---parameters.cpp // 调用parameters接口 +| | | | |---publish.cpp // 调用publish接口 +| | | | |---publishInfo.cpp // 调用publishInfo接口 +| | | | |---CMakeLists.txt // 编译脚本 +| |---ets +| | |---entryability +| | | |---EntryAbility.ets +| | |---pages +| | | |---Index.ets // 首页 +| | | |---OrderedCommonEvent.ets // orderedcommonevent 页面 +| | | |---parameters.ets // parameters 页面 +| | | |---Publish.ets // publish 页面 +| | | |---PublishInfo.ets // publishInfo 页面 +| |---resources // 静态资源 +|---ohosTest +| |---ets +| | |---tests +| | | |---Ability.test.ets // 自动化测试用例 +``` + +### 具体实现 + +通过在IDE中创建Native C++工程,例如:在C++代码中定义对外接口为createParameters,映射C++接口CreateParameters。通过获取JS的资源对象,并转化为Native的资源对象,即可调用对外开放的Native接口。在JS侧导入"libentry.so",调用src/main/cpp/type/libentry/index.d.ts中声明的接口。 + +- Parameters对应接口实现,源代码参考:[parameters.cpp](entry/src/main/cpp/parameters.cpp),[Parameters.ets](entry/src/main/ets/pages/Parameters.ets)。 + 1. CreateParameters接口实现:通过调用OH_CommonEvent_CreateParameters()接口,创建公共事件附加信息对象,并将弹出CustomDialog返回结果信息; + 2. DestroyParameters接口实现:通过调用OH_CommonEvent_DestroyParameters()接口,销毁公共事件附加信息对象,并将弹出CustomDialog返回结果信息; + 3. SetIntToParameters接口实现:通过调用OH_CommonEvent_SetIntToParameters()接口,设置公共事件附加信息的int数组内容,并将弹出CustomDialog返回结果信息; + 4. SetIntArrayToParameters接口实现:通过调用OH_CommonEvent_SetIntArrayToParameters()接口,设置公共事件附加信息的int数组内容,并将弹出CustomDialog返回结果信息; + 5. SetDoubleToParameters接口实现:通过调用OH_CommonEvent_SetDoubleToParameters()接口,设置公共事件附加信息的double类型内容,并将弹出CustomDialog返回结果信息; + 6. SetDoubleArrayToParameters接口实现:通过调用OH_CommonEvent_SetDoubleArrayToParameters()接口,设置公共事件附加信息的double数组内容,并将弹出CustomDialog返回结果信息; + 7. SetBoolToParameters接口实现:通过调用OH_CommonEvent_SetBoolToParameters()接口,设置公共事件附加信息的布尔类型内容,并将弹出CustomDialog返回结果信息; + 8. SetBoolArrayToParameters接口实现:通过调用OH_CommonEvent_SetBoolArrayToParameters()接口,设置公共事件附加信息的布尔数组内容,并将弹出CustomDialog返回结果信息; + 9. SetCharToParameters接口实现:通过调用OH_CommonEvent_SetCharToParameters()接口,设置公共事件附加信息的字符类型内容,并将弹出CustomDialog返回结果信息; + 10. SetCharArrayToParameters接口实现:通过调用OH_CommonEvent_SetCharArrayToParameters()接口,设置公共事件附加信息的字符数组内容,并将弹出CustomDialog返回结果信息; + +- PublishInfo对应接口实现,源代码参考:[publishinfo.cpp](entry/src/main/cpp/publishinfo.cpp),[PublishInfo.ets](entry/src/main/ets/pages/PublishInfo.ets)。 + 1. CreatePublishInfo接口实现:通过调用OH_CommonEvent_CreatePublishInfo()接口,创建公共事件属性对象,并将弹出CustomDialog返回结果信息; + 2. DestroyPublishInfo接口实现:通过调用OH_CommonEvent_DestroyPublishInfo()接口,销毁公共事件属性对象,并将弹出CustomDialog返回结果信息; + 3. SetPublishInfoBundleName接口实现:通过调用OH_CommonEvent_SetPublishInfoBundleName()接口,设置公共事件包名称,并将弹出CustomDialog返回结果信息; + 4. SetPublishInfoPermissions接口实现:通过调用OH_CommonEvent_SetPublishInfoPermissions()接口,设置公共事件权限,并将弹出CustomDialog返回结果信息; + 5. SetPublishInfoCode接口实现:通过调用OH_CommonEvent_SetPublishInfoCode()接口,设置公共事件结果码,并将弹出CustomDialog返回结果信息; + 6. SetPublishInfoData接口实现:通过调用OH_CommonEvent_SetPublishInfoData()接口,设置公共事件结果数据,并将弹出CustomDialog返回结果信息; + 7. SetPublishInfoParameters接口实现:通过调用OH_CommonEvent_SetPublishInfoParameters()接口,设置公共事件附加信息,并将弹出CustomDialog返回结果信息; + +- Publish对应接口实现,源代码参考:[publish.cpp](entry/src/main/cpp/publish.cpp),[Publish.ets](entry/src/main/ets/pages/Publish.ets)。 + 1. CreatePublishInfo接口实现:通过调用OH_CommonEvent_Publish()接口,发布自定义公共事件,并将弹出CustomDialog返回结果信息; + 2. DestroyPublishInfo接口实现:通过调用OH_CommonEvent_PublishWithInfo()接口,发布带有指定属性的自定义公共事件,并将弹出CustomDialog返回结果信息; + +- OrderedCommonEvent对应接口实现,源代码参考:[orderedcommonevent.cpp](entry/src/main/cpp/orderedcommonevent.cpp),[OrderedCommonEvent.ets](entry/src/main/ets/pages/OrderedCommonEvent.ets)。 + 1. IsOrderedCommonEvent接口实现:通过调用OH_CommonEvent_IsOrderedCommonEvent()接口,查询当前公共事件是否为有序公共事件,并将弹出CustomDialog返回结果信息; + 2. FinishCommonEvent接口实现:通过调用OH_CommonEvent_FinishCommonEvent()接口,用于订阅者结束对当前有序公共事件的处理,并将弹出CustomDialog返回结果信息; + 3. GetAbortCommonEvent接口实现:通过调用OH_CommonEvent_GetAbortCommonEvent()接口,获取当前有序公共事件是否处于中止状态,并将弹出CustomDialog返回结果信息; + 4. AbortCommonEvent接口实现:通过调用OH_CommonEvent_AbortCommonEvent()接口,中止当前的有序公共事件,并将弹出CustomDialog返回结果信息; + 5. ClearAbortCommonEvent接口实现:通过调用OH_CommonEvent_ClearAbortCommonEvent()接口,取消当前有序公共事件的中止状态,并将弹出CustomDialog返回结果信息; + 6. GetCodeFromSubscriber接口实现:通过调用OH_CommonEvent_GetCodeFromSubscriber()接口,获取有序公共事件代码,并将弹出CustomDialog返回结果信息; + 7. GetDataFromSubscriber接口实现:通过调用OH_CommonEvent_GetDataFromSubscriber()接口,获取有序公共事件的数据,并将弹出CustomDialog返回结果信息; + 8. SetCodeToSubscriber接口实现:通过调用OH_CommonEvent_SetCodeToSubscriber()接口,设置有序公共事件的代码,并将弹出CustomDialog返回结果信息; + 9. SetDataToSubscriber接口实现:通过调用OH_CommonEvent_SetDataToSubscriber()接口,设置有序公共事件的数据,并将弹出CustomDialog返回结果信息; + +### 相关权限 + +不涉及 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1. 本示例仅支持标准系统上运行,支持设备:RK3568; +2. 本示例为Stage模型,支持API16版本SDK,版本号:5.1.0.48; +3. 本示例需要使用DevEco Studio NEXT Release(5.0.5.315)及以上版本才可编译运行; + +### 下载 + +如需单独下载本工程,执行如下命令: + +```bash +git init +git config core.sparsecheckout true +echo code/BasicFeature/Native/NdkNotification/ > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +``` diff --git a/code/BasicFeature/Native/NdkCommonEvent/build-profile.json5 b/code/BasicFeature/Native/NdkCommonEvent/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..87246d1513574bd6ca7c5c63a16333b8738321e0 --- /dev/null +++ b/code/BasicFeature/Native/NdkCommonEvent/build-profile.json5 @@ -0,0 +1,57 @@ +/* + * 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": { + "products": [ + { + "name": "default", + "signingConfig": "default", + "compileSdkVersion": 16, + "compatibleSdkVersion": 16, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug" + }, + { + "name": "release" + } + ], + + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} diff --git a/code/BasicFeature/Native/NdkCommonEvent/entry/build-profile.json5 b/code/BasicFeature/Native/NdkCommonEvent/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..65165fa66ffa626a070f75565bf63639ec795d69 --- /dev/null +++ b/code/BasicFeature/Native/NdkCommonEvent/entry/build-profile.json5 @@ -0,0 +1,35 @@ +/* + * 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": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + "abiFilters": ["arm64-v8a", "armeabi-v7a", "x86_64"] + } + }, + "targets": [ + { + "name": "default", + "runtimeOS": "OpenHarmony" + }, + { + "name": "ohosTest", + } + ] +} diff --git a/code/BasicFeature/Native/NdkCommonEvent/entry/hvigorfile.ts b/code/BasicFeature/Native/NdkCommonEvent/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/BasicFeature/Native/NdkCommonEvent/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/Native/NdkCommonEvent/entry/oh-package.json5 b/code/BasicFeature/Native/NdkCommonEvent/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- /dev/null +++ b/code/BasicFeature/Native/NdkCommonEvent/entry/oh-package.json5 @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libentry.so": "file:./src/main/cpp/types/libentry" + } +} \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/cpp/CMakeLists.txt b/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..f7cc682b8f0f7ab2fabb004235217c540cae03c7 --- /dev/null +++ b/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,15 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(NdkCommonEvent) + +set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) + +if(DEFINED PACKAGE_FIND_FILE) + include(${PACKAGE_FIND_FILE}) +endif() + +include_directories(${NATIVERENDER_ROOT_PATH} + ${NATIVERENDER_ROOT_PATH}/include) + +add_library(entry SHARED napi_init.cpp) +target_link_libraries(entry PUBLIC libace_napi.z.so libhilog_ndk.z.so libohcommonevent.so) \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/cpp/common.h b/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/cpp/common.h new file mode 100644 index 0000000000000000000000000000000000000000..991d6dfc8f4d75493e801ffbbc1d5baf9a2c1ea8 --- /dev/null +++ b/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/cpp/common.h @@ -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. + */ + +#ifndef NDKCOMMONEVENT_SAMPLE_COMMON_H +#define NDKCOMMONEVENT_SAMPLE_COMMON_H + +#include +#include +#include +#include "BasicServicesKit/oh_commonevent.h" +#include "BasicServicesKit/oh_commonevent_support.h" + +#define PARAM_NEGATIVE_1 (-1) +#define PARAM_0 0 +#define PARAM_1 1 +#define PARAM_4 4 +#define PARAM_6 6 +#define SUCCESS 0 +#define INVALID_PARAM 401 +#define BUNDLE_NAME "com.samples.ndkcommonevent" +#define COMMON_EVENT_TEST "event_test" +#define KEY_INT "int" +#define KEY_INT_ARRAY "int_array" +#define KEY_LONG "long" +#define KEY_LONG_ARRAY "long_array" +#define KEY_DOUBLE "double" +#define KEY_DOUBLE_ARRAY "double_array" +#define KEY_BOOL "bool" +#define KEY_BOOL_ARRAY "bool_array" +#define KEY_CHAR "char" +#define KEY_CHAR_ARRAY "char_array" + +inline napi_value NAPI_SUCCESS(napi_env env) +{ + napi_value result = nullptr; + napi_create_int32(env, SUCCESS, &result); + return result; +} + +inline napi_value NAPI_FAILTURE(napi_env env) +{ + napi_value result = nullptr; + napi_create_int32(env, PARAM_NEGATIVE_1, &result); + return result; +} + +#endif // NDKCOMMONEVENT_SAMPLE_COMMON_H \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/cpp/napi_init.cpp b/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/cpp/napi_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9c1bc256da5d35e849c40ba8c4230ca04580bf88 --- /dev/null +++ b/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/cpp/napi_init.cpp @@ -0,0 +1,102 @@ +/* + * 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. + */ + +#include "napi/native_api.h" +#include "parameters.cpp" +#include "publishinfo.cpp" +#include "publish.cpp" +#include "orderedcommonevent.cpp" + +EXTERN_C_START +static napi_property_descriptor g_desc[] = { + {"createParameters", nullptr, CreateParameters, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"destroyParameters", nullptr, DestroyParameters, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"setIntToParameters", nullptr, SetIntToParameters, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"setIntArrayToParameters", nullptr, SetIntArrayToParameters, nullptr, nullptr, nullptr, napi_default, + nullptr}, + {"setLongToParameters", nullptr, SetLongToParameters, nullptr, nullptr, nullptr, napi_default, + nullptr}, + {"setLongArrayToParameters", nullptr, SetLongArrayToParameters, nullptr, nullptr, nullptr, napi_default, + nullptr}, + {"setBoolToParameters", nullptr, SetBoolToParameters, nullptr, nullptr, nullptr, napi_default, + nullptr}, + {"setBoolArrayToParameters", nullptr, SetBoolArrayToParameters, nullptr, nullptr, nullptr, napi_default, + nullptr}, + {"setDoubleToParameters", nullptr, SetDoubleToParameters, nullptr, nullptr, nullptr, napi_default, + nullptr}, + {"setDoubleArrayToParameters", nullptr, SetDoubleArrayToParameters, nullptr, nullptr, nullptr, napi_default, + nullptr}, + {"setCharToParameters", nullptr, SetCharToParameters, nullptr, nullptr, nullptr, napi_default, + nullptr}, + {"setCharArrayToParameters", nullptr, SetCharArrayToParameters, nullptr, nullptr, nullptr, napi_default, + nullptr}, + {"createPublishInfo", nullptr, CreatePublishInfo, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"destroyPublishInfo", nullptr, DestroyPublishInfo, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"setPublishInfoBundleName", nullptr, SetPublishInfoBundleName, nullptr, nullptr, nullptr, napi_default, + nullptr}, + {"setPublishInfoPermissions", nullptr, SetPublishInfoPermissions, nullptr, nullptr, nullptr, napi_default, + nullptr}, + {"setPublishInfoCode", nullptr, SetPublishInfoCode, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getSetPublishInfoCode", nullptr, GetSetPublishInfoCode, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"setPublishInfoData", nullptr, SetPublishInfoData, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getSetPublishInfoData", nullptr, GetSetPublishInfoData, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"setPublishInfoParameters", nullptr, SetPublishInfoParameters, nullptr, nullptr, nullptr, napi_default, + nullptr}, + {"getSetPublishInfoParameters", nullptr, GetSetPublishInfoParameters, nullptr, nullptr, nullptr, napi_default, + nullptr}, + {"isOrderedCommonEvent", nullptr, IsOrderedCommonEvent, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getIsOrderedCommonEvent", nullptr, GetIsOrderedCommonEvent, nullptr, nullptr, nullptr, napi_default, + nullptr}, + {"finishCommonEvent", nullptr, FinishCommonEvent, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getFinishCommonEvent", nullptr, GetFinishCommonEvent, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getAbortCommonEvent", nullptr, GetAbortCommonEvent, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getGetAbortCommonEvent", nullptr, GetGetAbortCommonEvent, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"abortCommonEvent", nullptr, AbortCommonEvent, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getAbortCommonEvent2", nullptr, GetAbortCommonEvent2, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"clearAbortCommonEvent", nullptr, ClearAbortCommonEvent, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getClearAbortCommonEvent", nullptr, GetClearAbortCommonEvent, nullptr, nullptr, nullptr, napi_default, + nullptr}, + {"subscriberCommonEvent", nullptr, SubscriberCommonEvent, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getGetCodeFromSubscriber", nullptr, GetGetCodeFromSubscriber, nullptr, nullptr, nullptr, napi_default, + nullptr}, + {"getSetCodeToSubscriber", nullptr, GetSetCodeToSubscriber, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getGetDataFromSubscriber", nullptr, GetGetDataFromSubscriber, nullptr, nullptr, nullptr, napi_default, + nullptr}, + {"getSetDataToSubscriber", nullptr, GetSetDataToSubscriber, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"publish", nullptr, Publish, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"publishWithInfo", nullptr, PublishWithInfo, nullptr, nullptr, nullptr, napi_default, nullptr} +}; + +static napi_value Init(napi_env env, napi_value exports) +{ + napi_define_properties(env, exports, sizeof(g_desc) / sizeof(g_desc[0]), g_desc); + return exports; +} +EXTERN_C_END + +static napi_module entry = { + .nm_version = 1, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_register_func = Init, + .nm_modname = "entry", + .nm_priv = ((void*)0), + .reserved = { 0 }, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) +{ + napi_module_register(&entry); +} \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/cpp/orderedcommonevent.cpp b/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/cpp/orderedcommonevent.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5096325c9232198b05c6db29224780d609416047 --- /dev/null +++ b/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/cpp/orderedcommonevent.cpp @@ -0,0 +1,409 @@ +/* + * 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. + */ + +#include "napi/native_api.h" +#include "hilog/log.h" +#include "BasicServicesKit/oh_commonevent.h" +#include "common.h" + +static bool g_isOrderedCommonEvent = false; +static bool g_isAbort = false; +static bool g_isGetAbort = false; +static bool g_isClearAborted = false; +static bool g_isFinished = false; +static CommonEvent_Subscriber* g_subscriber = nullptr; +static CommonEvent_SubscribeInfo* g_subscribeInfo = nullptr; +static CommonEvent_PublishInfo* g_publishInfo = nullptr; + +void IsOrderedCommonEventCallback(const CommonEvent_RcvData *data) +{ + if (g_subscriber != nullptr) { + g_isOrderedCommonEvent = OH_CommonEvent_IsOrderedCommonEvent(g_subscriber); + } else { + g_isOrderedCommonEvent = false; + } +} + +static napi_value IsOrderedCommonEvent(napi_env env, napi_callback_info info) +{ + const char* events[] = {COMMON_EVENT_TEST}; + int32_t eventsNum = sizeof(events) / sizeof(char*); + g_subscribeInfo = OH_CommonEvent_CreateSubscribeInfo(events, eventsNum); + if (g_subscribeInfo == nullptr) { + return NAPI_FAILTURE(env); + } + g_subscriber = OH_CommonEvent_CreateSubscriber(g_subscribeInfo, IsOrderedCommonEventCallback); + if (g_subscriber == nullptr) { + return NAPI_FAILTURE(env); + } + if (OH_CommonEvent_Subscribe(g_subscriber) != COMMONEVENT_ERR_OK) { + return NAPI_FAILTURE(env); + } + bool ordered = true; + CommonEvent_PublishInfo* publishInfo = OH_CommonEvent_CreatePublishInfo(ordered); + if (publishInfo != nullptr) { + OH_CommonEvent_PublishWithInfo(COMMON_EVENT_TEST, publishInfo); + OH_CommonEvent_DestroyPublishInfo(publishInfo); + publishInfo = nullptr; + } + return NAPI_SUCCESS(env); +} + +static napi_value GetIsOrderedCommonEvent(napi_env env, napi_callback_info info) +{ + if (g_subscriber != nullptr) { + OH_CommonEvent_UnSubscribe(g_subscriber); + OH_CommonEvent_DestroySubscriber(g_subscriber); + g_subscriber = nullptr; + } + if (g_subscribeInfo != nullptr) { + OH_CommonEvent_DestroySubscribeInfo(g_subscribeInfo); + g_subscribeInfo = nullptr; + } + if (!g_isOrderedCommonEvent) { + return NAPI_FAILTURE(env); + } + return NAPI_SUCCESS(env); +} + +void FinishCommonEventCallback(const CommonEvent_RcvData *data) +{ + if (g_subscriber != nullptr) { + g_isFinished = OH_CommonEvent_FinishCommonEvent(g_subscriber); + } else { + g_isFinished = false; + } +} + +static napi_value FinishCommonEvent(napi_env env, napi_callback_info info) +{ + const char* events[] = {COMMON_EVENT_TEST}; + int32_t eventsNum = sizeof(events) / sizeof(char*); + g_subscribeInfo = OH_CommonEvent_CreateSubscribeInfo(events, eventsNum); + if (g_subscribeInfo == nullptr) { + return NAPI_FAILTURE(env); + } + g_subscriber = OH_CommonEvent_CreateSubscriber(g_subscribeInfo, FinishCommonEventCallback); + if (g_subscriber == nullptr) { + return NAPI_FAILTURE(env); + } + if (OH_CommonEvent_Subscribe(g_subscriber) != COMMONEVENT_ERR_OK) { + return NAPI_FAILTURE(env); + } + bool ordered = true; + CommonEvent_PublishInfo* publishInfo = OH_CommonEvent_CreatePublishInfo(ordered); + if (publishInfo != nullptr) { + OH_CommonEvent_PublishWithInfo(COMMON_EVENT_TEST, publishInfo); + OH_CommonEvent_DestroyPublishInfo(publishInfo); + publishInfo = nullptr; + } + return NAPI_SUCCESS(env); +} + +static napi_value GetFinishCommonEvent(napi_env env, napi_callback_info info) +{ + if (g_subscriber != nullptr) { + OH_CommonEvent_UnSubscribe(g_subscriber); + OH_CommonEvent_DestroySubscriber(g_subscriber); + g_subscriber = nullptr; + } + if (g_subscribeInfo != nullptr) { + OH_CommonEvent_DestroySubscribeInfo(g_subscribeInfo); + g_subscribeInfo = nullptr; + } + if (!g_isFinished) { + return NAPI_FAILTURE(env); + } + return NAPI_SUCCESS(env); +} + +void GetAbortCommonEventCallback(const CommonEvent_RcvData *data) +{ + if (g_subscriber != nullptr) { + if (OH_CommonEvent_AbortCommonEvent(g_subscriber)) { + g_isGetAbort = OH_CommonEvent_GetAbortCommonEvent(g_subscriber); + } + } else { + g_isGetAbort = false; + } +} + +static napi_value GetAbortCommonEvent(napi_env env, napi_callback_info info) +{ + const char* events[] = {COMMON_EVENT_TEST}; + int32_t eventsNum = sizeof(events) / sizeof(char*); + g_subscribeInfo = OH_CommonEvent_CreateSubscribeInfo(events, eventsNum); + if (g_subscribeInfo == nullptr) { + return NAPI_FAILTURE(env); + } + g_subscriber = OH_CommonEvent_CreateSubscriber(g_subscribeInfo, GetAbortCommonEventCallback); + if (g_subscriber == nullptr) { + return NAPI_FAILTURE(env); + } + if (OH_CommonEvent_Subscribe(g_subscriber) != COMMONEVENT_ERR_OK) { + return NAPI_FAILTURE(env); + } + bool ordered = true; + CommonEvent_PublishInfo* publishInfo = OH_CommonEvent_CreatePublishInfo(ordered); + if (publishInfo != nullptr) { + OH_CommonEvent_PublishWithInfo(COMMON_EVENT_TEST, publishInfo); + OH_CommonEvent_DestroyPublishInfo(publishInfo); + publishInfo = nullptr; + } + return NAPI_SUCCESS(env); +} + +static napi_value GetGetAbortCommonEvent(napi_env env, napi_callback_info info) +{ + if (g_subscriber != nullptr) { + OH_CommonEvent_UnSubscribe(g_subscriber); + OH_CommonEvent_DestroySubscriber(g_subscriber); + g_subscriber = nullptr; + } + if (g_subscribeInfo != nullptr) { + OH_CommonEvent_DestroySubscribeInfo(g_subscribeInfo); + g_subscribeInfo = nullptr; + } + if (!g_isGetAbort) { + return NAPI_FAILTURE(env); + } + return NAPI_SUCCESS(env); +} + +void AbortCommonEventCallback(const CommonEvent_RcvData *data) +{ + if (g_subscriber != nullptr) { + g_isAbort = OH_CommonEvent_AbortCommonEvent(g_subscriber); + } else { + g_isAbort = false; + } +} + +static napi_value AbortCommonEvent(napi_env env, napi_callback_info info) +{ + const char* events[] = {COMMON_EVENT_TEST}; + int32_t eventsNum = sizeof(events) / sizeof(char*); + g_subscribeInfo = OH_CommonEvent_CreateSubscribeInfo(events, eventsNum); + if (g_subscribeInfo == nullptr) { + return NAPI_FAILTURE(env); + } + g_subscriber = OH_CommonEvent_CreateSubscriber(g_subscribeInfo, AbortCommonEventCallback); + if (g_subscriber == nullptr) { + return NAPI_FAILTURE(env); + } + if (OH_CommonEvent_Subscribe(g_subscriber) != COMMONEVENT_ERR_OK) { + return NAPI_FAILTURE(env); + } + bool ordered = true; + CommonEvent_PublishInfo* publishInfo = OH_CommonEvent_CreatePublishInfo(ordered); + if (publishInfo != nullptr) { + OH_CommonEvent_PublishWithInfo(COMMON_EVENT_TEST, publishInfo); + OH_CommonEvent_DestroyPublishInfo(publishInfo); + publishInfo = nullptr; + } + return NAPI_SUCCESS(env); +} + +static napi_value GetAbortCommonEvent2(napi_env env, napi_callback_info info) +{ + if (g_subscriber != nullptr) { + OH_CommonEvent_UnSubscribe(g_subscriber); + OH_CommonEvent_DestroySubscriber(g_subscriber); + g_subscriber = nullptr; + } + if (g_subscribeInfo != nullptr) { + OH_CommonEvent_DestroySubscribeInfo(g_subscribeInfo); + g_subscribeInfo = nullptr; + } + if (!g_isAbort) { + return NAPI_FAILTURE(env); + } + return NAPI_SUCCESS(env); +} + +void ClearAbortCommonEventCallback(const CommonEvent_RcvData *data) +{ + if (g_subscriber != nullptr) { + g_isAbort = OH_CommonEvent_AbortCommonEvent(g_subscriber); + g_isClearAborted = OH_CommonEvent_ClearAbortCommonEvent(g_subscriber); + } else { + g_isClearAborted = false; + } +} + +static napi_value ClearAbortCommonEvent(napi_env env, napi_callback_info info) +{ + const char* events[] = {COMMON_EVENT_TEST}; + int32_t eventsNum = sizeof(events) / sizeof(char*); + g_subscribeInfo = OH_CommonEvent_CreateSubscribeInfo(events, eventsNum); + if (g_subscribeInfo == nullptr) { + return NAPI_FAILTURE(env); + } + g_subscriber = OH_CommonEvent_CreateSubscriber(g_subscribeInfo, ClearAbortCommonEventCallback); + if (g_subscriber == nullptr) { + return NAPI_FAILTURE(env); + } + if (OH_CommonEvent_Subscribe(g_subscriber) != COMMONEVENT_ERR_OK) { + return NAPI_FAILTURE(env); + } + bool ordered = true; + CommonEvent_PublishInfo* publishInfo = OH_CommonEvent_CreatePublishInfo(ordered); + if (publishInfo != nullptr) { + OH_CommonEvent_PublishWithInfo(COMMON_EVENT_TEST, publishInfo); + OH_CommonEvent_DestroyPublishInfo(publishInfo); + publishInfo = nullptr; + } + return NAPI_SUCCESS(env); +} + +static napi_value GetClearAbortCommonEvent(napi_env env, napi_callback_info info) +{ + if (g_subscriber != nullptr) { + OH_CommonEvent_UnSubscribe(g_subscriber); + OH_CommonEvent_DestroySubscriber(g_subscriber); + g_subscriber = nullptr; + } + if (g_subscribeInfo != nullptr) { + OH_CommonEvent_DestroySubscribeInfo(g_subscribeInfo); + g_subscribeInfo = nullptr; + } + if (!g_isClearAborted) { + return NAPI_FAILTURE(env); + } + return NAPI_SUCCESS(env); +} + +void SubscriberCommonEventCallback(const CommonEvent_RcvData *data) +{ +} + +static napi_value SubscriberCommonEvent(napi_env env, napi_callback_info info) +{ + const char* events[] = {COMMON_EVENT_TEST}; + int32_t eventsNum = sizeof(events) / sizeof(char*); + g_subscribeInfo = OH_CommonEvent_CreateSubscribeInfo(events, eventsNum); + if (g_subscribeInfo == nullptr) { + return NAPI_FAILTURE(env); + } + g_subscriber = OH_CommonEvent_CreateSubscriber(g_subscribeInfo, SubscriberCommonEventCallback); + if (g_subscriber == nullptr) { + return NAPI_FAILTURE(env); + } + if (OH_CommonEvent_Subscribe(g_subscriber) != COMMONEVENT_ERR_OK) { + return NAPI_FAILTURE(env); + } + bool ordered = true; + CommonEvent_PublishInfo* publishInfo = OH_CommonEvent_CreatePublishInfo(ordered); + if (publishInfo != nullptr) { + OH_CommonEvent_PublishWithInfo(COMMON_EVENT_TEST, publishInfo); + OH_CommonEvent_DestroyPublishInfo(publishInfo); + publishInfo = nullptr; + } + return NAPI_SUCCESS(env); +} + +static napi_value GetGetCodeFromSubscriber(napi_env env, napi_callback_info info) +{ + if (g_subscriber != nullptr) { + int32_t code = PARAM_NEGATIVE_1; + bool ret = OH_CommonEvent_SetCodeToSubscriber(g_subscriber, code); + if (!ret) { + return NAPI_FAILTURE(env); + } + int32_t retCode = OH_CommonEvent_GetCodeFromSubscriber(g_subscriber); + if (retCode != code) { + return NAPI_FAILTURE(env); + } + OH_CommonEvent_UnSubscribe(g_subscriber); + OH_CommonEvent_DestroySubscriber(g_subscriber); + g_subscriber = nullptr; + } + if (g_subscribeInfo != nullptr) { + OH_CommonEvent_DestroySubscribeInfo(g_subscribeInfo); + g_subscribeInfo = nullptr; + } + return NAPI_SUCCESS(env); +} + +static napi_value GetSetCodeToSubscriber(napi_env env, napi_callback_info info) +{ + if (g_subscriber != nullptr) { + int32_t code = PARAM_1; + bool ret = OH_CommonEvent_SetCodeToSubscriber(g_subscriber, code); + if (!ret) { + return NAPI_FAILTURE(env); + } + int32_t retCode = OH_CommonEvent_GetCodeFromSubscriber(g_subscriber); + if (retCode != code) { + return NAPI_FAILTURE(env); + } + OH_CommonEvent_UnSubscribe(g_subscriber); + OH_CommonEvent_DestroySubscriber(g_subscriber); + g_subscriber = nullptr; + } + if (g_subscribeInfo != nullptr) { + OH_CommonEvent_DestroySubscribeInfo(g_subscribeInfo); + g_subscribeInfo = nullptr; + } + return NAPI_SUCCESS(env); +} + +static napi_value GetGetDataFromSubscriber(napi_env env, napi_callback_info info) +{ + if (g_subscriber != nullptr) { + const char* data = "data"; + size_t length = PARAM_4; + bool ret = OH_CommonEvent_SetDataToSubscriber(g_subscriber, data, length); + if (!ret) { + return NAPI_FAILTURE(env); + } + const char* retData = (char *)OH_CommonEvent_GetDataFromSubscriber(g_subscriber); + if (retData == nullptr || strlen(retData) != length) { + return NAPI_FAILTURE(env); + } + OH_CommonEvent_UnSubscribe(g_subscriber); + OH_CommonEvent_DestroySubscriber(g_subscriber); + g_subscriber = nullptr; + } + if (g_subscribeInfo != nullptr) { + OH_CommonEvent_DestroySubscribeInfo(g_subscribeInfo); + g_subscribeInfo = nullptr; + } + return NAPI_SUCCESS(env); +} + +static napi_value GetSetDataToSubscriber(napi_env env, napi_callback_info info) +{ + if (g_subscriber != nullptr) { + const char* data = "data"; + size_t length = PARAM_1; + bool ret = OH_CommonEvent_SetDataToSubscriber(g_subscriber, data, length); + if (!ret) { + return NAPI_FAILTURE(env); + } + const char* retData = (char *)OH_CommonEvent_GetDataFromSubscriber(g_subscriber); + if (retData == nullptr || strlen(retData) != length) { + return NAPI_FAILTURE(env); + } + OH_CommonEvent_UnSubscribe(g_subscriber); + OH_CommonEvent_DestroySubscriber(g_subscriber); + g_subscriber = nullptr; + } + if (g_subscribeInfo != nullptr) { + OH_CommonEvent_DestroySubscribeInfo(g_subscribeInfo); + g_subscribeInfo = nullptr; + } + return NAPI_SUCCESS(env); +} \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/cpp/parameters.cpp b/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/cpp/parameters.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8525fe335b75380f4e88998b1099512b67761cc2 --- /dev/null +++ b/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/cpp/parameters.cpp @@ -0,0 +1,239 @@ +/* + * 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. + */ + +#include "napi/native_api.h" +#include "hilog/log.h" +#include "BasicServicesKit/oh_commonevent.h" +#include "common.h" + +static CommonEvent_Parameters* g_parameters = nullptr; +static napi_value CreateParameters(napi_env env, napi_callback_info info) +{ + g_parameters = OH_CommonEvent_CreateParameters(); + if (g_parameters == nullptr) { + return NAPI_FAILTURE(env); + } + return NAPI_SUCCESS(env); +} + +static napi_value DestroyParameters(napi_env env, napi_callback_info info) +{ + if (g_parameters != nullptr) { + OH_CommonEvent_DestroyParameters(g_parameters); + g_parameters = nullptr; + } + return NAPI_SUCCESS(env); +} + +static napi_value SetIntToParameters(napi_env env, napi_callback_info info) +{ + auto parameters = OH_CommonEvent_CreateParameters(); + if (parameters != nullptr) { + int value = PARAM_1; + if (OH_CommonEvent_SetIntToParameters(parameters, KEY_INT, value) != COMMONEVENT_ERR_OK) { + return NAPI_FAILTURE(env); + } + if (OH_CommonEvent_GetIntFromParameters(parameters, KEY_INT, PARAM_0) != PARAM_1) { + return NAPI_FAILTURE(env); + } + OH_CommonEvent_DestroyParameters(parameters); + parameters = nullptr; + } else { + return NAPI_FAILTURE(env); + } + return NAPI_SUCCESS(env); +} + +static napi_value SetIntArrayToParameters(napi_env env, napi_callback_info info) +{ + auto parameters = OH_CommonEvent_CreateParameters(); + if (parameters != nullptr) { + int value[] = {PARAM_1, PARAM_4, PARAM_6}; + size_t num = sizeof(value) / sizeof(int); + if (OH_CommonEvent_SetIntArrayToParameters(parameters, KEY_INT_ARRAY, value, num) != COMMONEVENT_ERR_OK) { + return NAPI_FAILTURE(env); + } + int* ptr = nullptr; + if (OH_CommonEvent_GetIntArrayFromParameters(parameters, KEY_INT_ARRAY, &ptr) != num) { + return NAPI_FAILTURE(env); + } + OH_CommonEvent_DestroyParameters(parameters); + parameters = nullptr; + } else { + return NAPI_FAILTURE(env); + } + return NAPI_SUCCESS(env); +} + +static napi_value SetLongToParameters(napi_env env, napi_callback_info info) +{ + auto parameters = OH_CommonEvent_CreateParameters(); + if (parameters != nullptr) { + long value = PARAM_1; + if (OH_CommonEvent_SetLongToParameters(parameters, KEY_LONG, value) != COMMONEVENT_ERR_OK) { + return NAPI_FAILTURE(env); + } + if (OH_CommonEvent_GetLongFromParameters(parameters, KEY_LONG, PARAM_0) != PARAM_1) { + return NAPI_FAILTURE(env); + } + OH_CommonEvent_DestroyParameters(parameters); + parameters = nullptr; + } else { + return NAPI_FAILTURE(env); + } + return NAPI_SUCCESS(env); +} + +static napi_value SetLongArrayToParameters(napi_env env, napi_callback_info info) +{ + auto parameters = OH_CommonEvent_CreateParameters(); + if (parameters != nullptr) { + long value[] = {PARAM_1, PARAM_4, PARAM_6}; + size_t num = sizeof(value) / sizeof(long); + if (OH_CommonEvent_SetLongArrayToParameters(parameters, KEY_LONG_ARRAY, value, num) != COMMONEVENT_ERR_OK) { + return NAPI_FAILTURE(env); + } + long* ptr = nullptr; + if (OH_CommonEvent_GetLongArrayFromParameters(parameters, KEY_LONG_ARRAY, &ptr) != num) { + return NAPI_FAILTURE(env); + } + OH_CommonEvent_DestroyParameters(parameters); + parameters = nullptr; + } else { + return NAPI_FAILTURE(env); + } + return NAPI_SUCCESS(env); +} + +static napi_value SetDoubleToParameters(napi_env env, napi_callback_info info) +{ + auto parameters = OH_CommonEvent_CreateParameters(); + if (parameters != nullptr) { + double value = PARAM_1; + if (OH_CommonEvent_SetDoubleToParameters(parameters, KEY_DOUBLE, value) != COMMONEVENT_ERR_OK) { + return NAPI_FAILTURE(env); + } + if (OH_CommonEvent_GetDoubleFromParameters(parameters, KEY_DOUBLE, PARAM_0) != PARAM_1) { + return NAPI_FAILTURE(env); + } + OH_CommonEvent_DestroyParameters(parameters); + parameters = nullptr; + } else { + return NAPI_FAILTURE(env); + } + return NAPI_SUCCESS(env); +} + +static napi_value SetDoubleArrayToParameters(napi_env env, napi_callback_info info) +{ + auto parameters = OH_CommonEvent_CreateParameters(); + if (parameters != nullptr) { + double value[] = {PARAM_1, PARAM_4, PARAM_6}; + size_t num = sizeof(value) / sizeof(double); + if (OH_CommonEvent_SetDoubleArrayToParameters(parameters, KEY_DOUBLE_ARRAY, value, num) != + COMMONEVENT_ERR_OK) { + return NAPI_FAILTURE(env); + } + double* ptr = nullptr; + if (OH_CommonEvent_GetDoubleArrayFromParameters(parameters, KEY_DOUBLE_ARRAY, &ptr) != num) { + return NAPI_FAILTURE(env); + } + OH_CommonEvent_DestroyParameters(parameters); + parameters = nullptr; + } else { + return NAPI_FAILTURE(env); + } + return NAPI_SUCCESS(env); +} + +static napi_value SetBoolToParameters(napi_env env, napi_callback_info info) +{ + auto parameters = OH_CommonEvent_CreateParameters(); + if (parameters != nullptr) { + bool value = true; + if (OH_CommonEvent_SetBoolToParameters(parameters, KEY_BOOL, value) != COMMONEVENT_ERR_OK) { + return NAPI_FAILTURE(env); + } + if (OH_CommonEvent_GetBoolFromParameters(parameters, KEY_BOOL, false) != true) { + return NAPI_FAILTURE(env); + } + OH_CommonEvent_DestroyParameters(parameters); + parameters = nullptr; + } else { + return NAPI_FAILTURE(env); + } + return NAPI_SUCCESS(env); +} + +static napi_value SetBoolArrayToParameters(napi_env env, napi_callback_info info) +{ + auto parameters = OH_CommonEvent_CreateParameters(); + if (parameters != nullptr) { + bool value[] = {true, false, true}; + size_t num = sizeof(value) / sizeof(bool); + if (OH_CommonEvent_SetBoolArrayToParameters(parameters, KEY_BOOL_ARRAY, value, num) != COMMONEVENT_ERR_OK) { + return NAPI_FAILTURE(env); + } + bool* ptr = nullptr; + if (OH_CommonEvent_GetBoolArrayFromParameters(parameters, KEY_BOOL_ARRAY, &ptr) != num) { + return NAPI_FAILTURE(env); + } + OH_CommonEvent_DestroyParameters(parameters); + parameters = nullptr; + } else { + return NAPI_FAILTURE(env); + } + return NAPI_SUCCESS(env); +} + +static napi_value SetCharToParameters(napi_env env, napi_callback_info info) +{ + auto parameters = OH_CommonEvent_CreateParameters(); + if (parameters != nullptr) { + char value = 'a'; + if (OH_CommonEvent_SetCharToParameters(parameters, KEY_CHAR, value) != COMMONEVENT_ERR_OK) { + return NAPI_FAILTURE(env); + } + if (OH_CommonEvent_GetCharFromParameters(parameters, KEY_CHAR, 'v') != value) { + return NAPI_FAILTURE(env); + } + OH_CommonEvent_DestroyParameters(parameters); + parameters = nullptr; + } else { + return NAPI_FAILTURE(env); + } + return NAPI_SUCCESS(env); +} + +static napi_value SetCharArrayToParameters(napi_env env, napi_callback_info info) +{ + auto parameters = OH_CommonEvent_CreateParameters(); + if (parameters != nullptr) { + char value[] = {'a', 'b', 'c'}; + size_t num = sizeof(value) / sizeof(char); + if (OH_CommonEvent_SetCharArrayToParameters(parameters, KEY_CHAR_ARRAY, value, num) != COMMONEVENT_ERR_OK) { + return NAPI_FAILTURE(env); + } + char* ptr = nullptr; + if (OH_CommonEvent_GetCharArrayFromParameters(parameters, KEY_CHAR_ARRAY, &ptr) != (num + 1)) { + return NAPI_FAILTURE(env); + } + OH_CommonEvent_DestroyParameters(parameters); + parameters = nullptr; + } else { + return NAPI_FAILTURE(env); + } + return NAPI_SUCCESS(env); +} \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/cpp/publish.cpp b/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/cpp/publish.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e9edba94987119546b3b3b475cd00d4dd22d8acc --- /dev/null +++ b/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/cpp/publish.cpp @@ -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. + */ + +#include "napi/native_api.h" +#include "hilog/log.h" +#include "BasicServicesKit/oh_commonevent.h" +#include "common.h" + +static napi_value Publish(napi_env env, napi_callback_info info) +{ + const char* event = COMMON_EVENT_TEST; + if (OH_CommonEvent_Publish(event) != COMMONEVENT_ERR_OK) { + return NAPI_FAILTURE(env); + } + return NAPI_SUCCESS(env); +} + +static napi_value PublishWithInfo(napi_env env, napi_callback_info info) +{ + const char* event = COMMON_EVENT_TEST; + bool ordered = true; + auto publishInfo = OH_CommonEvent_CreatePublishInfo(ordered); + if (OH_CommonEvent_PublishWithInfo(event, publishInfo) != COMMONEVENT_ERR_OK) { + return NAPI_FAILTURE(env); + } + if (publishInfo != nullptr) { + OH_CommonEvent_DestroyPublishInfo(publishInfo); + } + publishInfo = nullptr; + return NAPI_SUCCESS(env); +} \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/cpp/publishinfo.cpp b/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/cpp/publishinfo.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b2cdce694180032b589b30d07890274b19ab8d40 --- /dev/null +++ b/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/cpp/publishinfo.cpp @@ -0,0 +1,280 @@ +/* + * 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. + */ + +#include "napi/native_api.h" +#include "hilog/log.h" +#include "BasicServicesKit/oh_commonevent.h" +#include "common.h" + +static CommonEvent_Subscriber* g_subscriberPI = nullptr; +static CommonEvent_SubscribeInfo* g_subscribeInfoPI = nullptr; +static CommonEvent_PublishInfo* g_publishInfoPI = nullptr; +static char* g_publishInfoBN = nullptr; +static bool g_isPublishInfoData = false; +static int32_t g_publishInfoCode = PARAM_0; +static int32_t g_parametersInt = PARAM_0; + +static napi_value CreatePublishInfo(napi_env env, napi_callback_info info) +{ + bool ordered = true; + g_publishInfoPI = OH_CommonEvent_CreatePublishInfo(ordered); + if (g_publishInfoPI == nullptr) { + return NAPI_FAILTURE(env); + } + return NAPI_SUCCESS(env); +} + +static napi_value DestroyPublishInfo(napi_env env, napi_callback_info info) +{ + if (g_publishInfoPI != nullptr) { + OH_CommonEvent_DestroyPublishInfo(g_publishInfoPI); + g_publishInfoPI = nullptr; + } else { + return NAPI_FAILTURE(env); + } + return NAPI_SUCCESS(env); +} + +void PublishInfoCallback001(const CommonEvent_RcvData *data) +{ + if (data != nullptr) { + g_publishInfoBN = (char*)OH_CommonEvent_GetBundleNameFromRcvData(data); + } else { + g_publishInfoBN = nullptr; + } +} + +static napi_value SetPublishInfoBundleName(napi_env env, napi_callback_info info) +{ + bool ordered = true; + auto publishInfo = OH_CommonEvent_CreatePublishInfo(ordered); + if (publishInfo != nullptr) { + const char* bundleName = BUNDLE_NAME; + if (OH_CommonEvent_SetPublishInfoBundleName(publishInfo, bundleName) != COMMONEVENT_ERR_OK) { + return NAPI_FAILTURE(env); + } + OH_CommonEvent_PublishWithInfo(COMMON_EVENT_TEST, publishInfo); + OH_CommonEvent_DestroyPublishInfo(publishInfo); + publishInfo = nullptr; + } else { + return NAPI_FAILTURE(env); + } + return NAPI_SUCCESS(env); +} + +static napi_value SetPublishInfoPermissions(napi_env env, napi_callback_info info) +{ + bool ordered = true; + auto publishInfo = OH_CommonEvent_CreatePublishInfo(ordered); + if (publishInfo != nullptr) { + const char* permissions[] = {"ohos.permission.RECEIVER_STARTUP_COMPLETED"}; + int32_t num = PARAM_1; + if (OH_CommonEvent_SetPublishInfoPermissions(publishInfo, permissions, num) != COMMONEVENT_ERR_OK) { + return NAPI_FAILTURE(env); + } + OH_CommonEvent_DestroyPublishInfo(publishInfo); + publishInfo = nullptr; + } else { + return NAPI_FAILTURE(env); + } + return NAPI_SUCCESS(env); +} + +void PublishInfoCallback002(const CommonEvent_RcvData *data) +{ + if (data != nullptr) { + g_publishInfoCode = OH_CommonEvent_GetCodeFromRcvData(data); + } else { + g_publishInfoCode = PARAM_0; + } +} + +static napi_value GetSetPublishInfoCode(napi_env env, napi_callback_info info) +{ + if (g_subscriberPI != nullptr) { + OH_CommonEvent_UnSubscribe(g_subscriberPI); + OH_CommonEvent_DestroySubscriber(g_subscriberPI); + g_subscriberPI = nullptr; + } + if (g_subscribeInfoPI != nullptr) { + OH_CommonEvent_DestroySubscribeInfo(g_subscribeInfoPI); + g_subscribeInfoPI = nullptr; + } + if (g_publishInfoCode != PARAM_1) { + return NAPI_FAILTURE(env); + } + return NAPI_SUCCESS(env); +} + +static napi_value SetPublishInfoCode(napi_env env, napi_callback_info info) +{ + const char* events[] = {COMMON_EVENT_TEST}; + int32_t eventsNum = sizeof(events) / sizeof(char*); + g_subscribeInfoPI = OH_CommonEvent_CreateSubscribeInfo(events, eventsNum); + if (g_subscribeInfoPI == nullptr) { + return NAPI_FAILTURE(env); + } + g_subscriberPI = OH_CommonEvent_CreateSubscriber(g_subscribeInfoPI, PublishInfoCallback002); + if (g_subscriberPI == nullptr) { + return NAPI_FAILTURE(env); + } + if (OH_CommonEvent_Subscribe(g_subscriberPI) != COMMONEVENT_ERR_OK) { + return NAPI_FAILTURE(env); + } + bool ordered = true; + auto publishInfo = OH_CommonEvent_CreatePublishInfo(ordered); + if (publishInfo != nullptr) { + int32_t code = PARAM_1; + if (OH_CommonEvent_SetPublishInfoCode(publishInfo, code) != COMMONEVENT_ERR_OK) { + return NAPI_FAILTURE(env); + } + if (OH_CommonEvent_PublishWithInfo(COMMON_EVENT_TEST, publishInfo) != COMMONEVENT_ERR_OK) { + return NAPI_FAILTURE(env); + } + OH_CommonEvent_DestroyPublishInfo(publishInfo); + publishInfo = nullptr; + } else { + return NAPI_FAILTURE(env); + } + return NAPI_SUCCESS(env); +} + +void PublishInfoCallback003(const CommonEvent_RcvData *data) +{ + if (data != nullptr && ::strcmp((char *)OH_CommonEvent_GetDataStrFromRcvData(data), "d") == 0) { + g_isPublishInfoData = true; + } else { + g_isPublishInfoData = false; + } +} + +static napi_value GetSetPublishInfoData(napi_env env, napi_callback_info info) +{ + if (g_subscriberPI != nullptr) { + OH_CommonEvent_UnSubscribe(g_subscriberPI); + OH_CommonEvent_DestroySubscriber(g_subscriberPI); + g_subscriberPI = nullptr; + } + if (g_subscribeInfoPI != nullptr) { + OH_CommonEvent_DestroySubscribeInfo(g_subscribeInfoPI); + g_subscribeInfoPI = nullptr; + } + if (!g_isPublishInfoData) { + return NAPI_FAILTURE(env); + } + return NAPI_SUCCESS(env); +} + +static napi_value SetPublishInfoData(napi_env env, napi_callback_info info) +{ + const char* events[] = {COMMON_EVENT_TEST}; + int32_t eventsNum = sizeof(events) / sizeof(char*); + g_subscribeInfoPI = OH_CommonEvent_CreateSubscribeInfo(events, eventsNum); + if (g_subscribeInfoPI == nullptr) { + return NAPI_FAILTURE(env); + } + g_subscriberPI = OH_CommonEvent_CreateSubscriber(g_subscribeInfoPI, PublishInfoCallback003); + if (g_subscriberPI == nullptr) { + return NAPI_FAILTURE(env); + } + if (OH_CommonEvent_Subscribe(g_subscriberPI) != COMMONEVENT_ERR_OK) { + return NAPI_FAILTURE(env); + } + bool ordered = true; + auto publishInfo = OH_CommonEvent_CreatePublishInfo(ordered); + if (publishInfo != nullptr) { + const char* data = "data"; + size_t length = PARAM_1; + g_isPublishInfoData = false; + if (OH_CommonEvent_SetPublishInfoData(publishInfo, data, length) != COMMONEVENT_ERR_OK) { + return NAPI_FAILTURE(env); + } + if (OH_CommonEvent_PublishWithInfo(COMMON_EVENT_TEST, publishInfo) != COMMONEVENT_ERR_OK) { + return NAPI_FAILTURE(env); + } + OH_CommonEvent_DestroyPublishInfo(publishInfo); + publishInfo = nullptr; + } else { + return NAPI_FAILTURE(env); + } + return NAPI_SUCCESS(env); +} + +void PublishInfoCallback005(const CommonEvent_RcvData *data) +{ + if (data != nullptr) { + auto parameters = OH_CommonEvent_GetParametersFromRcvData(data); + if (parameters != nullptr) { + g_parametersInt = OH_CommonEvent_GetIntFromParameters(parameters, KEY_INT, PARAM_0); + } + } else { + g_parametersInt = PARAM_0; + } +} + +static napi_value GetSetPublishInfoParameters(napi_env env, napi_callback_info info) +{ + if (g_subscriberPI != nullptr) { + OH_CommonEvent_UnSubscribe(g_subscriberPI); + OH_CommonEvent_DestroySubscriber(g_subscriberPI); + g_subscriberPI = nullptr; + } + if (g_subscribeInfoPI != nullptr) { + OH_CommonEvent_DestroySubscribeInfo(g_subscribeInfoPI); + g_subscribeInfoPI = nullptr; + } + if (g_parametersInt != PARAM_1) { + return NAPI_FAILTURE(env); + } + return NAPI_SUCCESS(env); +} + +static napi_value SetPublishInfoParameters(napi_env env, napi_callback_info info) +{ + const char* events[] = {COMMON_EVENT_TEST}; + int32_t eventsNum = sizeof(events) / sizeof(char*); + g_subscribeInfoPI = OH_CommonEvent_CreateSubscribeInfo(events, eventsNum); + if (g_subscribeInfoPI == nullptr) { + return NAPI_FAILTURE(env); + } + g_subscriberPI = OH_CommonEvent_CreateSubscriber(g_subscribeInfoPI, PublishInfoCallback005); + if (g_subscriberPI == nullptr) { + return NAPI_FAILTURE(env); + } + if (OH_CommonEvent_Subscribe(g_subscriberPI) != COMMONEVENT_ERR_OK) { + return NAPI_FAILTURE(env); + } + bool ordered = true; + auto publishInfo = OH_CommonEvent_CreatePublishInfo(ordered); + auto parameters = OH_CommonEvent_CreateParameters(); + if (publishInfo != nullptr && parameters != nullptr) { + if (OH_CommonEvent_SetIntToParameters(parameters, KEY_INT, PARAM_1) != COMMONEVENT_ERR_OK) { + return NAPI_FAILTURE(env); + } + if (OH_CommonEvent_SetPublishInfoParameters(publishInfo, parameters) != COMMONEVENT_ERR_OK) { + return NAPI_FAILTURE(env); + } + if (OH_CommonEvent_PublishWithInfo(COMMON_EVENT_TEST, publishInfo) != COMMONEVENT_ERR_OK) { + return NAPI_FAILTURE(env); + } + OH_CommonEvent_DestroyParameters(parameters); + parameters = nullptr; + OH_CommonEvent_DestroyPublishInfo(publishInfo); + publishInfo = nullptr; + } else { + return NAPI_FAILTURE(env); + } + return NAPI_SUCCESS(env); +} \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/cpp/types/libentry/Index.d.ts b/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..7cdecab663765d7256053b54eb2c4d4c9c498774 --- /dev/null +++ b/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/cpp/types/libentry/Index.d.ts @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export const createParameters: () => number; +export const destroyParameters: () => number; +export const setIntToParameters: () => number; +export const setIntArrayToParameters: () => number; +export const setLongToParameters: () => number; +export const setLongArrayToParameters: () => number; +export const setDoubleToParameters: () => number; +export const setDoubleArrayToParameters: () => number; +export const setBoolToParameters: () => number; +export const setBoolArrayToParameters: () => number; +export const setCharToParameters: () => number; +export const setCharArrayToParameters: () => number; + +export const createPublishInfo: () => number; +export const destroyPublishInfo: () => number; +export const setPublishInfoBundleName: () => number; +export const getPublishInfo001: () => number; +export const setPublishInfoPermissions: () => number; +export const setPublishInfoCode: () => number; +export const getSetPublishInfoCode: () => number; +export const setPublishInfoData: () => number; +export const getSetPublishInfoData: () => number; +export const setPublishInfoParameters: () => number; +export const getSetPublishInfoParameters: () => number; + +export const publish: () => number; +export const publishWithInfo: () => number; + +export const isOrderedCommonEvent: () => number; +export const getIsOrderedCommonEvent: () => number; +export const finishCommonEvent: () => number; +export const getFinishCommonEvent: () => number; +export const getAbortCommonEvent: () => number; +export const getGetAbortCommonEvent: () => number; +export const abortCommonEvent: () => number; +export const getAbortCommonEvent2: () => number; +export const clearAbortCommonEvent: () => number; +export const getClearAbortCommonEvent: () => number; +export const subscriberCommonEvent: () => number; +export const getGetCodeFromSubscriber: () => number; +export const getSetCodeToSubscriber: () => number; +export const getGetDataFromSubscriber: () => number; +export const getSetDataToSubscriber: () => number; \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6abf3b7c20f22c62aaac6a995a25cae672f73f35 --- /dev/null +++ b/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -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. + */ + +{ + "name": "libentry.so", + "types": "./Index.d.ts", + "version": "1.0.0", + "description": "Please describe the basic information." +} \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/ets/entryability/EntryAbility.ets b/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..c5539bddd7a772710f55da0ddd7b5676305469de --- /dev/null +++ b/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/ets/entryability/EntryAbility.ets @@ -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. + */ + +import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +}; diff --git a/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/ets/pages/Index.ets b/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..374bb640df5907370bd40da460fdeb2a460bfcaf --- /dev/null +++ b/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,68 @@ +/* + * 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 testNapi from 'libentry.so'; +import router from '@ohos.router'; + +@Entry +@Component +struct Index { + private fileName: string[] = [ + 'Parameters', + 'PublishInfo', + 'Publish', + 'OrderedCommonEvent' + ] + + build() { + Column() { + Column() { + Text($r(`app.string.main_title`)) + .fontSize(30) + .fontWeight(700) + .textAlign(TextAlign.Start) + .margin({ top: 12, left: 12, right: 12 }) + } + .width('100%') + .height(px2vp(70)) + .alignItems(HorizontalAlign.Start) + + List({ initialIndex: 0 }) { + ForEach(this.fileName, (item: string) => { + ListItem() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { + Button($r(`app.string.${item}_title`)) + .layoutWeight(1) + .fontSize(18) + .width('100%') + .id(`${item}`) + .onClick(() => { + router.pushUrl({ + url: `pages/${item}` + }); + }) + } + } + .height('8.45%') + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + }, (item: string) => item) + } + .height('85%') + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/ets/pages/OrderedCommonEvent.ets b/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/ets/pages/OrderedCommonEvent.ets new file mode 100644 index 0000000000000000000000000000000000000000..86719ff9070c7e02f2f3522ad6118ee7c26e6e37 --- /dev/null +++ b/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/ets/pages/OrderedCommonEvent.ets @@ -0,0 +1,336 @@ +/* + * 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 testNapi from 'libentry.so'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { promptAction } from '@kit.ArkUI'; +import { commonEventManager } from '@kit.BasicServicesKit'; + +const TAG: string = 'OrderedCommonEvent'; +const DOMAIN: number = 0xFF00; +const SUCCESS: number = 0; +const FAILURE: number = -1; +const WAITTIME3000: number = 3000; + +@Entry +@Component +struct Index { + @Provide('pageInfo') pageInfo: NavPathStack = new NavPathStack(); + @State title: Resource = $r(`app.string.OrderedCommonEvent_title`); + @State result: number = 0; + @State isButtonEnabled: boolean = true; + + privacyDialogController: CustomDialogController = new CustomDialogController({ + builder: CustomDialogExample({ title: $title, result: $result }), + autoCancel: false, + alignment: DialogAlignment.Center, + customStyle: false, + backgroundColor: Color.White, + }); + + build() { + Column() { + Column() { + Text($r(`app.string.OrderedCommonEvent_title`)) + .fontSize(30) + .fontWeight(700) + .textAlign(TextAlign.Start) + .margin({ top: 12, left: 12, right: 12 }) + } + .width('100%') + .height(px2vp(70)) + .alignItems(HorizontalAlign.Start) + + List({ initialIndex: 0 }) { + ListItem() { + Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { + Button($r(`app.string.IsOrderedCommonEvent`)) + .layoutWeight(1) + .fontSize(18) + .width('100%') + .enabled(this.isButtonEnabled) + .onClick(() => { + this.isButtonEnabled = false; + this.title = $r(`app.string.IsOrderedCommonEvent`); + this.result = FAILURE; + if (testNapi.isOrderedCommonEvent() === SUCCESS) { + setTimeout(() => { + this.result = testNapi.getIsOrderedCommonEvent(); + this.privacyDialogController.open(); + this.isButtonEnabled = true; + }, WAITTIME3000) + } + }) + .id('isOrderedCommonEvent') + } + } + .height('8.45%') + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { + Button($r(`app.string.FinishCommonEvent`)) + .layoutWeight(1) + .fontSize(18) + .width('100%') + .enabled(this.isButtonEnabled) + .onClick(() => { + this.isButtonEnabled = false; + this.title = $r(`app.string.FinishCommonEvent`); + this.result = FAILURE; + if (testNapi.finishCommonEvent() === SUCCESS) { + setTimeout(() => { + this.result = testNapi.getFinishCommonEvent(); + this.privacyDialogController.open(); + this.isButtonEnabled = true; + }, WAITTIME3000) + } + }) + .id('finishCommonEvent') + } + } + .height('8.45%') + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { + Button($r(`app.string.AbortCommonEvent`)) + .layoutWeight(1) + .fontSize(18) + .width('100%') + .enabled(this.isButtonEnabled) + .onClick(() => { + this.isButtonEnabled = false; + this.title = $r(`app.string.AbortCommonEvent`); + this.result = FAILURE; + if (testNapi.abortCommonEvent() === SUCCESS) { + setTimeout(() => { + this.result = testNapi.getAbortCommonEvent2(); + this.privacyDialogController.open(); + this.isButtonEnabled = true; + }, WAITTIME3000) + } + }) + .id('abortCommonEvent') + } + } + .height('8.45%') + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { + Button($r(`app.string.GetAbortCommonEvent`)) + .layoutWeight(1) + .fontSize(18) + .width('100%') + .enabled(this.isButtonEnabled) + .onClick(() => { + this.isButtonEnabled = false; + this.title = $r(`app.string.GetAbortCommonEvent`); + this.result = FAILURE; + if (testNapi.getAbortCommonEvent() === SUCCESS) { + setTimeout(() => { + this.result = testNapi.getGetAbortCommonEvent(); + this.privacyDialogController.open(); + this.isButtonEnabled = true; + }, WAITTIME3000) + } + }) + .id('getAbortCommonEvent') + } + } + .height('8.45%') + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { + Button($r(`app.string.ClearAbortCommonEvent`)) + .layoutWeight(1) + .fontSize(18) + .width('100%') + .enabled(this.isButtonEnabled) + .onClick(() => { + this.isButtonEnabled = false; + this.title = $r(`app.string.ClearAbortCommonEvent`); + this.result = FAILURE; + if (testNapi.clearAbortCommonEvent() === SUCCESS) { + setTimeout(() => { + this.result = testNapi.getClearAbortCommonEvent(); + this.privacyDialogController.open(); + this.isButtonEnabled = true; + }, WAITTIME3000) + } + }) + .id('clearAbortCommonEvent') + } + } + .height('8.45%') + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { + Button($r(`app.string.GetCodeFromSubscriber`)) + .layoutWeight(1) + .fontSize(18) + .width('100%') + .enabled(this.isButtonEnabled) + .onClick(() => { + this.isButtonEnabled = false; + this.title = $r(`app.string.GetCodeFromSubscriber`); + this.result = FAILURE; + if (testNapi.subscriberCommonEvent() === SUCCESS) { + setTimeout(() => { + this.result = testNapi.getGetCodeFromSubscriber(); + this.privacyDialogController.open(); + this.isButtonEnabled = true; + }, WAITTIME3000) + } + }) + .id('getCodeFromSubscriber') + } + } + .height('8.45%') + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { + Button($r(`app.string.SetCodeToSubscriber`)) + .layoutWeight(1) + .fontSize(18) + .width('100%') + .enabled(this.isButtonEnabled) + .onClick(() => { + this.isButtonEnabled = false; + this.title = $r(`app.string.SetCodeToSubscriber`); + this.result = FAILURE; + if (testNapi.subscriberCommonEvent() === SUCCESS) { + setTimeout(() => { + this.result = testNapi.getSetCodeToSubscriber(); + this.privacyDialogController.open(); + this.isButtonEnabled = true; + }, WAITTIME3000) + } + }) + .id('setCodeToSubscriber') + } + } + .height('8.45%') + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { + Button($r(`app.string.GetDataFromSubscriber`)) + .layoutWeight(1) + .fontSize(18) + .width('100%') + .enabled(this.isButtonEnabled) + .onClick(() => { + this.isButtonEnabled = false; + this.title = $r(`app.string.GetDataFromSubscriber`); + this.result = FAILURE; + if (testNapi.subscriberCommonEvent() === SUCCESS) { + setTimeout(() => { + this.result = testNapi.getGetDataFromSubscriber(); + this.privacyDialogController.open(); + this.isButtonEnabled = true; + }, WAITTIME3000) + } + }) + .id('getDataFromSubscriber') + } + } + .height('8.45%') + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + + ListItem() { + Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { + Button($r(`app.string.SetDataToSubscriber`)) + .layoutWeight(1) + .fontSize(18) + .width('100%') + .enabled(this.isButtonEnabled) + .onClick(() => { + this.isButtonEnabled = false; + this.title = $r(`app.string.SetDataToSubscriber`); + this.result = FAILURE; + if (testNapi.subscriberCommonEvent() === SUCCESS) { + setTimeout(() => { + this.result = testNapi.getSetDataToSubscriber(); + this.privacyDialogController.open(); + this.isButtonEnabled = true; + }, WAITTIME3000) + } + }) + .id('setDataToSubscriber') + } + } + .height('8.45%') + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + } + .height('85%') + } + .width('100%') + .height('100%') + } +} + +@CustomDialog +struct CustomDialogExample { + @Link result: number; + @Link title: Resource; + + controller?: CustomDialogController; + cancel: () => void = () => { + } + confirm: () => void = () => { + } + + build() { + Column() { + Text(this.title) + .fontSize(24) + .fontWeight(700) + .height(px2vp(100)) + Text('Result: ' + (this.result === SUCCESS ? 'success' : 'failure')) + .fontSize(18) + .fontWeight(400) + .textAlign(TextAlign.Start) + .margin({ left: px2vp(84), right: px2vp(84) }) + .width('90%') + Button('OK', { buttonStyle: ButtonStyleMode.TEXTUAL, role: ButtonRole.NORMAL }) + .onClick(() => { + if (this.controller != undefined) { + this.controller.close(); + } + }) + .id('okOrderedCommonEvent') + .stateEffect(false) + .fontSize(18) + .fontWeight(500) + .margin(5) + } + } +} \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/ets/pages/Parameters.ets b/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/ets/pages/Parameters.ets new file mode 100644 index 0000000000000000000000000000000000000000..2a4fa3b1b150494947f11b389999d2bd923aa3c4 --- /dev/null +++ b/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/ets/pages/Parameters.ets @@ -0,0 +1,343 @@ +/* + * 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 testNapi from 'libentry.so'; + +@Entry +@Component +struct Index { + @Provide('pageInfo') pageInfo: NavPathStack = new NavPathStack(); + @State title: Resource = $r(`app.string.Parameters_title`); + @State result: number = 0; + @State isButtonEnabled: boolean = true; + + privacyDialogController: CustomDialogController = new CustomDialogController({ + builder: CustomDialogExample({ title: $title, result: $result }), + autoCancel: false, + alignment: DialogAlignment.Center, + customStyle: false, + backgroundColor: Color.White, + }); + + build() { + Column() { + Column() { + Text($r(`app.string.Parameters_title`)) + .fontSize(30) + .fontWeight(700) + .textAlign(TextAlign.Start) + .margin({ top: 8, left: 12, right: 12 }) + } + .width('100%') + .height(px2vp(70)) + .alignItems(HorizontalAlign.Start) + + List({ initialIndex: 0 }) { + ListItem() { + Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { + Button($r(`app.string.CreateParameters`)) + .layoutWeight(1) + .fontSize(14) + .width('100%') + .enabled(this.isButtonEnabled) + .onClick(() => { + this.isButtonEnabled = false; + this.title = $r(`app.string.CreateParameters`); + this.result = testNapi.createParameters(); + this.privacyDialogController.open(); + this.isButtonEnabled = true; + }) + .id('createParameters') + } + } + .height('6%') + .borderRadius(24) + .margin({ top: 8, right: 12, left: 12 }) + + ListItem() { + Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { + Button($r(`app.string.DestroyParameters`)) + .layoutWeight(1) + .fontSize(14) + .width('100%') + .enabled(this.isButtonEnabled) + .onClick(() => { + this.isButtonEnabled = false; + this.title = $r(`app.string.DestroyParameters`); + this.result = testNapi.destroyParameters(); + this.privacyDialogController.open(); + this.isButtonEnabled = true; + }) + .id('destroyParameters') + } + } + .height('6%') + .borderRadius(24) + .margin({ top: 8, right: 12, left: 12 }) + + ListItem() { + Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { + Button($r(`app.string.SetIntToParameters`)) + .layoutWeight(1) + .fontSize(14) + .width('100%') + .enabled(this.isButtonEnabled) + .onClick(() => { + this.isButtonEnabled = false; + this.title = $r(`app.string.SetIntToParameters`); + this.result = testNapi.setIntToParameters(); + this.privacyDialogController.open(); + this.isButtonEnabled = true; + }) + .id('setIntToParameters') + } + } + .height('6%') + .borderRadius(24) + .margin({ top: 8, right: 12, left: 12 }) + + ListItem() { + Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { + Button($r(`app.string.SetIntArrayToParameters`)) + .layoutWeight(1) + .fontSize(14) + .width('100%') + .enabled(this.isButtonEnabled) + .onClick(() => { + this.isButtonEnabled = false; + this.title = $r(`app.string.SetIntArrayToParameters`); + this.result = testNapi.setIntArrayToParameters(); + this.privacyDialogController.open(); + this.isButtonEnabled = true; + }) + .id('setIntArrayToParameters') + } + } + .height('6%') + .borderRadius(24) + .margin({ top: 8, right: 12, left: 12 }) + + ListItem() { + Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { + Button($r(`app.string.SetLongToParameters`)) + .layoutWeight(1) + .fontSize(14) + .width('100%') + .enabled(this.isButtonEnabled) + .onClick(() => { + this.isButtonEnabled = false; + this.title = $r(`app.string.SetLongToParameters`); + this.result = testNapi.setLongToParameters(); + this.privacyDialogController.open(); + this.isButtonEnabled = true; + }) + .id('setLongToParameters') + } + } + .height('6%') + .borderRadius(24) + .margin({ top: 8, right: 12, left: 12 }) + + ListItem() { + Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { + Button($r(`app.string.SetLongArrayToParameters`)) + .layoutWeight(1) + .fontSize(14) + .width('100%') + .enabled(this.isButtonEnabled) + .onClick(() => { + this.isButtonEnabled = false; + this.title = $r(`app.string.SetLongArrayToParameters`); + this.result = testNapi.setLongArrayToParameters(); + this.privacyDialogController.open(); + this.isButtonEnabled = true; + }) + .id('setLongArrayToParameters') + } + } + .height('6%') + .borderRadius(24) + .margin({ top: 8, right: 12, left: 12 }) + + ListItem() { + Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { + Button($r(`app.string.SetDoubleToParameters`)) + .layoutWeight(1) + .fontSize(14) + .width('100%') + .enabled(this.isButtonEnabled) + .onClick(() => { + this.isButtonEnabled = false; + this.title = $r(`app.string.SetDoubleToParameters`); + this.result = testNapi.setDoubleToParameters(); + this.privacyDialogController.open(); + this.isButtonEnabled = true; + }) + .id('setDoubleToParameters') + } + } + .height('6%') + .borderRadius(24) + .margin({ top: 8, right: 12, left: 12 }) + + ListItem() { + Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { + Button($r(`app.string.SetDoubleArrayToParameters`)) + .layoutWeight(1) + .fontSize(14) + .width('100%') + .enabled(this.isButtonEnabled) + .onClick(() => { + this.isButtonEnabled = false; + this.title = $r(`app.string.SetDoubleArrayToParameters`); + this.result = testNapi.setDoubleArrayToParameters(); + this.privacyDialogController.open(); + this.isButtonEnabled = true; + }) + .id('setDoubleArrayToParameters') + } + } + .height('6%') + .borderRadius(24) + .margin({ top: 8, right: 12, left: 12 }) + + ListItem() { + Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { + Button($r(`app.string.SetBoolToParameters`)) + .layoutWeight(1) + .fontSize(14) + .width('100%') + .enabled(this.isButtonEnabled) + .onClick(() => { + this.isButtonEnabled = false; + this.title = $r(`app.string.SetBoolToParameters`); + this.result = testNapi.setBoolToParameters(); + this.privacyDialogController.open(); + this.isButtonEnabled = true; + }) + .id('setBoolToParameters') + } + } + .height('6%') + .borderRadius(24) + .margin({ top: 8, right: 12, left: 12 }) + + ListItem() { + Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { + Button($r(`app.string.SetBoolArrayToParameters`)) + .layoutWeight(1) + .fontSize(14) + .width('100%') + .enabled(this.isButtonEnabled) + .onClick(() => { + this.isButtonEnabled = false; + this.title = $r(`app.string.SetBoolArrayToParameters`); + this.result = testNapi.setBoolArrayToParameters(); + this.privacyDialogController.open(); + this.isButtonEnabled = true; + }) + .id('setBoolArrayToParameters') + } + } + .height('6%') + .borderRadius(24) + .margin({ top: 8, right: 12, left: 12 }) + + ListItem() { + Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { + Button($r(`app.string.SetCharToParameters`)) + .layoutWeight(1) + .fontSize(14) + .width('100%') + .enabled(this.isButtonEnabled) + .onClick(() => { + this.isButtonEnabled = false; + this.title = $r(`app.string.SetCharToParameters`); + this.result = testNapi.setCharToParameters(); + this.privacyDialogController.open(); + this.isButtonEnabled = true; + }) + .id('setCharToParameters') + } + } + .height('6%') + .borderRadius(24) + .margin({ top: 8, right: 12, left: 12 }) + + ListItem() { + Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { + Button($r(`app.string.SetCharArrayToParameters`)) + .layoutWeight(1) + .fontSize(14) + .width('100%') + .enabled(this.isButtonEnabled) + .onClick(() => { + this.isButtonEnabled = false; + this.title = $r(`app.string.SetCharArrayToParameters`); + this.result = testNapi.setCharArrayToParameters(); + this.privacyDialogController.open(); + this.isButtonEnabled = true; + }) + .id('setCharArrayToParameters') + } + } + .height('6%') + .borderRadius(24) + .margin({ top: 8, right: 12, left: 12 }) + } + .height('85%') + } + .width('100%') + .height('100%') + } +} + +@CustomDialog +struct CustomDialogExample { + @Link result: number; + @Link title: Resource; + + controller?: CustomDialogController; + cancel: () => void = () => { + } + confirm: () => void = () => { + } + + build() { + Column() { + Text(this.title) + .fontSize(24) + .fontWeight(700) + .height(px2vp(100)) + Text('Result: ' + (this.result == 0 ? 'success' : 'failure')) + .fontSize(14) + .fontWeight(400) + .textAlign(TextAlign.Start) + .margin({ left: px2vp(84), right: px2vp(84) }) + .width('90%') + Button('OK', { buttonStyle: ButtonStyleMode.TEXTUAL, role: ButtonRole.NORMAL }) + .onClick(() => { + if (this.controller != undefined) { + this.controller.close(); + } + }) + .id('okParameters') + .stateEffect(false) + .fontSize(14) + .fontWeight(500) + .margin(5) + } + } +} \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/ets/pages/Publish.ets b/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/ets/pages/Publish.ets new file mode 100644 index 0000000000000000000000000000000000000000..9fae45608707147ce6e451a236fa1ba589dd7e73 --- /dev/null +++ b/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/ets/pages/Publish.ets @@ -0,0 +1,141 @@ +/* + * 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 testNapi from 'libentry.so'; +import { commonEventManager } from '@kit.BasicServicesKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { promptAction } from '@kit.ArkUI'; + +const TAG: string = 'PublishInfo'; +const DOMAIN: number = 0xFF00; +const SUCCESS: number = 0; + +@Entry +@Component +struct Index{ + @Provide('pageInfo')pageInfo: NavPathStack = new NavPathStack(); + @State title: Resource = $r(`app.string.Publish_title`); + @State result: number = 0; + @State isButtonEnabled: boolean = true; + + privacyDialogController: CustomDialogController = new CustomDialogController({ + builder: CustomDialogExample({ title: $title, result: $result }), + autoCancel: false, + alignment: DialogAlignment.Center, + customStyle: false, + backgroundColor: Color.White, + }); + + build(){ + Column() { + Column() { + Text($r('app.string.Publish_title')) + .fontSize(30) + .fontWeight(700) + .textAlign(TextAlign.Start) + .margin({ top: 12, left: 12, right: 12 }) + } + .width('100%') + .height(px2vp(70)) + .alignItems(HorizontalAlign.Start) + + List({ initialIndex: 0 }) { + ListItem() { + Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { + Button($r(`app.string.Publish`)) + .layoutWeight(1) + .fontSize(18) + .width('100%') + .enabled(this.isButtonEnabled) + .onClick(() => { + this.isButtonEnabled = false; + this.title = $r(`app.string.Publish`); + this.result = testNapi.publish(); + this.privacyDialogController.open(); + this.isButtonEnabled = true; + }) + .id('publish') + } + } + .height('8.45%') + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { + Button($r(`app.string.PublishWithInfo`)) + .layoutWeight(1) + .fontSize(18) + .width('100%') + .enabled(this.isButtonEnabled) + .onClick(() => { + this.isButtonEnabled = false; + this.title = $r(`app.string.PublishWithInfo`); + this.result = testNapi.publishWithInfo(); + this.privacyDialogController.open(); + this.isButtonEnabled = true; + }) + .id('publishWithInfo') + } + } + .height('8.45%') + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + } + .height('86%') + } + .width('100%') + .height('100%') + } +} + +@CustomDialog +struct CustomDialogExample { + @Link result: number; + @Link title: Resource; + + controller?: CustomDialogController; + cancel: () => void = () => { + } + confirm: () => void = () => { + } + + build() { + Column() { + Text(this.title) + .fontSize(24) + .fontWeight(700) + .height(px2vp(100)) + Text('Result: ' + (this.result ==0 ? 'success' : 'failed')) + .fontSize(18) + .fontWeight(400) + .textAlign(TextAlign.Start) + .margin({ left: px2vp(84), right: px2vp(84) }) + .width('90%') + Button('OK', { buttonStyle: ButtonStyleMode.TEXTUAL, role: ButtonRole.NORMAL }) + .onClick(() => { + if (this.controller != undefined) { + this.controller.close(); + } + }) + .id('okPublish') + .stateEffect(false) + .fontSize(18) + .fontWeight(500) + .margin(5) + } + } +} \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/ets/pages/PublishInfo.ets b/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/ets/pages/PublishInfo.ets new file mode 100644 index 0000000000000000000000000000000000000000..a863bf32cb894246609c1129c0446b7116fa51d5 --- /dev/null +++ b/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/ets/pages/PublishInfo.ets @@ -0,0 +1,264 @@ +/* + * 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 testNapi from 'libentry.so'; +import { commonEventManager } from '@kit.BasicServicesKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { promptAction } from '@kit.ArkUI'; + +const TAG: string = 'PublishInfo'; +const DOMAIN: number = 0xFF00; +const SUCCESS: number = 0; +const FAILURE: number = -1; +const WAITTIME3000: number = 3000; + +@Entry +@Component +struct Index { + @Provide('pageInfo') pageInfo: NavPathStack = new NavPathStack(); + @State title: Resource = $r(`app.string.Parameters_title`); + @State result: number = 0; + @State isButtonEnabled: boolean = true; + + privacyDialogController: CustomDialogController = new CustomDialogController({ + builder: CustomDialogExample({ title: $title, result: $result }), + autoCancel: false, + alignment: DialogAlignment.Center, + customStyle: false, + backgroundColor: Color.White, + }); + + + build() { + Column() { + Column() { + Text($r(`app.string.PublishInfo_title`)) + .fontSize(30) + .fontWeight(700) + .textAlign(TextAlign.Start) + .margin({ top: 12, left: 12, right: 12 }) + } + .width('100%') + .height(px2vp(70)) + .alignItems(HorizontalAlign.Start) + + List({ initialIndex: 0 }) { + ListItem() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { + Button($r(`app.string.CreatePublishInfo`)) + .layoutWeight(1) + .fontSize(18) + .width('100%') + .enabled(this.isButtonEnabled) + .onClick(() => { + this.isButtonEnabled = false; + this.title = $r(`app.string.CreatePublishInfo`); + this.result = testNapi.createPublishInfo(); + this.privacyDialogController.open(); + this.isButtonEnabled = true; + }) + .id('createPublishInfo') + } + } + .height('8.45%') + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { + Button($r(`app.string.DestroyPublishInfo`)) + .layoutWeight(1) + .fontSize(18) + .width('100%') + .enabled(this.isButtonEnabled) + .onClick(() => { + this.isButtonEnabled = false; + this.title = $r(`app.string.DestroyPublishInfo`); + this.result = testNapi.destroyPublishInfo(); + this.privacyDialogController.open(); + this.isButtonEnabled = true; + }) + .id('destroyPublishInfo') + } + } + .height('8.45%') + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { + Button($r(`app.string.SetPublishInfoBundleName`)) + .layoutWeight(1) + .fontSize(18) + .width('100%') + .enabled(this.isButtonEnabled) + .onClick(() => { + this.isButtonEnabled = false; + this.title = $r(`app.string.SetPublishInfoBundleName`); + this.result = testNapi.setPublishInfoBundleName(); + this.privacyDialogController.open(); + this.isButtonEnabled = true; + }) + .id('setPublishInfoBundleName') + } + } + .height('8.45%') + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { + Button($r(`app.string.SetPublishInfoPermissions`)) + .layoutWeight(1) + .fontSize(18) + .width('100%') + .enabled(this.isButtonEnabled) + .onClick(() => { + this.isButtonEnabled = false; + this.title = $r(`app.string.SetPublishInfoPermissions`); + this.result = testNapi.setPublishInfoPermissions(); + this.privacyDialogController.open(); + this.isButtonEnabled = true; + }) + .id('setPublishInfoPermissions') + } + } + .height('8.45%') + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { + Button($r(`app.string.SetPublishInfoCode`)) + .layoutWeight(1) + .fontSize(18) + .width('100%') + .enabled(this.isButtonEnabled) + .onClick(() => { + this.isButtonEnabled = false; + this.title = $r(`app.string.SetPublishInfoCode`); + this.result = FAILURE; + if (testNapi.setPublishInfoCode() === SUCCESS) { + setTimeout(() => { + this.result = testNapi.getSetPublishInfoCode(); + this.privacyDialogController.open(); + this.isButtonEnabled = true; + }, WAITTIME3000) + } + }) + .id('setPublishInfoCode') + } + } + .height('8.45%') + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { + Button($r(`app.string.SetPublishInfoData`)) + .layoutWeight(1) + .fontSize(18) + .width('100%') + .enabled(this.isButtonEnabled) + .onClick(() => { + this.isButtonEnabled = false; + this.title = $r(`app.string.SetPublishInfoData`); + this.result = FAILURE; + if (testNapi.setPublishInfoData() === SUCCESS) { + setTimeout(() => { + this.result = testNapi.getSetPublishInfoData(); + this.privacyDialogController.open(); + this.isButtonEnabled = true; + }, WAITTIME3000) + } + }) + .id('setPublishInfoData') + } + } + .height('8.45%') + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { + Button($r(`app.string.SetPublishInfoParameters`)) + .layoutWeight(1) + .fontSize(18) + .width('100%') + .enabled(this.isButtonEnabled) + .onClick(() => { + this.isButtonEnabled = false; + this.title = $r(`app.string.SetPublishInfoParameters`); + this.result = FAILURE; + if (testNapi.setPublishInfoParameters() === SUCCESS) { + setTimeout(() => { + this.result = testNapi.getSetPublishInfoParameters(); + this.privacyDialogController.open(); + this.isButtonEnabled = true; + }, WAITTIME3000) + } + }) + .id('setPublishInfoParameters') + } + } + .height('8.45%') + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + } + .height('85%') + } + .width('100%') + .height('100%') + } +} + +@CustomDialog +struct CustomDialogExample { + @Link result: number; + @Link title: Resource; + + controller?: CustomDialogController; + cancel: () => void = () => { + } + confirm: () => void = () => { + } + + build() { + Column() { + Text(this.title) + .fontSize(24) + .fontWeight(700) + .height(px2vp(100)) + Text('Result: ' + (this.result == 0 ? 'success' : 'failure')) + .fontSize(18) + .fontWeight(400) + .textAlign(TextAlign.Start) + .margin({ left: px2vp(84), right: px2vp(84) }) + .width('90%') + Button('OK', { buttonStyle: ButtonStyleMode.TEXTUAL, role: ButtonRole.NORMAL }) + .onClick(() => { + if (this.controller != undefined) { + this.controller.close(); + } + }) + .id('okPublishInfo') + .stateEffect(false) + .fontSize(18) + .fontWeight(500) + .margin(5) + } + } +} \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/module.json5 b/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..8db806361111d6ad3ae57789aa204307e7fa2b7a --- /dev/null +++ b/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/module.json5 @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:startIcon", + "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/Native/NdkCommonEvent/entry/src/main/resources/base/element/color.json b/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..6cdb3e3002dfe27880828a3b181946668beef78c --- /dev/null +++ b/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/resources/base/element/color.json @@ -0,0 +1,16 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + }, + { + "name": "backGrounding", + "value": "#f1f3f5" + }, + { + "name": "text_color", + "value": "#182431" + } + ] +} \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/resources/base/element/string.json b/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..d8e24254bc69dfb88d9efc2ecd2f294267cb1272 --- /dev/null +++ b/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/resources/base/element/string.json @@ -0,0 +1,156 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "CommonEventSample" + }, + { + "name": "main_title", + "value": "NDKCommonEvent Sample" + }, + { + "name": "Parameters_title", + "value": "Parameters Sample" + }, + { + "name": "CreateParameters", + "value": "CreateParameters" + }, + { + "name": "DestroyParameters", + "value": "DestroyParameters" + }, + { + "name": "SetIntToParameters", + "value": "SetIntToParameters" + }, + { + "name": "SetIntArrayToParameters", + "value": "SetIntArrayToParameters" + }, + { + "name": "SetLongToParameters", + "value": "SetLongToParameters" + }, + { + "name": "SetLongArrayToParameters", + "value": "SetLongArrayToParameters" + }, + { + "name": "SetDoubleToParameters", + "value": "SetDoubleToParameters" + }, + { + "name": "SetDoubleArrayToParameters", + "value": "SetDoubleArrayToParameters" + }, + { + "name": "SetBoolToParameters", + "value": "SetBoolToParameters" + }, + { + "name": "SetBoolArrayToParameters", + "value": "SetBoolArrayToParameters" + }, + { + "name": "SetCharToParameters", + "value": "SetCharToParameters" + }, + { + "name": "SetCharArrayToParameters", + "value": "SetCharArrayToParameters" + }, + { + "name": "OrderedCommonEvent_title", + "value": "OrderedCommonEvent Sample" + }, + { + "name": "IsOrderedCommonEvent", + "value": "IsOrderedCommonEvent" + }, + { + "name": "FinishCommonEvent", + "value": "FinishCommonEvent" + }, + { + "name": "AbortCommonEvent", + "value": "AbortCommonEvent " + }, + { + "name": "GetAbortCommonEvent", + "value": "GetAbortCommonEvent" + }, + { + "name": "ClearAbortCommonEvent", + "value": "ClearAbortCommonEvent" + }, + { + "name": "SetCodeToSubscriber", + "value": "SetCodeToSubscriber" + }, + { + "name": "GetCodeFromSubscriber", + "value": "GetCodeFromSubscriber" + }, + { + "name": "SetDataToSubscriber", + "value": "SetDataToSubscriber" + }, + { + "name": "GetDataFromSubscriber", + "value": "GetDataFromSubscriber" + }, + { + "name": "Publish_title", + "value": "Publish Sample" + }, + { + "name": "Publish", + "value": "Publish" + }, + { + "name": "PublishWithInfo", + "value": "PublishWithInfo" + }, + { + "name": "PublishInfo_title", + "value": "PublishInfo Sample" + }, + { + "name": "CreatePublishInfo", + "value": "CreatePublishInfo" + }, + { + "name": "DestroyPublishInfo", + "value": "DestroyPublishInfo" + }, + { + "name": "SetPublishInfoBundleName", + "value": "SetPublishInfoBundleName" + }, + { + "name": "SetPublishInfoPermissions", + "value": "SetPublishInfoPermissions" + }, + { + "name": "SetPublishInfoCode", + "value": "SetPublishInfoCode" + }, + { + "name": "SetPublishInfoData", + "value": "SetPublishInfoData" + }, + { + "name": "SetPublishInfoParameters", + "value": "SetPublishInfoParameters" + } + ] +} diff --git a/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/resources/base/media/startIcon.png b/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/resources/base/media/startIcon.png differ diff --git a/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/resources/base/profile/backup_config.json b/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/BasicFeature/Native/NdkCommonEvent/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/Native/NdkCommonEvent/entry/src/main/resources/base/profile/main_pages.json b/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..6294d6bfa2648c2ad401ad96f1f964c6f224f1e1 --- /dev/null +++ b/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,9 @@ +{ + "src": [ + "pages/Index", + "pages/Parameters", + "pages/PublishInfo", + "pages/OrderedCommonEvent", + "pages/Publish" + ] +} diff --git a/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/resources/en_US/element/string.json b/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..5e65e4b9a3a1f015aa11ddee4059f624da1b1257 --- /dev/null +++ b/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/resources/en_US/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "CommonEventSample" + } + ] +} diff --git a/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/resources/zh_CN/element/string.json b/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f3a76a747efcac33a101db32edc803cd481389b9 --- /dev/null +++ b/code/BasicFeature/Native/NdkCommonEvent/entry/src/main/resources/zh_CN/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "模块描述" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "CommonEventSample" + } + ] +} diff --git a/code/BasicFeature/Native/NdkCommonEvent/entry/src/ohosTest/ets/test/Ability.test.ets b/code/BasicFeature/Native/NdkCommonEvent/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..67a50b74b727610f1808414d4f13428ab9edab0f --- /dev/null +++ b/code/BasicFeature/Native/NdkCommonEvent/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,403 @@ +/* + * 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 AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; +import { describe, beforeAll, it, expect } from '@ohos/hypium'; +import { Driver, ON } from '@ohos.UiTest'; + +const TAG: string = '[Sample_NativeCommonEventAPI]'; +const WAITTIME1000: number = 1000; +const WAITTIME2000: number = 2000; +const WAITTIME3000: number = 3000; +const WAITTIME4000: number = 4000; + +export default function abilityTest() { + describe('ActsAbilityTest', () => { + + beforeAll(async () => { + console.info(TAG + ' StartAbility_001 begin'); + + let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); + try{ + await abilityDelegator.startAbility({ + bundleName: 'com.samples.ndkcommonevent', + abilityName: 'EntryAbility' + }); + } catch (exception) { + console.info(TAG + ` StartAbility_001 exception = ${JSON.stringify(exception)}`); + expect().assertFail(); + } + console.info(TAG + ' StartAbility_001 end'); + }) + + /** + * @tc.number: NativeCommomEvent_Parameters_001 + * @tc.name: NativeCommomEvent_Parameters_001 + * @tc.desc: detect and click the button to check application commomevent parameters + */ + it('NativeCommomEvent_Parameters_001', 0, async (done: Function) => { + console.info(TAG + ' NativeCommomEvent_Parameters_001 begin'); + let driver = await Driver.create(); + await driver.delayMs(WAITTIME1000); + + // 进入parametersSample开发示例页面 + let btn = await driver.findComponent(ON.id('Parameters')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + // 点击createParameters + await driver.assertComponentExist(ON.id('createParameters')); + btn = await driver.findComponent(ON.id('createParameters')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + await driver.assertComponentExist(ON.id('okParameters')); + btn = await driver.findComponent(ON.id('okParameters')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + // 点击destroyParameters + await driver.assertComponentExist(ON.id('destroyParameters')); + btn = await driver.findComponent(ON.id('destroyParameters')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + await driver.assertComponentExist(ON.id('okParameters')); + btn = await driver.findComponent(ON.id('okParameters')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + // 点击setIntToParameters + await driver.assertComponentExist(ON.id('setIntToParameters')); + btn = await driver.findComponent(ON.id('setIntToParameters')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + await driver.assertComponentExist(ON.id('okParameters')); + btn = await driver.findComponent(ON.id('okParameters')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + // 点击setIntArrayToParameters + await driver.assertComponentExist(ON.id('setIntArrayToParameters')); + btn = await driver.findComponent(ON.id('setIntArrayToParameters')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + await driver.assertComponentExist(ON.id('okParameters')); + btn = await driver.findComponent(ON.id('okParameters')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + // 点击setLongToParameters + await driver.assertComponentExist(ON.id('setLongToParameters')); + btn = await driver.findComponent(ON.id('setLongToParameters')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + await driver.assertComponentExist(ON.id('okParameters')); + btn = await driver.findComponent(ON.id('okParameters')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + // 点击setLongArrayToParameters + await driver.assertComponentExist(ON.id('setLongArrayToParameters')); + btn = await driver.findComponent(ON.id('setLongArrayToParameters')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + await driver.assertComponentExist(ON.id('okParameters')); + btn = await driver.findComponent(ON.id('okParameters')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + // 点击setDoubleToParameters + await driver.assertComponentExist(ON.id('setDoubleToParameters')); + btn = await driver.findComponent(ON.id('setDoubleToParameters')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + await driver.assertComponentExist(ON.id('okParameters')); + btn = await driver.findComponent(ON.id('okParameters')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + // 点击setDoubleArrayToParameters + await driver.assertComponentExist(ON.id('setDoubleArrayToParameters')); + btn = await driver.findComponent(ON.id('setDoubleArrayToParameters')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + await driver.assertComponentExist(ON.id('okParameters')); + btn = await driver.findComponent(ON.id('okParameters')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + // 点击setBoolToParameters + await driver.assertComponentExist(ON.id('setBoolToParameters')); + btn = await driver.findComponent(ON.id('setBoolToParameters')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + await driver.assertComponentExist(ON.id('okParameters')); + btn = await driver.findComponent(ON.id('okParameters')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + // 点击setBoolArrayToParameters + await driver.assertComponentExist(ON.id('setBoolArrayToParameters')); + btn = await driver.findComponent(ON.id('setBoolArrayToParameters')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + await driver.assertComponentExist(ON.id('okParameters')); + btn = await driver.findComponent(ON.id('okParameters')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + // 点击setCharToParameters + await driver.assertComponentExist(ON.id('setCharToParameters')); + btn = await driver.findComponent(ON.id('setCharToParameters')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + await driver.assertComponentExist(ON.id('okParameters')); + btn = await driver.findComponent(ON.id('okParameters')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + // 点击setCharArrayToParameters + await driver.assertComponentExist(ON.id('setCharArrayToParameters')); + btn = await driver.findComponent(ON.id('setCharArrayToParameters')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + await driver.assertComponentExist(ON.id('okParameters')); + btn = await driver.findComponent(ON.id('okParameters')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + + await driver.delayMs(WAITTIME1000); + await driver.pressBack(); + await driver.delayMs(WAITTIME1000); + console.info(TAG + ' NativeCommomEvent_Parameters_001 end'); + done(); + }) + + /** + * @tc.number: NativeCommomEvent_PublishInfo_001 + * @tc.name: NativeCommomEvent_PublishInfo_001 + * @tc.desc: detect and click the button to check application commomevent publishInfo + */ + it('NativeCommomEvent_PublishInfo_001', 0, async (done: Function) => { + console.info(TAG + ' NativeCommomEvent_PublishInfo_001 begin'); + let driver = await Driver.create(); + await driver.delayMs(WAITTIME1000); + + // 进入publishInfoSample开发示例页面 + let btn = await driver.findComponent(ON.id('PublishInfo')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + // 点击createPublishInfo + await driver.assertComponentExist(ON.id('createPublishInfo')); + btn = await driver.findComponent(ON.id('createPublishInfo')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + await driver.assertComponentExist(ON.id('okPublishInfo')); + btn = await driver.findComponent(ON.id('okPublishInfo')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + // 点击destroyPublishInfo + await driver.assertComponentExist(ON.id('destroyPublishInfo')); + btn = await driver.findComponent(ON.id('destroyPublishInfo')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + await driver.assertComponentExist(ON.id('okPublishInfo')); + btn = await driver.findComponent(ON.id('okPublishInfo')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + // 点击setPublishInfoBundleName + await driver.assertComponentExist(ON.id('setPublishInfoBundleName')); + btn = await driver.findComponent(ON.id('setPublishInfoBundleName')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + await driver.assertComponentExist(ON.id('okPublishInfo')); + btn = await driver.findComponent(ON.id('okPublishInfo')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + //点击setPublishInfoPermissions + await driver.assertComponentExist(ON.id('setPublishInfoPermissions')); + btn = await driver.findComponent(ON.id('setPublishInfoPermissions')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + await driver.assertComponentExist(ON.id('okPublishInfo')); + btn = await driver.findComponent(ON.id('okPublishInfo')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + //点击setPublishInfoCode + await driver.assertComponentExist(ON.id('setPublishInfoCode')); + btn = await driver.findComponent(ON.id('setPublishInfoCode')); + await btn.click(); + await driver.delayMs(WAITTIME4000); + await driver.assertComponentExist(ON.id('okPublishInfo')); + btn = await driver.findComponent(ON.id('okPublishInfo')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + //点击setPublishInfoData + await driver.assertComponentExist(ON.id('setPublishInfoData')); + btn = await driver.findComponent(ON.id('setPublishInfoData')); + await btn.click(); + await driver.delayMs(WAITTIME4000); + await driver.assertComponentExist(ON.id('okPublishInfo')); + btn = await driver.findComponent(ON.id('okPublishInfo')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + //点击setPublishInfoParameters + await driver.assertComponentExist(ON.id('setPublishInfoParameters')); + btn = await driver.findComponent(ON.id('setPublishInfoParameters')); + await btn.click(); + await driver.delayMs(WAITTIME4000); + await driver.assertComponentExist(ON.id('okPublishInfo')); + btn = await driver.findComponent(ON.id('okPublishInfo')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + + await driver.delayMs(WAITTIME1000); + await driver.pressBack(); + await driver.delayMs(WAITTIME1000); + console.info(TAG + ' NativeCommomEvent_PublishInfo_001 end'); + done(); + }) + + /** + * @tc.number: NativeCommomEvent_Publish_001 + * @tc.name: NativeCommomEvent_Publish_001 + * @tc.desc: detect and click the button to check application commomevent publish + */ + it('NativeCommomEvent_Publish_001', 0, async (done: Function) => { + console.info(TAG + ' NativeCommomEvent_Publish_001 begin'); + let driver = await Driver.create(); + await driver.delayMs(WAITTIME1000); + + // 进入publishSample开发示例页面 + let btn = await driver.findComponent(ON.id('Publish')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + // 点击publish + await driver.assertComponentExist(ON.id('publish')); + btn = await driver.findComponent(ON.id('publish')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + await driver.assertComponentExist(ON.id('okPublish')); + btn = await driver.findComponent(ON.id('okPublish')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + // 点击publishWithInfo + await driver.assertComponentExist(ON.id('publishWithInfo')); + btn = await driver.findComponent(ON.id('publishWithInfo')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + await driver.assertComponentExist(ON.id('okPublish')); + btn = await driver.findComponent(ON.id('okPublish')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + + await driver.delayMs(WAITTIME1000); + await driver.pressBack(); + await driver.delayMs(WAITTIME1000); + console.info(TAG + ' NativeCommomEvent_Publish_001 end'); + done(); + }) + + /** + * @tc.number: NativeCommomEvent_OrderedCommonEvent_001 + * @tc.name: NativeCommomEvent_OrderedCommonEvent_001 + * @tc.desc: detect and click the button to check application commomevent orderedcommonevent + */ + it('NativeCommomEvent_OrderedCommonEvent_001', 0, async (done: Function) => { + console.info(TAG + ' NativeCommomEvent_OrderedCommonEvent_001 begin'); + let driver = await Driver.create(); + await driver.delayMs(WAITTIME1000); + + // 进入orderedCommonEventSample开发示例页面 + let btn = await driver.findComponent(ON.id('OrderedCommonEvent')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + // 点击isOrderedCommonEvent + await driver.assertComponentExist(ON.id('isOrderedCommonEvent')); + btn = await driver.findComponent(ON.id('isOrderedCommonEvent')); + await btn.click(); + await driver.delayMs(WAITTIME4000); + await driver.assertComponentExist(ON.id('okOrderedCommonEvent')); + btn = await driver.findComponent(ON.id('okOrderedCommonEvent')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + // 点击finishCommonEvent + await driver.assertComponentExist(ON.id('finishCommonEvent')); + btn = await driver.findComponent(ON.id('finishCommonEvent')); + await btn.click(); + await driver.delayMs(WAITTIME4000); + await driver.assertComponentExist(ON.id('okOrderedCommonEvent')); + btn = await driver.findComponent(ON.id('okOrderedCommonEvent')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + // 点击abortCommonEvent + await driver.assertComponentExist(ON.id('abortCommonEvent')); + btn = await driver.findComponent(ON.id('abortCommonEvent')); + await btn.click(); + await driver.delayMs(WAITTIME4000); + await driver.assertComponentExist(ON.id('okOrderedCommonEvent')); + btn = await driver.findComponent(ON.id('okOrderedCommonEvent')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + // 点击getAbortCommonEvent + await driver.assertComponentExist(ON.id('getAbortCommonEvent')); + btn = await driver.findComponent(ON.id('getAbortCommonEvent')); + await btn.click(); + await driver.delayMs(WAITTIME4000); + await driver.assertComponentExist(ON.id('okOrderedCommonEvent')); + btn = await driver.findComponent(ON.id('okOrderedCommonEvent')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + // 点击clearAbortCommonEvent + await driver.assertComponentExist(ON.id('clearAbortCommonEvent')); + btn = await driver.findComponent(ON.id('clearAbortCommonEvent')); + await btn.click(); + await driver.delayMs(WAITTIME4000); + await driver.assertComponentExist(ON.id('okOrderedCommonEvent')); + btn = await driver.findComponent(ON.id('okOrderedCommonEvent')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + // 点击getCodeFromSubscriber + await driver.assertComponentExist(ON.id('getCodeFromSubscriber')); + btn = await driver.findComponent(ON.id('getCodeFromSubscriber')); + await btn.click(); + await driver.delayMs(WAITTIME4000); + await driver.assertComponentExist(ON.id('okOrderedCommonEvent')); + btn = await driver.findComponent(ON.id('okOrderedCommonEvent')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + // 点击setCodeToSubscriber + await driver.assertComponentExist(ON.id('setCodeToSubscriber')); + btn = await driver.findComponent(ON.id('setCodeToSubscriber')); + await btn.click(); + await driver.delayMs(WAITTIME4000); + await driver.assertComponentExist(ON.id('okOrderedCommonEvent')); + btn = await driver.findComponent(ON.id('okOrderedCommonEvent')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + // 点击getDataFromSubscriber + await driver.assertComponentExist(ON.id('getDataFromSubscriber')); + btn = await driver.findComponent(ON.id('getDataFromSubscriber')); + await btn.click(); + await driver.delayMs(WAITTIME4000); + await driver.assertComponentExist(ON.id('okOrderedCommonEvent')); + btn = await driver.findComponent(ON.id('okOrderedCommonEvent')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + // 点击setDataToSubscriber + await driver.assertComponentExist(ON.id('setDataToSubscriber')); + btn = await driver.findComponent(ON.id('setDataToSubscriber')); + await btn.click(); + await driver.delayMs(WAITTIME4000); + await driver.assertComponentExist(ON.id('okOrderedCommonEvent')); + btn = await driver.findComponent(ON.id('okOrderedCommonEvent')); + await btn.click(); + await driver.delayMs(WAITTIME1000); + + await driver.delayMs(WAITTIME1000); + await driver.pressBack(); + await driver.delayMs(WAITTIME1000); + console.info(TAG + ' NativeCommomEvent_OrderedCommonEvent_001 end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkCommonEvent/entry/src/ohosTest/ets/test/List.test.ets b/code/BasicFeature/Native/NdkCommonEvent/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..37ee7d03651ee8d41c854a5d12868af4b510ca92 --- /dev/null +++ b/code/BasicFeature/Native/NdkCommonEvent/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(); +} diff --git a/code/BasicFeature/Native/NdkCommonEvent/entry/src/ohosTest/module.json5 b/code/BasicFeature/Native/NdkCommonEvent/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/code/BasicFeature/Native/NdkCommonEvent/entry/src/ohosTest/module.json5 @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/BasicFeature/Native/NdkCommonEvent/hvigor/hvigor-config.json5 b/code/BasicFeature/Native/NdkCommonEvent/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..114aaf5af8f837f4921838398e637503501e7cc8 --- /dev/null +++ b/code/BasicFeature/Native/NdkCommonEvent/hvigor/hvigor-config.json5 @@ -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. + */ + +{ + "modelVersion": "5.0.0", + "dependencies": { + } +} diff --git a/code/BasicFeature/Native/NdkCommonEvent/hvigorfile.ts b/code/BasicFeature/Native/NdkCommonEvent/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..2a5e543f190732c159beb574dfc9fa37bc94e156 --- /dev/null +++ b/code/BasicFeature/Native/NdkCommonEvent/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/Native/NdkCommonEvent/oh-package.json5 b/code/BasicFeature/Native/NdkCommonEvent/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..37c22b202a9577e792485ef2f2f8f2d5702ed5f1 --- /dev/null +++ b/code/BasicFeature/Native/NdkCommonEvent/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.0", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.19", + "@ohos/hamock": "1.0.0" + } +} diff --git a/code/BasicFeature/Native/NdkCommonEvent/ohosTest.md b/code/BasicFeature/Native/NdkCommonEvent/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..355d8accdf8b5fccab5ac0e67928984c663dbf27 --- /dev/null +++ b/code/BasicFeature/Native/NdkCommonEvent/ohosTest.md @@ -0,0 +1,11 @@ +# Native Notification 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +|---------|---------------|-------------|-------------|------|------| +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 查询当前应用通知使能状态 | 设备正常运行,拉起位于首页 | 点击查询按钮 | 查询成功,显示查询结果 | 是 | Pass | + + + diff --git a/code/BasicFeature/Native/NdkCommonEvent/screenshots/device/main.jpg b/code/BasicFeature/Native/NdkCommonEvent/screenshots/device/main.jpg new file mode 100644 index 0000000000000000000000000000000000000000..9b8065cf289a9f5c34ee1070c6e772b2130986cc Binary files /dev/null and b/code/BasicFeature/Native/NdkCommonEvent/screenshots/device/main.jpg differ diff --git a/code/BasicFeature/Native/NdkCommonEvent/screenshots/device/orderedcommonevent.jpg b/code/BasicFeature/Native/NdkCommonEvent/screenshots/device/orderedcommonevent.jpg new file mode 100644 index 0000000000000000000000000000000000000000..b85c407b42de0415edea812a87d38fc639dc0ad2 Binary files /dev/null and b/code/BasicFeature/Native/NdkCommonEvent/screenshots/device/orderedcommonevent.jpg differ diff --git a/code/BasicFeature/Native/NdkCommonEvent/screenshots/device/parameters.jpg b/code/BasicFeature/Native/NdkCommonEvent/screenshots/device/parameters.jpg new file mode 100644 index 0000000000000000000000000000000000000000..13c0f01072b38e73692506c2dbbf0164ae61697c Binary files /dev/null and b/code/BasicFeature/Native/NdkCommonEvent/screenshots/device/parameters.jpg differ diff --git a/code/BasicFeature/Native/NdkCommonEvent/screenshots/device/publish.jpg b/code/BasicFeature/Native/NdkCommonEvent/screenshots/device/publish.jpg new file mode 100644 index 0000000000000000000000000000000000000000..be4293187e4b882198e731f732b648d26b2fb6ba Binary files /dev/null and b/code/BasicFeature/Native/NdkCommonEvent/screenshots/device/publish.jpg differ diff --git a/code/BasicFeature/Native/NdkCommonEvent/screenshots/device/publishinfo.jpg b/code/BasicFeature/Native/NdkCommonEvent/screenshots/device/publishinfo.jpg new file mode 100644 index 0000000000000000000000000000000000000000..9f7a175ed76c28ae29472a36f5048a3a621c6512 Binary files /dev/null and b/code/BasicFeature/Native/NdkCommonEvent/screenshots/device/publishinfo.jpg differ