diff --git a/OAT.xml b/OAT.xml index 34a8629de448c1a5ade9198e5229bacbcd87c4c1..6d4ce0db885fcbcca92969550482aadf000d4037 100644 --- a/OAT.xml +++ b/OAT.xml @@ -2252,6 +2252,40 @@ Note:If the text contains special characters, please escape them according to th <filteritem type="filepath" name="code/BasicFeature/Web/WebGetCameraImage/entry/src/main/resources/base/media/web_get_camera_image.gif" desc="Provided by code/UI/WebGetCameraImage"/> <filteritem type="filepath" name="code/BasicFeature/Web/WebGetCameraImage/AppScope/resources/base/media/background.png" desc="Provided by code/UI/WebGetCameraImage"/> <filteritem type="filepath" name="code/BasicFeature/Web/WebGetCameraImage/AppScope/resources/base/media/foreground.png" desc="Provided by code/UI/WebGetCameraImage"/> + <filteritem type="filepath" name="code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/screenshots/JsvmProcess_1.png" desc="Provided by code/DocsSample/ArkTs/JSVMAPI/JsvmProcess"/> + <filteritem type="filepath" name="code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/screenshots/JsvmProcess_2.png" desc="Provided by code/DocsSample/ArkTs/JSVMAPI/JsvmProcess"/> + <filteritem type="filepath" name="code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/screenshots/JsvmBasicDataTypes_1.png" desc="Provided by code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes"/> + <filteritem type="filepath" name="code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/screenshots/JsvmBasicDataTypes_2.png" desc="Provided by code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes"/> + <filteritem type="filepath" name="code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/screenshots/JsvmAboutArray_1.png" desc="Provided by code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray"/> + <filteritem type="filepath" name="code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/screenshots/JsvmAboutArray_2.png" desc="Provided by code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray"/> + <filteritem type="filepath" name="code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArrayBuffer/screenshots/JsvmAboutArrayBuffer_1.png" desc="Provided by code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArrayBuffer"/> + <filteritem type="filepath" name="code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArrayBuffer/screenshots/JsvmAboutArrayBuffer_2.png" desc="Provided by code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArrayBuffer"/> + <filteritem type="filepath" name="code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/screenshots/JsvmAboutBigint_1.png" desc="Provided by code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint"/> + <filteritem type="filepath" name="code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/screenshots/JsvmAboutBigint_2.png" desc="Provided by code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint"/> + <filteritem type="filepath" name="code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/screenshots/JsvmAboutDate_1.png" desc="Provided by code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate"/> + <filteritem type="filepath" name="code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/screenshots/JsvmAboutDate_2.png" desc="Provided by code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate"/> + <filteritem type="filepath" name="code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/screenshots/JsvmAboutObject_1.png" desc="Provided by code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject"/> + <filteritem type="filepath" name="code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/screenshots/JsvmAboutObject_2.png" desc="Provided by code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject"/> + <filteritem type="filepath" name="code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/screenshots/JsvmAboutPrimitive_1.png" desc="Provided by code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive"/> + <filteritem type="filepath" name="code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/screenshots/JsvmAboutPrimitive_2.png" desc="Provided by code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive"/> + <filteritem type="filepath" name="code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/screenshots/JsvmAboutProperty_1.png" desc="Provided by code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty"/> + <filteritem type="filepath" name="code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/screenshots/JsvmAboutProperty_2.png" desc="Provided by code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty"/> + <filteritem type="filepath" name="code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/screenshots/JsvmAboutString_1.png" desc="Provided by code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString"/> + <filteritem type="filepath" name="code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/screenshots/JsvmAboutString_2.png" desc="Provided by code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString"/> + <filteritem type="filepath" name="code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/screenshots/JsvmLifeCycle_1.png" desc="Provided by code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle"/> + <filteritem type="filepath" name="code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/screenshots/JsvmLifeCycle_2.png" desc="Provided by code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle"/> + <filteritem type="filepath" name="code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/screenshots/JsvmError_1.png" desc="Provided by code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError"/> + <filteritem type="filepath" name="code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/screenshots/JsvmError_2.png" desc="Provided by code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError"/> + <filteritem type="filepath" name="code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/screenshots/UsageInstructionsOne_1.png" desc="Provided by code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne"/> + <filteritem type="filepath" name="code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/screenshots/UsageInstructionsOne_2.png" desc="Provided by code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne"/> + <filteritem type="filepath" name="code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/screenshots/UsageInstructionsTwo_1.png" desc="Provided by code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo"/> + <filteritem type="filepath" name="code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/screenshots/UsageInstructionsTwo_2.png" desc="Provided by code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo"/> + <filteritem type="filepath" name="code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/screenshots/JsvmDebug_1.png" desc="Provided by code/DocsSample/ArkTs/JSVMAPI/JsvmDebug"/> + <filteritem type="filepath" name="code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/screenshots/JsvmDebug_2.png" desc="Provided by code/DocsSample/ArkTs/JSVMAPI/JsvmDebug"/> + <filteritem type="filepath" name="code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/screenshots/JsvmAboutClass_1.png" desc="Provided by code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass"/> + <filteritem type="filepath" name="code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/screenshots/JsvmAboutClass_2.png" desc="Provided by code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass"/> + <filteritem type="filepath" name="code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/screenshots/JsvmAboutPromise_1.png" desc="Provided by code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise"/> + <filteritem type="filepath" name="code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/screenshots/JsvmAboutPromise_2.png" desc="Provided by code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise"/> </filefilter> <filefilter name="defaultPolicyFilter" desc="License文件头校验策略的过滤条件" > <filteritem type="filename" name="oh-package.json5" desc="OpenHarmony工程编译入口脚本,无需添加License头"/> diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/.gitignore new file mode 100755 index 0000000000000000000000000000000000000000..0b9dda19af05cf615a8be3bc063b228131da6b7c --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/.gitignore @@ -0,0 +1,12 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +/.appanalyzer \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/AppScope/app.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/AppScope/app.json5 new file mode 100755 index 0000000000000000000000000000000000000000..4c34bddd1e355d98f66f53c9c2f1f047af99260b --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/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.jsvmprocess", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/AppScope/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..7b8d90ea32181dd4ead1ab4701d69de977e8cfc8 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "JsvmProcess" + } + ] +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/AppScope/resources/base/media/app_icon.png new file mode 100755 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/AppScope/resources/base/media/app_icon.png differ diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/README.md b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/README.md new file mode 100755 index 0000000000000000000000000000000000000000..3b5babcca6f31ae62883b2cc11c18512a20e7643 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/README.md @@ -0,0 +1,76 @@ +# ArkTS使用JSVM-API实现JS与C/C++语言交互开发流程 + +### 介绍 + +使用JSVM-API实现跨语言交互,首先需要按照JSVM-API的机制实现模块的注册和加载等相关动作。 + +- ArkTS/JS侧:实现C++方法的调用。代码比较简单,import一个对应的so库后,即可调用C++方法。 +- Native侧:.cpp文件,实现模块的注册。需要提供注册lib库的名称,并在注册回调方法中定义接口的映射关系,即Native方法及对应的JS/ArkTS接口名称等。 + +该工程中展示的代码详细描述可查如下链接: + +- [使用JSVM-API实现JS与C/C++语言交互开发流程](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-process.md) + +### 效果预览 + +| 首页 | 执行及结果即时反馈 | +| :-------------------------------------------------------------: | :-------------------------------------------------------------: | +| <img src="./screenshots/JsvmProcess_1.png" style="zoom:33%;" /> | <img src="./screenshots/JsvmProcess_2.png" style="zoom:33%;" /> | + +### 使用说明 + +1. 在主界面,可以点击hello world,开始执行。 +2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 使用JSVM-API实现JS与C/C++语言交互开发流程示例代码 + │ │ │ │ ├── oh-package.json5 // 使用JSVM-API实现JS与C/C++语言交互开发流程示例代码 + │ │ ├── CMakeLists.txt // 使用JSVM-API实现JS与C/C++语言交互开发流程示例代码 + │ │ ├── hello.cpp // 使用JSVM-API实现JS与C/C++语言交互开发流程示例代码 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 使用JSVM-API实现JS与C/C++语言交互开发流程示例代码 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:Phone。 + +2.本示例为Stage模型,支持API15版本SDK,版本号:5.0.3.135,镜像版本号:HarmonyOS NEXT_5.0.3.135。 + +3.本示例需要使用DevEco Studio 5.0.3 Release (Build Version: 5.0.9.300, built on March 13, 2025)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +``` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkTs/JSVMAPI/JsvmProcess > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +``` diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/build-profile.json5 new file mode 100755 index 0000000000000000000000000000000000000000..a21d5afe8864439233629ea7ea6ae9958d18ee60 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/build-profile.json5 @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compileSdkVersion": "5.0.3(15)", + "compatibleSdkVersion": "5.0.3(15)", + "targetSdkVersion": "5.0.3(15)", + "runtimeOS": "HarmonyOS", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/code-linter.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/code-linter.json5 new file mode 100755 index 0000000000000000000000000000000000000000..9deb9807637aa27ebde62e61e2362a417aacdc04 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/code-linter.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. + */ + +{ + "files": [ + "**/*.ets" + ], + "ignore": [ + "**/src/ohosTest/**/*", + "**/src/test/**/*", + "**/src/mock/**/*", + "**/node_modules/**/*", + "**/oh_modules/**/*", + "**/build/**/*", + "**/.preview/**/*" + ], + "ruleSet": [ + "plugin:@performance/recommended", + "plugin:@typescript-eslint/recommended" + ], + "rules": { + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/.gitignore new file mode 100755 index 0000000000000000000000000000000000000000..32abf8fd5e44623ebe60bf2adeee4a366372cc85 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/build-profile.json5 new file mode 100755 index 0000000000000000000000000000000000000000..d27072efd782a98fdc3b4456f19249ba19c31bbb --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/build-profile.json5 @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + "abiFilters": ["arm64-v8a", "x86_64"] + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + }, + "nativeLib": { + "debugSymbol": { + "strip": true, + "exclude": [] + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/hvigorfile.ts new file mode 100755 index 0000000000000000000000000000000000000000..46872af92274609fb7926a0eb6451cebbb18afef --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/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/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/obfuscation-rules.txt new file mode 100755 index 0000000000000000000000000000000000000000..5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/oh-package.json5 new file mode 100755 index 0000000000000000000000000000000000000000..5d993e5251fd56950970aa593aefef1b8d71e976 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/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/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/cpp/CMakeLists.txt new file mode 100755 index 0000000000000000000000000000000000000000..a481b73ee5b5ebe0a1bf336940d8c7efc697ae54 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JSVMDemo) + +set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) +# 日志打印配置 +add_definitions( "-DLOG_DOMAIN=0xd0d0" ) +add_definitions( "-DLOG_TAG=\"testTag\"" ) +include_directories(${NATIVERENDER_ROOT_PATH} + ${NATIVERENDER_ROOT_PATH}/include) + +# 添加名为entry的库 +add_library(entry SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(entry PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/cpp/hello.cpp new file mode 100755 index 0000000000000000000000000000000000000000..0a0b5272cbdf006850b5031e6ca49eafa60f2501 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/cpp/hello.cpp @@ -0,0 +1,160 @@ +/* + * 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 "ark_runtime/jsvm.h" + +#define LOG_DOMAIN 0x3200 +#define LOG_TAG "APP" + +static int g_aa = 0; + +#define CHECK_RET(theCall) \ + do { \ + JSVM_Status cond = theCall; \ + if ((cond) != JSVM_OK) { \ + const JSVM_ExtendedErrorInfo *info; \ + OH_JSVM_GetLastErrorInfo(env, &info); \ + OH_LOG_ERROR(LOG_APP, "jsvm fail file: %{public}s line: %{public}d ret = %{public}d message = %{public}s", \ + __FILE__, __LINE__, cond, info != nullptr ? info->errorMessage : ""); \ + return -1; \ + } \ + } while (0) + +#define CHECK(theCall) \ + do { \ + JSVM_Status cond = theCall; \ + if ((cond) != JSVM_OK) { \ + OH_LOG_ERROR(LOG_APP, "jsvm fail file: %{public}s line: %{public}d ret = %{public}d", __FILE__, __LINE__, \ + cond); \ + return -1; \ + } \ + } while (0) + +// 用于调用theCall并检查其返回值是否为JSVM_OK。 +// 如果不是,则调用OH_JSVM_GetLastErrorInfo处理错误并返回retVal。 +#define JSVM_CALL_BASE(env, theCall, retVal) \ + do { \ + JSVM_Status cond = theCall; \ + if (cond != JSVM_OK) { \ + const JSVM_ExtendedErrorInfo *info; \ + OH_JSVM_GetLastErrorInfo(env, &info); \ + OH_LOG_ERROR(LOG_APP, "jsvm fail file: %{public}s line: %{public}d ret = %{public}d message = %{public}s", \ + __FILE__, __LINE__, cond, info != nullptr ? info->errorMessage : ""); \ + return retVal; \ + } \ + } while (0) + +// JSVM_CALL_BASE的简化版本,返回nullptr +#define JSVM_CALL(theCall) JSVM_CALL_BASE(env, theCall, nullptr) + +// OH_JSVM_StrictEquals的样例方法 +static JSVM_Value IsStrictEquals(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 接受两个入参 + size_t argc = 2; + JSVM_Value args[2] = {nullptr}; + JSVM_CALL(OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr)); + // 调用OH_JSVM_StrictEquals接口判断给定的两个JavaScript value是否严格相等 + bool result = false; + JSVM_Status status = OH_JSVM_StrictEquals(env, args[0], args[1], &result); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM OH_JSVM_StrictEquals: failed"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_StrictEquals: success: %{public}d", result); + } + JSVM_Value isStrictEqual; + JSVM_CALL(OH_JSVM_GetBoolean(env, result, &isStrictEqual)); + return isStrictEqual; +} +// IsStrictEquals注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = IsStrictEquals}, +}; +static JSVM_CallbackStruct *method = param; +// IsStrictEquals方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"isStrictEquals", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS( let data = '123'; + let value = 123; + isStrictEquals(data, value);)JS"; + +static int32_t TestJSVM() +{ + JSVM_InitOptions initOptions = {0}; + JSVM_VM vm; + JSVM_Env env = nullptr; + JSVM_VMScope vmScope; + JSVM_EnvScope envScope; + JSVM_HandleScope handleScope; + JSVM_Value result; + // 初始化JavaScript引擎实例 + if (g_aa == 0) { + g_aa++; + CHECK(OH_JSVM_Init(&initOptions)); + } + // 创建JSVM环境 + CHECK(OH_JSVM_CreateVM(nullptr, &vm)); + CHECK(OH_JSVM_CreateEnv(vm, sizeof(descriptor) / sizeof(descriptor[0]), descriptor, &env)); + CHECK(OH_JSVM_OpenVMScope(vm, &vmScope)); + CHECK_RET(OH_JSVM_OpenEnvScope(env, &envScope)); + CHECK_RET(OH_JSVM_OpenHandleScope(env, &handleScope)); + + // 通过script调用测试函数 + JSVM_Script script; + JSVM_Value jsSrc; + CHECK_RET(OH_JSVM_CreateStringUtf8(env, SRC_CALL_NATIVE, JSVM_AUTO_LENGTH, &jsSrc)); + CHECK_RET(OH_JSVM_CompileScript(env, jsSrc, nullptr, 0, true, nullptr, &script)); + CHECK_RET(OH_JSVM_RunScript(env, script, &result)); + + // 销毁JSVM环境 + CHECK_RET(OH_JSVM_CloseHandleScope(env, handleScope)); + CHECK_RET(OH_JSVM_CloseEnvScope(env, envScope)); + CHECK(OH_JSVM_CloseVMScope(vm, vmScope)); + CHECK(OH_JSVM_DestroyEnv(env)); + CHECK(OH_JSVM_DestroyVM(vm)); + return 0; +} + +static napi_value RunTest(napi_env env, napi_callback_info info) +{ + TestJSVM(); + return nullptr; +} + +// 模块注册信息,供arkts侧调用 +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = {{"runTest", nullptr, RunTest, nullptr, nullptr, nullptr, napi_default, nullptr}}; + napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); + return exports; +} +EXTERN_C_END + +static napi_module demoModule = { + .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(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/cpp/types/libentry/Index.d.ts new file mode 100755 index 0000000000000000000000000000000000000000..8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/cpp/types/libentry/Index.d.ts @@ -0,0 +1,16 @@ +/* + * 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 runTest: () => void; \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100755 index 0000000000000000000000000000000000000000..846e4c7e13ead48abe6019bd40f3a13bf8f9c083 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/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/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100755 index 0000000000000000000000000000000000000000..a36ca588fe1aa322e8fca13744debe6f29d41d44 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/ets/entryability/EntryAbility.ets @@ -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. + */ + +import { AbilityConstant, ConfigurationConstant, 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 { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + 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'); + } +}; \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100755 index 0000000000000000000000000000000000000000..1504a74f09dfdcfae408be979f99369a2c5affab --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -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. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(0x0000, 'testTag', 'onBackup ok'); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(0x0000, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/ets/pages/Index.ets new file mode 100755 index 0000000000000000000000000000000000000000..905d4aee1e43471eaf5d78a53e250bf29e00647a --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/ets/pages/Index.ets @@ -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. + */ + +import napitest from 'libentry.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + .onClick(() => { + try { + napitest.runTest(); + this.message = 'success'; + } catch (error) { + console.error('An error occurred: ', error); + this.message = 'fail'; + } + }) + } + .width('100%') + } + .height('100%') + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/module.json5 new file mode 100755 index 0000000000000000000000000000000000000000..776ce01475229d674487a2830790c4c87b777379 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/module.json5 @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "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:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ] + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/resources/base/element/color.json new file mode 100755 index 0000000000000000000000000000000000000000..d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..7ea79fc923027d7102b96eca844f27ca2ce38471 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "JsvmProcess" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/resources/base/media/background.png new file mode 100755 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/resources/base/media/background.png differ diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/resources/base/media/foreground.png new file mode 100755 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/resources/base/media/foreground.png differ diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/resources/base/media/layered_image.json new file mode 100755 index 0000000000000000000000000000000000000000..16cf3219a2997a071cd6f0cd4816d3e173b18d15 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/resources/base/media/startIcon.png new file mode 100755 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/resources/base/media/startIcon.png differ diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/resources/base/profile/backup_config.json new file mode 100755 index 0000000000000000000000000000000000000000..d742c2f96e7dd0f406f499941f3147345e998f95 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/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/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/resources/base/profile/main_pages.json new file mode 100755 index 0000000000000000000000000000000000000000..14bbd62cb9de385b1f5551945d749bb5e0e5fc2c --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/resources/dark/element/color.json new file mode 100755 index 0000000000000000000000000000000000000000..438d5bc43bb23c59c210d586b96635a72da5b64a --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/resources/dark/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/resources/en_US/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/resources/en_US/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..7ea79fc923027d7102b96eca844f27ca2ce38471 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/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": "JsvmProcess" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/resources/zh_CN/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/resources/zh_CN/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..16fcf0c75f86f523fbebae253952ed225edaacb7 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/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": "JsvmProcess" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..b0690e03efc28c20291353de66f77eb8c599b838 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/ohosTest/ets/test/Ability.test.ets @@ -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. + */ + +import { describe, it, expect } from '@ohos/hypium'; +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; + +export default function abilityTest() { + describe('ActsAbilityTest', () => { + /** + * 打开应用,点击Hello World执行 + */ + it('testJsvmProcess', 0, async (done: Function) => { + console.log('uitest: TestJsvmProcess begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + } + const driver = Driver.create(); + await delegator.startAbility(want); + await driver.delayMs(1000); + + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.log('get top ability'); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('Hello World')); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('success')); + console.log('uitest: TestJsvmProcess end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/ohosTest/ets/test/List.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..a10a79ed1d91b6040cc81d926b62c250e8f3866d --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/ohosTest/module.json5 new file mode 100755 index 0000000000000000000000000000000000000000..9983b2ba4e55e31a172f0328c82c9a75bfa00ded --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/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/DocsSample/ArkTs/JSVMAPI/JsvmProcess/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/hvigor/hvigor-config.json5 new file mode 100755 index 0000000000000000000000000000000000000000..cef74543b1f97c82275e4bf3434b162395bff2eb --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/hvigor/hvigor-config.json5 @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "modelVersion": "5.0.1", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/hvigorfile.ts new file mode 100755 index 0000000000000000000000000000000000000000..2db60fa91881f6961e5def61af680301d22a1341 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/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/DocsSample/ArkTs/JSVMAPI/JsvmProcess/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/oh-package.json5 new file mode 100755 index 0000000000000000000000000000000000000000..eaef52736f22c14e04fca386ba01611ab32a7e4a --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/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.1", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.19", + "@ohos/hamock": "1.0.0" + } +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/ohosTest.md b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/ohosTest.md new file mode 100755 index 0000000000000000000000000000000000000000..a5e25bbf8717ad8578daa9c5f290e636c210301f --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/ohosTest.md @@ -0,0 +1,8 @@ +# JsvmProcess 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ----------------------------------------- | ------------ | --------------- | ---------------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 使用JSVM-API实现JS与C/C++语言交互开发流程 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/screenshots/JsvmProcess_1.png b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/screenshots/JsvmProcess_1.png new file mode 100755 index 0000000000000000000000000000000000000000..b5d7d8912c33ad5d396165630aac9f733b4cf98e Binary files /dev/null and b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/screenshots/JsvmProcess_1.png differ diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/screenshots/JsvmProcess_2.png b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/screenshots/JsvmProcess_2.png new file mode 100755 index 0000000000000000000000000000000000000000..7823f8b8205726b9fe7752fad4e95f7cbff529fa Binary files /dev/null and b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/screenshots/JsvmProcess_2.png differ